All Downloads are FREE. Search and download functionalities are using the official Maven repository.

kotlin.collections.SetsJVM.kt Maven / Gradle / Ivy

There is a newer version: 2.0.0.0-RC3
Show newest version
/*
 * 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))





© 2015 - 2024 Weber Informatics LLC | Privacy Policy