Skip to content

Commit

Permalink
[Fix] Fix crash in toEnumSet() when set is empty.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanghai committed Jul 7, 2022
1 parent 29e7002 commit 590c8ea
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ fun <T : Enum<T>> enumSetOf(first: T, vararg rest: T): EnumSet<T> = EnumSet.of(f

fun <T> Iterable<T>.toLinkedSet(): LinkedHashSet<T> = toCollection(LinkedHashSet())

fun <T : Enum<T>> Collection<T>.toEnumSet(): EnumSet<T> = EnumSet.copyOf(this)
inline fun <reified T : Enum<T>> Collection<T>.toEnumSet(): EnumSet<T> =
if (isNotEmpty()) EnumSet.copyOf(this) else EnumSet.noneOf(T::class.java)

fun <T : Collection<*>> T.takeIfNotEmpty(): T? = if (isNotEmpty()) this else null

Expand Down

0 comments on commit 590c8ea

Please sign in to comment.