refactor .notNull() to be .orEmpty() which is a better name

This commit is contained in:
James Strachan
2012-03-05 13:15:51 +00:00
parent 0b60105824
commit 12875e1ca2
5 changed files with 13 additions and 13 deletions
@@ -51,8 +51,8 @@ class JavadocStyleHtmlDoclet() : Doclet {
classes.addAll(pmap.keySet())
for (c in classes) {
if (c != null) {
val functions = map.get(c).notNull()
val properties = pmap.get(c).notNull()
val functions = map.get(c).orEmpty()
val properties = pmap.get(c).orEmpty()
run("${p.nameAsPath}/${c.nameAsPath}-extensions.html",
ClassExtensionsTemplate(model, p, c, functions, properties))
}
@@ -78,7 +78,7 @@ abstract class KDocTemplate() : TextTemplate() {
if ((cname.startsWith("jet.Function") || cname.startsWith("jet.ExtensionFunction")) && arguments.notEmpty()) {
val rt = arguments.last()
// TODO use drop()
val rest = arguments.subList(0, arguments.size - 1).notNull()
val rest = arguments.subList(0, arguments.size - 1).orEmpty()
"${typeArguments(rest, "(", ")", "()")}&nbsp;<A HREF=\"${href(c)}\" title=\"${c.kind} in ${c.packageName}\">-&gt;</a>&nbsp;${link(rt)}"
} else if (cname.startsWith("jet.Tuple")) {
if (arguments.isEmpty()) {
@@ -45,7 +45,7 @@ fun inheritedExtensionFunctions(functions: Collection<KFunction>): Map<KClass, S
// for each class, lets walk its base classes and add any other extension functions from base classes
val answer = TreeMap<KClass, SortedSet<KFunction>>()
for (c in map.keySet()) {
val allFunctions = map.get(c).notNull().toSortedSet()
val allFunctions = map.get(c).orEmpty().toSortedSet()
answer.put(c, allFunctions)
val des = c.descendants()
for (b in des) {
@@ -73,7 +73,7 @@ fun inheritedExtensionProperties(properties: Collection<KProperty>): Map<KClass,
// for each class, lets walk its base classes and add any other extension properties from base classes
val answer = TreeMap<KClass, SortedSet<KProperty>>()
for (c in map.keySet()) {
val allProperties = map.get(c).notNull().toSortedSet()
val allProperties = map.get(c).orEmpty().toSortedSet()
answer.put(c, allProperties)
val des = c.descendants()
for (b in des) {
+6 -6
View File
@@ -54,12 +54,12 @@ inline fun <in T: java.lang.Comparable<T>> List<T>.sort(comparator: java.util.Co
return this
}
/** Converts the nullable List into an empty List if its null */
inline fun <T> java.util.List<T>?.notNull() : java.util.List<T>
/** Returns the List if its not null otherwise returns the empty list */
inline fun <T> java.util.List<T>?.orEmpty() : java.util.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>
/** Returns the Set if its not null otherwise returns the empty set */
inline fun <T> java.util.Set<T>?.orEmpty() : java.util.Set<T>
= if (this != null) this else Collections.EMPTY_SET as java.util.Set<T>
/**
@@ -99,7 +99,7 @@ val <T> List<T>.last : T?
/** Returns true if the collection is not empty */
inline fun <T> java.util.Collection<T>.notEmpty() : Boolean = !this.isEmpty()
/** Converts the nullable collection into an empty collection if its null */
inline fun <T> java.util.Collection<T>?.notNull() : Collection<T>
/** Returns the Collection if its not null otherwise it returns the empty list */
inline fun <T> java.util.Collection<T>?.orEmpty() : Collection<T>
= if (this != null) this else Collections.EMPTY_LIST as Collection<T>
+2 -2
View File
@@ -20,8 +20,8 @@ val JMap<*,*>.empty : Boolean
/** Provides [] access to maps */
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>
/** Returns the Mao if its not null otherwise it returns the empty Map */
inline fun <K,V> java.util.Map<K,V>?.orEmpty() : java.util.Map<K,V>
= if (this != null) this else Collections.EMPTY_MAP as java.util.Map<K,V>