KT-20357: Add samples for linkedSetOf
This commit is contained in:
committed by
Ilya Gorbunov
parent
95300ae31d
commit
4fa5e2d85c
@@ -333,6 +333,28 @@ class Collections {
|
||||
set += listOf(4, 5)
|
||||
assertPrints(set, "[1, 2, 4, 5]")
|
||||
}
|
||||
|
||||
@Sample
|
||||
fun emptyLinkedHashSet() {
|
||||
val set: LinkedHashSet<Int> = linkedSetOf<Int>()
|
||||
|
||||
set.add(1)
|
||||
set.add(3)
|
||||
set.add(2)
|
||||
|
||||
assertPrints(set, "[1, 3, 2]")
|
||||
}
|
||||
|
||||
@Sample
|
||||
fun linkedHashSet() {
|
||||
val set: LinkedHashSet<Int> = linkedSetOf(1, 3, 2)
|
||||
|
||||
assertPrints(set, "[1, 3, 2]")
|
||||
|
||||
set.remove(3)
|
||||
set += listOf(5, 4)
|
||||
assertPrints(set, "[1, 2, 5, 4]")
|
||||
}
|
||||
}
|
||||
|
||||
class Transformations {
|
||||
|
||||
@@ -73,7 +73,10 @@ public inline fun <T> hashSetOf(): HashSet<T> = HashSet()
|
||||
/** Returns a new [HashSet] with the given elements. */
|
||||
public fun <T> hashSetOf(vararg elements: T): HashSet<T> = elements.toCollection(HashSet(mapCapacity(elements.size)))
|
||||
|
||||
/** Returns an empty new [LinkedHashSet]. */
|
||||
/**
|
||||
* Returns an empty new [LinkedHashSet].
|
||||
* @sample samples.collections.Collections.Sets.emptyLinkedHashSet
|
||||
*/
|
||||
@SinceKotlin("1.1")
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun <T> linkedSetOf(): LinkedHashSet<T> = LinkedHashSet()
|
||||
@@ -81,6 +84,7 @@ public inline fun <T> linkedSetOf(): LinkedHashSet<T> = LinkedHashSet()
|
||||
/**
|
||||
* Returns a new [LinkedHashSet] with the given elements.
|
||||
* Elements of the set are iterated in the order they were specified.
|
||||
* @sample samples.collections.Collections.Sets.linkedHashSet
|
||||
*/
|
||||
public fun <T> linkedSetOf(vararg elements: T): LinkedHashSet<T> = elements.toCollection(LinkedHashSet(mapCapacity(elements.size)))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user