KT-3715 make Collection.notEmpty a property
Renamed "notEmpty()" methods to "isNotEmpty()" in following classes:
- Collection
- String
- Array
Added "notEmpty" property to Collection class
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package kotlin
|
||||
|
||||
/** Returns true if the array is not empty */
|
||||
public inline fun <T> Array<T>.notEmpty() : Boolean = !this.isEmpty()
|
||||
public inline fun <T> Array<T>.isNotEmpty() : Boolean = !this.isEmpty()
|
||||
|
||||
/** Returns true if the array is empty */
|
||||
public inline fun <T> Array<T>.isEmpty() : Boolean = this.size == 0
|
||||
|
||||
@@ -17,7 +17,11 @@ val Int.indices: IntRange
|
||||
get() = 0..this-1
|
||||
|
||||
/** Returns true if the collection is not empty */
|
||||
public inline fun <T> Collection<T>.notEmpty() : Boolean = !this.isEmpty()
|
||||
public inline fun <T> Collection<T>.isNotEmpty() : Boolean = !this.isEmpty()
|
||||
|
||||
/** Returns true if this collection is empty */
|
||||
val Collection<*>.notEmpty : Boolean
|
||||
get() = isNotEmpty()
|
||||
|
||||
/** Returns the Collection if its not null otherwise it returns the empty list */
|
||||
public inline fun <T> Collection<T>?.orEmpty() : Collection<T>
|
||||
|
||||
@@ -30,7 +30,7 @@ public inline fun String.trimTrailing(postfix: String): String {
|
||||
}
|
||||
|
||||
/** Returns true if the string is not null and not empty */
|
||||
public inline fun String?.notEmpty() : Boolean = this != null && this.length() > 0
|
||||
public inline fun String?.isNotEmpty() : Boolean = this != null && this.length() > 0
|
||||
|
||||
/**
|
||||
Iterator for characters of given CharSequence
|
||||
|
||||
@@ -179,7 +179,7 @@ get() = length()
|
||||
* @includeFunctionBody ../../test/StringTest.kt capitalize
|
||||
*/
|
||||
public inline fun String.capitalize(): String {
|
||||
return if (notEmpty() && charAt(0).isLowerCase()) substring(0, 1).toUpperCase() + substring(1) else this
|
||||
return if (isNotEmpty() && charAt(0).isLowerCase()) substring(0, 1).toUpperCase() + substring(1) else this
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -188,7 +188,7 @@ public inline fun String.capitalize(): String {
|
||||
* @includeFunctionBody ../../test/StringTest.kt decapitalize
|
||||
*/
|
||||
public inline fun String.decapitalize(): String {
|
||||
return if (notEmpty() && charAt(0).isUpperCase()) substring(0, 1).toLowerCase() + substring(1) else this
|
||||
return if (isNotEmpty() && charAt(0).isUpperCase()) substring(0, 1).toLowerCase() + substring(1) else this
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user