added not null helper methods for Set and Map
This commit is contained in:
@@ -55,8 +55,12 @@ inline fun <in T: java.lang.Comparable<T>> List<T>.sort(comparator: java.util.Co
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Converts the nullable List into an empty List if its null */
|
/** Converts the nullable List into an empty List if its null */
|
||||||
inline fun <T> java.util.List<T>?.notNull() : List<T>
|
inline fun <T> java.util.List<T>?.notNull() : java.util.List<T>
|
||||||
= if (this != null) this else Collections.EMPTY_LIST as List<T>
|
= if (this != null) this else Collections.EMPTY_LIST as java.util.List<T>
|
||||||
|
|
||||||
|
/** Converts the nullable Set into an empty Set if its null */
|
||||||
|
inline fun <T> java.util.Set<T>?.notNull() : java.util.Set<T>
|
||||||
|
= if (this != null) this else Collections.EMPTY_SET as java.util.Set<T>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
TODO figure out necessary variance/generics ninja stuff... :)
|
TODO figure out necessary variance/generics ninja stuff... :)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package std.util
|
|||||||
|
|
||||||
import java.util.Map as JMap
|
import java.util.Map as JMap
|
||||||
import java.util.HashMap
|
import java.util.HashMap
|
||||||
|
import java.util.Collections
|
||||||
|
|
||||||
// Temporary workaround: commenting out
|
// Temporary workaround: commenting out
|
||||||
//import java.util.Map.Entry as JEntry
|
//import java.util.Map.Entry as JEntry
|
||||||
@@ -19,6 +20,10 @@ val JMap<*,*>.empty : Boolean
|
|||||||
/** Provides [] access to maps */
|
/** Provides [] access to maps */
|
||||||
fun <K, V> JMap<K, V>.set(key : K, value : V) = this.put(key, value)
|
fun <K, V> JMap<K, V>.set(key : K, value : V) = this.put(key, value)
|
||||||
|
|
||||||
|
/** Converts the nullable Map into an empty Map if its null */
|
||||||
|
inline fun <K,V> java.util.Map<K,V>?.notNull() : java.util.Map<K,V>
|
||||||
|
= if (this != null) this else Collections.EMPTY_MAP as java.util.Map<K,V>
|
||||||
|
|
||||||
|
|
||||||
/** Returns the key of the entry */
|
/** Returns the key of the entry */
|
||||||
// Temporary workaround: commenting out
|
// Temporary workaround: commenting out
|
||||||
|
|||||||
Reference in New Issue
Block a user