kotlin.collections.Sets.kt Maven / Gradle / Ivy
@file:kotlin.jvm.JvmMultifileClass
@file:kotlin.jvm.JvmName("SetsKt")
package kotlin
import java.io.Serializable
import java.util.*
internal object EmptySet : Set, Serializable {
override fun equals(other: Any?): Boolean = other is Set<*> && other.isEmpty()
override fun hashCode(): Int = 0
override fun toString(): String = "[]"
override val size: Int get() = 0
override fun isEmpty(): Boolean = true
override fun contains(o: Nothing): Boolean = false
override fun containsAll(c: Collection): Boolean = c.isEmpty()
override fun iterator(): Iterator = EmptyIterator
private fun readResolve(): Any = EmptySet
}
/** Returns an empty read-only set. The returned set is serializable (JVM). */
public fun emptySet(): Set = EmptySet
/** Returns a new read-only ordered set with the given elements. The returned set is serializable (JVM). */
public fun setOf(vararg values: T): Set = if (values.size() > 0) values.toSet() else emptySet()
/** Returns an empty read-only set. The returned set is serializable (JVM). */
public fun setOf(): Set = emptySet()
/** Returns a new [HashSet] with the given elements. */
public fun hashSetOf(vararg values: T): HashSet = values.toCollection(HashSet(mapCapacity(values.size())))
/** Returns a new [LinkedHashSet] with the given elements. */
public fun linkedSetOf(vararg values: T): LinkedHashSet = values.toCollection(LinkedHashSet(mapCapacity(values.size())))
/** Returns this Set if it's not `null` and the empty set otherwise. */
public fun Set?.orEmpty(): Set = this ?: emptySet()
/* Not available on platform: JS */
/* Not available on platform: JS */
/* Not available on platform: JS */