Extension method to convert Enumeration to List
This commit is contained in:
committed by
Andrey Breslav
parent
cbc0e6404e
commit
f14ca2cf89
@@ -1,12 +1,14 @@
|
|||||||
package kotlin
|
package kotlin
|
||||||
|
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Helper to make java.util.Enumeration usable in for
|
Helper to make java.util.Enumeration usable in for
|
||||||
*/
|
*/
|
||||||
public fun <T> java.util.Enumeration<T>.iterator(): Iterator<T> = object: Iterator<T> {
|
public fun <T> java.util.Enumeration<T>.iterator(): Iterator<T> = object: Iterator<T> {
|
||||||
override fun hasNext(): Boolean = hasMoreElements()
|
override fun hasNext(): Boolean = hasMoreElements()
|
||||||
|
|
||||||
public override fun next() : T = nextElement()
|
public override fun next(): T = nextElement()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -58,3 +58,11 @@ public fun <K, V> linkedMapOf(vararg values: Pair<K, V>): LinkedHashMap<K, V> {
|
|||||||
/** Returns the Set if its not null otherwise returns the empty set */
|
/** Returns the Set if its not null otherwise returns the empty set */
|
||||||
public fun <T> Set<T>?.orEmpty(): Set<T>
|
public fun <T> Set<T>?.orEmpty(): Set<T>
|
||||||
= if (this != null) this else Collections.EMPTY_SET as Set<T>
|
= if (this != null) this else Collections.EMPTY_SET as Set<T>
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a list containing the elements returned by the
|
||||||
|
* specified enumeration in the order they are returned by the
|
||||||
|
* enumeration.
|
||||||
|
*/
|
||||||
|
fun <T> Enumeration<T>.toList(): List<T> = Collections.list(this)
|
||||||
|
|||||||
Reference in New Issue
Block a user