Skip to content

Commit fe12ef1

Browse files
committed
fix tests
1 parent 78f4dab commit fe12ef1

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

core/src/main/java/com/hoc/flowmvi/core/NonEmptySet.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ package com.hoc.flowmvi.core
33
/**
44
* `NonEmptySet` is a data type used to model sets that guarantee to have at least one value.
55
*/
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>() {
79
init {
810
require(set.isNotEmpty()) { "Set must not be empty" }
911
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>()
4749
*/
4850
@JvmStatic
4951
fun <T> of(element: T, vararg elements: T): NonEmptySet<T> = NonEmptySet(
50-
LinkedHashSet<T>(1 + elements.size).apply {
52+
buildSet(capacity = 1 + elements.size) {
5153
add(element)
5254
addAll(elements)
5355
}
5456
)
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))
5563
}
5664
}

0 commit comments

Comments
 (0)