Extension method to convert Enumeration to List

This commit is contained in:
Ilya Ryzhenkov
2014-04-14 17:29:11 +04:00
committed by Andrey Breslav
parent cbc0e6404e
commit f14ca2cf89
2 changed files with 11 additions and 1 deletions
@@ -1,12 +1,14 @@
package kotlin
import java.util.*
/**
Helper to make java.util.Enumeration usable in for
*/
public fun <T> java.util.Enumeration<T>.iterator(): Iterator<T> = object: Iterator<T> {
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 */
public fun <T> Set<T>?.orEmpty(): 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)