File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed
core/src/main/java/com/hoc/flowmvi/core Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,9 @@ package com.hoc.flowmvi.core
3
3
/* *
4
4
* `NonEmptySet` is a data type used to model sets that guarantee to have at least one value.
5
5
*/
6
- class NonEmptySet <out T > private constructor(val set : Set <T >) : AbstractSet<T>() {
6
+ class NonEmptySet <out T >
7
+ @Throws(IllegalArgumentException ::class )
8
+ private constructor (val set: Set <T >) : AbstractSet <T >() {
7
9
init {
8
10
require(set.isNotEmpty()) { " Set must not be empty" }
9
11
require(set !is NonEmptySet <T >) { " Set must not be NonEmptySet" }
@@ -47,10 +49,16 @@ class NonEmptySet<out T> private constructor(val set: Set<T>) : AbstractSet<T>()
47
49
*/
48
50
@JvmStatic
49
51
fun <T > of (element : T , vararg elements : T ): NonEmptySet <T > = NonEmptySet (
50
- LinkedHashSet < T >( 1 + elements.size). apply {
52
+ buildSet(capacity = 1 + elements.size) {
51
53
add(element)
52
54
addAll(elements)
53
55
}
54
56
)
57
+
58
+ /* *
59
+ * Creates a [NonEmptySet] that contains only the specified [element].
60
+ */
61
+ @JvmStatic
62
+ fun <T > of (element : T ): NonEmptySet <T > = NonEmptySet (setOf (element))
55
63
}
56
64
}
You can’t perform that action at this time.
0 commit comments