StdLib: Rename method parameters (Collections)
This commit is contained in:
@@ -3,53 +3,53 @@ package kotlin
|
||||
import java.util.*
|
||||
|
||||
@library
|
||||
public fun <T> arrayOf(vararg value : T): Array<T> = noImpl
|
||||
public fun <T> arrayOf(vararg elements: T): Array<T> = noImpl
|
||||
|
||||
// "constructors" for primitive types array
|
||||
|
||||
@library
|
||||
public fun doubleArrayOf(vararg content : Double): DoubleArray = noImpl
|
||||
public fun doubleArrayOf(vararg elements: Double): DoubleArray = noImpl
|
||||
|
||||
@library
|
||||
public fun floatArrayOf(vararg content : Float): FloatArray = noImpl
|
||||
public fun floatArrayOf(vararg elements: Float): FloatArray = noImpl
|
||||
|
||||
@library
|
||||
public fun longArrayOf(vararg content : Long): LongArray = noImpl
|
||||
public fun longArrayOf(vararg elements: Long): LongArray = noImpl
|
||||
|
||||
@library
|
||||
public fun intArrayOf(vararg content : Int): IntArray = noImpl
|
||||
public fun intArrayOf(vararg elements: Int): IntArray = noImpl
|
||||
|
||||
@library
|
||||
public fun charArrayOf(vararg content : Char): CharArray = noImpl
|
||||
public fun charArrayOf(vararg elements: Char): CharArray = noImpl
|
||||
|
||||
@library
|
||||
public fun shortArrayOf(vararg content : Short): ShortArray = noImpl
|
||||
public fun shortArrayOf(vararg elements: Short): ShortArray = noImpl
|
||||
|
||||
@library
|
||||
public fun byteArrayOf(vararg content : Byte): ByteArray = noImpl
|
||||
public fun byteArrayOf(vararg elements: Byte): ByteArray = noImpl
|
||||
|
||||
@library
|
||||
public fun booleanArrayOf(vararg content : Boolean): BooleanArray = noImpl
|
||||
public fun booleanArrayOf(vararg elements: Boolean): BooleanArray = noImpl
|
||||
|
||||
@library("copyToArray")
|
||||
public fun <reified T> Collection<T>.toTypedArray(): Array<T> = noImpl
|
||||
|
||||
|
||||
/**
|
||||
* Returns an immutable list containing only the specified object [value].
|
||||
* Returns an immutable list containing only the specified object [element].
|
||||
*/
|
||||
public fun listOf<T>(value: T): List<T> = arrayListOf(value)
|
||||
public fun listOf<T>(element: T): List<T> = arrayListOf(element)
|
||||
|
||||
/**
|
||||
* Returns an immutable set containing only the specified object [value].
|
||||
* Returns an immutable set containing only the specified object [element].
|
||||
*/
|
||||
public fun setOf<T>(value: T): Set<T> = hashSetOf(value)
|
||||
public fun setOf<T>(element: T): Set<T> = hashSetOf(element)
|
||||
|
||||
/**
|
||||
* Returns an immutable map, mapping only the specified key to the
|
||||
* specified value.
|
||||
*/
|
||||
public fun mapOf<K, V>(keyValuePair: Pair<K, V>): Map<K, V> = hashMapOf(keyValuePair)
|
||||
public fun mapOf<K, V>(pair: Pair<K, V>): Map<K, V> = hashMapOf(pair)
|
||||
|
||||
/**
|
||||
* Creates a new instance of the [Lazy] that uses the specified initialization function [initializer].
|
||||
|
||||
@@ -11,48 +11,48 @@ import kotlin.jvm.internal.Intrinsic
|
||||
/**
|
||||
* Returns an array containing the specified elements.
|
||||
*/
|
||||
@Intrinsic("kotlin.arrays.array") public fun <reified T> arrayOf(vararg t : T) : Array<T> = t as Array<T>
|
||||
@Intrinsic("kotlin.arrays.array") public fun <reified T> arrayOf(vararg elements: T) : Array<T> = elements as Array<T>
|
||||
|
||||
// "constructors" for primitive types array
|
||||
/**
|
||||
* Returns an array containing the specified [Double] numbers.
|
||||
*/
|
||||
@Intrinsic("kotlin.arrays.array") public fun doubleArrayOf(vararg content : Double) : DoubleArray = content
|
||||
@Intrinsic("kotlin.arrays.array") public fun doubleArrayOf(vararg elements: Double) : DoubleArray = elements
|
||||
|
||||
/**
|
||||
* Returns an array containing the specified [Float] numbers.
|
||||
*/
|
||||
@Intrinsic("kotlin.arrays.array") public fun floatArrayOf(vararg content : Float) : FloatArray = content
|
||||
@Intrinsic("kotlin.arrays.array") public fun floatArrayOf(vararg elements: Float) : FloatArray = elements
|
||||
|
||||
/**
|
||||
* Returns an array containing the specified [Long] numbers.
|
||||
*/
|
||||
@Intrinsic("kotlin.arrays.array") public fun longArrayOf(vararg content : Long) : LongArray = content
|
||||
@Intrinsic("kotlin.arrays.array") public fun longArrayOf(vararg elements: Long) : LongArray = elements
|
||||
|
||||
/**
|
||||
* Returns an array containing the specified [Int] numbers.
|
||||
*/
|
||||
@Intrinsic("kotlin.arrays.array") public fun intArrayOf(vararg content : Int) : IntArray = content
|
||||
@Intrinsic("kotlin.arrays.array") public fun intArrayOf(vararg elements: Int) : IntArray = elements
|
||||
|
||||
/**
|
||||
* Returns an array containing the specified characters.
|
||||
*/
|
||||
@Intrinsic("kotlin.arrays.array") public fun charArrayOf(vararg content : Char) : CharArray = content
|
||||
@Intrinsic("kotlin.arrays.array") public fun charArrayOf(vararg elements: Char) : CharArray = elements
|
||||
|
||||
/**
|
||||
* Returns an array containing the specified [Short] numbers.
|
||||
*/
|
||||
@Intrinsic("kotlin.arrays.array") public fun shortArrayOf(vararg content : Short) : ShortArray = content
|
||||
@Intrinsic("kotlin.arrays.array") public fun shortArrayOf(vararg elements: Short) : ShortArray = elements
|
||||
|
||||
/**
|
||||
* Returns an array containing the specified [Byte] numbers.
|
||||
*/
|
||||
@Intrinsic("kotlin.arrays.array") public fun byteArrayOf(vararg content : Byte) : ByteArray = content
|
||||
@Intrinsic("kotlin.arrays.array") public fun byteArrayOf(vararg elements: Byte) : ByteArray = elements
|
||||
|
||||
/**
|
||||
* Returns an array containing the specified boolean values.
|
||||
*/
|
||||
@Intrinsic("kotlin.arrays.array") public fun booleanArrayOf(vararg content : Boolean) : BooleanArray = content
|
||||
@Intrinsic("kotlin.arrays.array") public fun booleanArrayOf(vararg elements: Boolean) : BooleanArray = elements
|
||||
|
||||
/**
|
||||
* Converts the contents of this byte array to a string using the specified [charset].
|
||||
|
||||
@@ -22,12 +22,12 @@ internal object EmptyList : List<Nothing>, Serializable {
|
||||
|
||||
override val size: Int get() = 0
|
||||
override fun isEmpty(): Boolean = true
|
||||
override fun contains(o: Nothing): Boolean = false
|
||||
override fun containsAll(c: Collection<Nothing>): Boolean = c.isEmpty()
|
||||
override fun contains(element: Nothing): Boolean = false
|
||||
override fun containsAll(elements: Collection<Nothing>): Boolean = elements.isEmpty()
|
||||
|
||||
override fun get(index: Int): Nothing = throw IndexOutOfBoundsException("Index $index is out of bound of empty list.")
|
||||
override fun indexOf(o: Nothing): Int = -1
|
||||
override fun lastIndexOf(o: Nothing): Int = -1
|
||||
override fun indexOf(element: Nothing): Int = -1
|
||||
override fun lastIndexOf(element: Nothing): Int = -1
|
||||
|
||||
override fun iterator(): Iterator<Nothing> = EmptyIterator
|
||||
override fun listIterator(): ListIterator<Nothing> = EmptyIterator
|
||||
@@ -49,8 +49,8 @@ internal fun <T> Array<out T>.asCollection(): Collection<T> = ArrayAsCollection(
|
||||
private class ArrayAsCollection<T>(val values: Array<out T>): Collection<T> {
|
||||
override val size: Int get() = values.size
|
||||
override fun isEmpty(): Boolean = values.isEmpty()
|
||||
override fun contains(o: T): Boolean = values.contains(o)
|
||||
override fun containsAll(c: Collection<T>): Boolean = c.all { contains(it) }
|
||||
override fun contains(element: T): Boolean = values.contains(element)
|
||||
override fun containsAll(elements: Collection<T>): Boolean = elements.all { contains(it) }
|
||||
override fun iterator(): Iterator<T> = values.iterator()
|
||||
// override hidden toArray implementation to prevent copying of values array
|
||||
public fun toArray(): Array<out Any?> = values.varargToArrayOfAny()
|
||||
@@ -60,32 +60,32 @@ private class ArrayAsCollection<T>(val values: Array<out T>): Collection<T> {
|
||||
public fun <T> emptyList(): List<T> = EmptyList
|
||||
|
||||
/** Returns a new read-only list of given elements. The returned list is serializable (JVM). */
|
||||
public fun <T> listOf(vararg values: T): List<T> = if (values.size > 0) values.asList() else emptyList()
|
||||
public fun <T> listOf(vararg elements: T): List<T> = if (elements.size > 0) elements.asList() else emptyList()
|
||||
|
||||
/** Returns an empty read-only list. The returned list is serializable (JVM). */
|
||||
public fun <T> listOf(): List<T> = emptyList()
|
||||
|
||||
/**
|
||||
* Returns an immutable list containing only the specified object [value].
|
||||
* Returns an immutable list containing only the specified object [element].
|
||||
* The returned list is serializable.
|
||||
*/
|
||||
@JvmVersion
|
||||
public fun <T> listOf(value: T): List<T> = Collections.singletonList(value)
|
||||
public fun <T> listOf(element: T): List<T> = Collections.singletonList(element)
|
||||
|
||||
/** Returns a new [LinkedList] with the given elements. */
|
||||
@JvmVersion
|
||||
public fun <T> linkedListOf(vararg values: T): LinkedList<T>
|
||||
= if (values.size == 0) LinkedList() else LinkedList(ArrayAsCollection(values))
|
||||
public fun <T> linkedListOf(vararg elements: T): LinkedList<T>
|
||||
= if (elements.size == 0) LinkedList() else LinkedList(ArrayAsCollection(elements))
|
||||
|
||||
/** Returns a new [ArrayList] with the given elements. */
|
||||
public fun <T> arrayListOf(vararg values: T): ArrayList<T>
|
||||
= if (values.size == 0) ArrayList() else ArrayList(ArrayAsCollection(values))
|
||||
public fun <T> arrayListOf(vararg elements: T): ArrayList<T>
|
||||
= if (elements.size == 0) ArrayList() else ArrayList(ArrayAsCollection(elements))
|
||||
|
||||
/** Returns a new read-only list either of single given element, if it is not null, or empty list it the element is null. The returned list is serializable (JVM). */
|
||||
public fun <T : Any> listOfNotNull(value: T?): List<T> = if (value != null) listOf(value) else emptyList()
|
||||
public fun <T : Any> listOfNotNull(element: T?): List<T> = if (element != null) listOf(element) else emptyList()
|
||||
|
||||
/** Returns a new read-only list only of those given elements, that are not null. The returned list is serializable (JVM). */
|
||||
public fun <T : Any> listOfNotNull(vararg values: T?): List<T> = values.filterNotNull()
|
||||
public fun <T : Any> listOfNotNull(vararg elements: T?): List<T> = elements.filterNotNull()
|
||||
|
||||
/**
|
||||
* Returns an [IntRange] of the valid indices for this collection.
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.util.*
|
||||
* Allows to overcome type-safety restriction of `containsAll` that requires to pass a collection of type `Collection<E>`.
|
||||
*/
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
public inline fun Collection<*>.containsAllRaw(collection: Collection<Any?>): Boolean = (this as Collection<Any?>).containsAll(collection)
|
||||
public inline fun Collection<*>.containsAllRaw(elements: Collection<Any?>): Boolean = (this as Collection<Any?>).containsAll(elements)
|
||||
|
||||
/**
|
||||
* Removes a single instance of the specified element from this
|
||||
@@ -32,7 +32,7 @@ public inline fun <E> MutableCollection<E>.removeRaw(element: Any?): Boolean = (
|
||||
* @return `true` if any of the specified elements was removed from the collection, `false` if the collection was not modified.
|
||||
*/
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
public inline fun <E> MutableCollection<E>.removeAllRaw(collection: Collection<Any?>): Boolean = (this as MutableCollection<Any?>).removeAll(collection)
|
||||
public inline fun <E> MutableCollection<E>.removeAllRaw(elements: Collection<Any?>): Boolean = (this as MutableCollection<Any?>).removeAll(elements)
|
||||
|
||||
/**
|
||||
* Retains only the elements in this collection that are contained in the specified collection.
|
||||
@@ -42,7 +42,7 @@ public inline fun <E> MutableCollection<E>.removeAllRaw(collection: Collection<A
|
||||
* @return `true` if any element was removed from the collection, `false` if the collection was not modified.
|
||||
*/
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
public inline fun <E> MutableCollection<E>.retainAllRaw(collection: Collection<Any?>): Boolean = (this as MutableCollection<Any?>).retainAll(collection)
|
||||
public inline fun <E> MutableCollection<E>.retainAllRaw(elements: Collection<Any?>): Boolean = (this as MutableCollection<Any?>).retainAll(elements)
|
||||
|
||||
|
||||
|
||||
@@ -123,24 +123,24 @@ public operator fun <T> MutableCollection<in T>.plusAssign(element: T) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds all elements of the given [collection] to this mutable collection.
|
||||
* Adds all elements of the given [elements] collection to this mutable collection.
|
||||
*/
|
||||
public operator fun <T> MutableCollection<in T>.plusAssign(collection: Iterable<T>) {
|
||||
this.addAll(collection)
|
||||
public operator fun <T> MutableCollection<in T>.plusAssign(elements: Iterable<T>) {
|
||||
this.addAll(elements)
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds all elements of the given [array] to this mutable collection.
|
||||
* Adds all elements of the given [elements] array to this mutable collection.
|
||||
*/
|
||||
public operator fun <T> MutableCollection<in T>.plusAssign(array: Array<T>) {
|
||||
this.addAll(array)
|
||||
public operator fun <T> MutableCollection<in T>.plusAssign(elements: Array<T>) {
|
||||
this.addAll(elements)
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds all elements of the given [sequence] to this mutable collection.
|
||||
* Adds all elements of the given [elements] sequence to this mutable collection.
|
||||
*/
|
||||
public operator fun <T> MutableCollection<in T>.plusAssign(sequence: Sequence<T>) {
|
||||
this.addAll(sequence)
|
||||
public operator fun <T> MutableCollection<in T>.plusAssign(elements: Sequence<T>) {
|
||||
this.addAll(elements)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -151,99 +151,99 @@ public operator fun <T> MutableCollection<in T>.minusAssign(element: T) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all elements contained in the given [collection] from this mutable collection.
|
||||
* Removes all elements contained in the given [elements] collection from this mutable collection.
|
||||
*/
|
||||
public operator fun <T> MutableCollection<in T>.minusAssign(collection: Iterable<T>) {
|
||||
this.removeAll(collection)
|
||||
public operator fun <T> MutableCollection<in T>.minusAssign(elements: Iterable<T>) {
|
||||
this.removeAll(elements)
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all elements contained in the given [array] from this mutable collection.
|
||||
* Removes all elements contained in the given [elements] array from this mutable collection.
|
||||
*/
|
||||
public operator fun <T> MutableCollection<in T>.minusAssign(array: Array<T>) {
|
||||
this.removeAll(array)
|
||||
public operator fun <T> MutableCollection<in T>.minusAssign(elements: Array<T>) {
|
||||
this.removeAll(elements)
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all elements contained in the given [sequence] from this mutable collection.
|
||||
* Removes all elements contained in the given [elements] sequence from this mutable collection.
|
||||
*/
|
||||
public operator fun <T> MutableCollection<in T>.minusAssign(sequence: Sequence<T>) {
|
||||
this.removeAll(sequence)
|
||||
public operator fun <T> MutableCollection<in T>.minusAssign(elements: Sequence<T>) {
|
||||
this.removeAll(elements)
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds all elements of the given [iterable] to this [MutableCollection].
|
||||
* Adds all elements of the given [elements] collection to this [MutableCollection].
|
||||
*/
|
||||
public fun <T> MutableCollection<in T>.addAll(iterable: Iterable<T>) {
|
||||
when (iterable) {
|
||||
is Collection -> addAll(iterable)
|
||||
else -> for (item in iterable) add(item)
|
||||
public fun <T> MutableCollection<in T>.addAll(elements: Iterable<T>) {
|
||||
when (elements) {
|
||||
is Collection -> addAll(elements)
|
||||
else -> for (item in elements) add(item)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds all elements of the given [sequence] to this [MutableCollection].
|
||||
* Adds all elements of the given [elements] sequence to this [MutableCollection].
|
||||
*/
|
||||
public fun <T> MutableCollection<in T>.addAll(sequence: Sequence<T>) {
|
||||
for (item in sequence) add(item)
|
||||
public fun <T> MutableCollection<in T>.addAll(elements: Sequence<T>) {
|
||||
for (item in elements) add(item)
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds all elements of the given [array] to this [MutableCollection].
|
||||
* Adds all elements of the given [elements] array to this [MutableCollection].
|
||||
*/
|
||||
public fun <T> MutableCollection<in T>.addAll(array: Array<out T>) {
|
||||
addAll(array.asList())
|
||||
public fun <T> MutableCollection<in T>.addAll(elements: Array<out T>) {
|
||||
addAll(elements.asList())
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all elements from this [MutableCollection] that are also contained in the given [iterable].
|
||||
* Removes all elements from this [MutableCollection] that are also contained in the given [elements] collection.
|
||||
*/
|
||||
public fun <T> MutableCollection<in T>.removeAll(iterable: Iterable<T>) {
|
||||
removeAll(iterable.convertToSetForSetOperationWith(this))
|
||||
public fun <T> MutableCollection<in T>.removeAll(elements: Iterable<T>) {
|
||||
removeAll(elements.convertToSetForSetOperationWith(this))
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all elements from this [MutableCollection] that are also contained in the given [sequence].
|
||||
* Removes all elements from this [MutableCollection] that are also contained in the given [elements] sequence.
|
||||
*/
|
||||
public fun <T> MutableCollection<in T>.removeAll(sequence: Sequence<T>) {
|
||||
val set = sequence.toHashSet()
|
||||
public fun <T> MutableCollection<in T>.removeAll(elements: Sequence<T>) {
|
||||
val set = elements.toHashSet()
|
||||
if (set.isNotEmpty())
|
||||
removeAll(set)
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all elements from this [MutableCollection] that are also contained in the given [array].
|
||||
* Removes all elements from this [MutableCollection] that are also contained in the given [elements] array.
|
||||
*/
|
||||
public fun <T> MutableCollection<in T>.removeAll(array: Array<out T>) {
|
||||
if (array.isNotEmpty())
|
||||
removeAll(array.toHashSet())
|
||||
public fun <T> MutableCollection<in T>.removeAll(elements: Array<out T>) {
|
||||
if (elements.isNotEmpty())
|
||||
removeAll(elements.toHashSet())
|
||||
// else
|
||||
// removeAll(emptyList())
|
||||
}
|
||||
|
||||
/**
|
||||
* Retains only elements of this [MutableCollection] that are contained in the given [iterable].
|
||||
* Retains only elements of this [MutableCollection] that are contained in the given [elements] collection.
|
||||
*/
|
||||
public fun <T> MutableCollection<in T>.retainAll(iterable: Iterable<T>) {
|
||||
retainAll(iterable.convertToSetForSetOperationWith(this))
|
||||
public fun <T> MutableCollection<in T>.retainAll(elements: Iterable<T>) {
|
||||
retainAll(elements.convertToSetForSetOperationWith(this))
|
||||
}
|
||||
|
||||
/**
|
||||
* Retains only elements of this [MutableCollection] that are contained in the given [array].
|
||||
* Retains only elements of this [MutableCollection] that are contained in the given [elements] array.
|
||||
*/
|
||||
public fun <T> MutableCollection<in T>.retainAll(array: Array<out T>) {
|
||||
if (array.isNotEmpty())
|
||||
retainAll(array.toHashSet())
|
||||
public fun <T> MutableCollection<in T>.retainAll(elements: Array<out T>) {
|
||||
if (elements.isNotEmpty())
|
||||
retainAll(elements.toHashSet())
|
||||
else
|
||||
clear()
|
||||
// retainAll(emptyList())
|
||||
}
|
||||
|
||||
/**
|
||||
* Retains only elements of this [MutableCollection] that are contained in the given [sequence].
|
||||
* Retains only elements of this [MutableCollection] that are contained in the given [elements] sequence.
|
||||
*/
|
||||
public fun <T> MutableCollection<in T>.retainAll(sequence: Sequence<T>) {
|
||||
val set = sequence.toHashSet()
|
||||
public fun <T> MutableCollection<in T>.retainAll(elements: Sequence<T>) {
|
||||
val set = elements.toHashSet()
|
||||
if (set.isNotEmpty())
|
||||
retainAll(set)
|
||||
else
|
||||
|
||||
@@ -14,8 +14,8 @@ internal object EmptySet : Set<Nothing>, Serializable {
|
||||
|
||||
override val size: Int get() = 0
|
||||
override fun isEmpty(): Boolean = true
|
||||
override fun contains(o: Nothing): Boolean = false
|
||||
override fun containsAll(c: Collection<Nothing>): Boolean = c.isEmpty()
|
||||
override fun contains(element: Nothing): Boolean = false
|
||||
override fun containsAll(elements: Collection<Nothing>): Boolean = elements.isEmpty()
|
||||
|
||||
override fun iterator(): Iterator<Nothing> = EmptyIterator
|
||||
|
||||
@@ -26,37 +26,37 @@ internal object EmptySet : Set<Nothing>, Serializable {
|
||||
/** Returns an empty read-only set. The returned set is serializable (JVM). */
|
||||
public fun <T> emptySet(): Set<T> = EmptySet
|
||||
/** Returns a new read-only ordered set with the given elements. The returned set is serializable (JVM). */
|
||||
public fun <T> setOf(vararg values: T): Set<T> = if (values.size > 0) values.toSet() else emptySet()
|
||||
public fun <T> setOf(vararg elements: T): Set<T> = if (elements.size > 0) elements.toSet() else emptySet()
|
||||
|
||||
/** Returns an empty read-only set. The returned set is serializable (JVM). */
|
||||
public fun <T> setOf(): Set<T> = emptySet()
|
||||
|
||||
|
||||
/** Returns a new [HashSet] with the given elements. */
|
||||
public fun <T> hashSetOf(vararg values: T): HashSet<T> = values.toCollection(HashSet(mapCapacity(values.size)))
|
||||
public fun <T> hashSetOf(vararg elements: T): HashSet<T> = elements.toCollection(HashSet(mapCapacity(elements.size)))
|
||||
|
||||
/** Returns a new [LinkedHashSet] with the given elements. */
|
||||
public fun <T> linkedSetOf(vararg values: T): LinkedHashSet<T> = values.toCollection(LinkedHashSet(mapCapacity(values.size)))
|
||||
public fun <T> linkedSetOf(vararg elements: T): LinkedHashSet<T> = elements.toCollection(LinkedHashSet(mapCapacity(elements.size)))
|
||||
|
||||
/** Returns this Set if it's not `null` and the empty set otherwise. */
|
||||
public fun <T> Set<T>?.orEmpty(): Set<T> = this ?: emptySet()
|
||||
|
||||
/**
|
||||
* Returns an immutable set containing only the specified object [value].
|
||||
* Returns an immutable set containing only the specified object [element].
|
||||
* The returned set is serializable.
|
||||
*/
|
||||
@JvmVersion
|
||||
public fun <T> setOf(value: T): Set<T> = Collections.singleton(value)
|
||||
public fun <T> setOf(element: T): Set<T> = Collections.singleton(element)
|
||||
|
||||
|
||||
/**
|
||||
* Returns a new [SortedSet] with the given elements.
|
||||
*/
|
||||
@JvmVersion
|
||||
public fun <T> sortedSetOf(vararg values: T): TreeSet<T> = values.toCollection(TreeSet<T>())
|
||||
public fun <T> sortedSetOf(vararg elements: T): TreeSet<T> = elements.toCollection(TreeSet<T>())
|
||||
|
||||
/**
|
||||
* Returns a new [SortedSet] with the given [comparator] and elements.
|
||||
*/
|
||||
@JvmVersion
|
||||
public fun <T> sortedSetOf(comparator: Comparator<in T>, vararg values: T): TreeSet<T> = values.toCollection(TreeSet<T>(comparator))
|
||||
public fun <T> sortedSetOf(comparator: Comparator<in T>, vararg elements: T): TreeSet<T> = elements.toCollection(TreeSet<T>(comparator))
|
||||
|
||||
Reference in New Issue
Block a user