kotlin.collections.SetsJVM.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of polaris-all Show documentation
Show all versions of polaris-all Show documentation
All in one project for polaris-java
/*
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@file:kotlin.jvm.JvmMultifileClass
@file:kotlin.jvm.JvmName("SetsKt")
package kotlin.collections
import kotlin.collections.builders.SetBuilder
/**
* Returns an immutable set containing only the specified object [element].
* The returned set is serializable.
*/
public fun setOf(element: T): Set = java.util.Collections.singleton(element)
@PublishedApi
@SinceKotlin("1.3")
@kotlin.internal.InlineOnly
internal actual inline fun buildSetInternal(builderAction: MutableSet.() -> Unit): Set {
return build(createSetBuilder().apply(builderAction))
}
@PublishedApi
@SinceKotlin("1.3")
@kotlin.internal.InlineOnly
internal actual inline fun buildSetInternal(capacity: Int, builderAction: MutableSet.() -> Unit): Set {
return build(createSetBuilder(capacity).apply(builderAction))
}
@PublishedApi
@SinceKotlin("1.3")
internal fun createSetBuilder(): MutableSet {
return SetBuilder()
}
@PublishedApi
@SinceKotlin("1.3")
internal fun createSetBuilder(capacity: Int): MutableSet {
return SetBuilder(capacity)
}
@PublishedApi
@SinceKotlin("1.3")
internal fun build(builder: MutableSet): Set {
return (builder as SetBuilder).build()
}
/**
* Returns a new [java.util.SortedSet] with the given elements.
*/
public fun sortedSetOf(vararg elements: T): java.util.TreeSet = elements.toCollection(java.util.TreeSet())
/**
* Returns a new [java.util.SortedSet] with the given [comparator] and elements.
*/
public fun sortedSetOf(comparator: Comparator, vararg elements: T): java.util.TreeSet = elements.toCollection(java.util.TreeSet(comparator))