standard library: added isEmpty/isNotEmpty functions for primitive arrays

This commit is contained in:
nik
2013-12-01 15:02:45 +04:00
committed by Evgeny Gerashchenko
parent b636538422
commit 45e9211943
12 changed files with 171 additions and 6 deletions
@@ -183,6 +183,20 @@ public inline fun <K> BooleanArray.groupByTo(result: MutableMap<K, MutableList<B
return result
}
/**
* Returns true if the array is empty
*/
public fun BooleanArray.isEmpty() : Boolean {
return size == 0
}
/**
* Returns true if the array is empty
*/
public fun BooleanArray.isNotEmpty() : Boolean {
return !isEmpty()
}
/**
* Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied.
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
@@ -183,6 +183,20 @@ public inline fun <K> ByteArray.groupByTo(result: MutableMap<K, MutableList<Byte
return result
}
/**
* Returns true if the array is empty
*/
public fun ByteArray.isEmpty() : Boolean {
return size == 0
}
/**
* Returns true if the array is empty
*/
public fun ByteArray.isNotEmpty() : Boolean {
return !isEmpty()
}
/**
* Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied.
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
@@ -183,6 +183,20 @@ public inline fun <K> CharArray.groupByTo(result: MutableMap<K, MutableList<Char
return result
}
/**
* Returns true if the array is empty
*/
public fun CharArray.isEmpty() : Boolean {
return size == 0
}
/**
* Returns true if the array is empty
*/
public fun CharArray.isNotEmpty() : Boolean {
return !isEmpty()
}
/**
* Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied.
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
@@ -183,6 +183,20 @@ public inline fun <K> DoubleArray.groupByTo(result: MutableMap<K, MutableList<Do
return result
}
/**
* Returns true if the array is empty
*/
public fun DoubleArray.isEmpty() : Boolean {
return size == 0
}
/**
* Returns true if the array is empty
*/
public fun DoubleArray.isNotEmpty() : Boolean {
return !isEmpty()
}
/**
* Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied.
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
@@ -183,6 +183,20 @@ public inline fun <K> FloatArray.groupByTo(result: MutableMap<K, MutableList<Flo
return result
}
/**
* Returns true if the array is empty
*/
public fun FloatArray.isEmpty() : Boolean {
return size == 0
}
/**
* Returns true if the array is empty
*/
public fun FloatArray.isNotEmpty() : Boolean {
return !isEmpty()
}
/**
* Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied.
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
@@ -183,6 +183,20 @@ public inline fun <K> IntArray.groupByTo(result: MutableMap<K, MutableList<Int>>
return result
}
/**
* Returns true if the array is empty
*/
public fun IntArray.isEmpty() : Boolean {
return size == 0
}
/**
* Returns true if the array is empty
*/
public fun IntArray.isNotEmpty() : Boolean {
return !isEmpty()
}
/**
* Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied.
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
@@ -183,6 +183,20 @@ public inline fun <K> LongArray.groupByTo(result: MutableMap<K, MutableList<Long
return result
}
/**
* Returns true if the array is empty
*/
public fun LongArray.isEmpty() : Boolean {
return size == 0
}
/**
* Returns true if the array is empty
*/
public fun LongArray.isNotEmpty() : Boolean {
return !isEmpty()
}
/**
* Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied.
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
@@ -183,6 +183,20 @@ public inline fun <K> ShortArray.groupByTo(result: MutableMap<K, MutableList<Sho
return result
}
/**
* Returns true if the array is empty
*/
public fun ShortArray.isEmpty() : Boolean {
return size == 0
}
/**
* Returns true if the array is empty
*/
public fun ShortArray.isNotEmpty() : Boolean {
return !isEmpty()
}
/**
* Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied.
* If a collection could be huge you can specify a non-negative value of *limit* which will only show a subset of the collection then it will
+24
View File
@@ -59,6 +59,30 @@ class ArraysJVMTest {
}
}
test fun isEmpty() {
assertTrue(intArray().isEmpty())
assertFalse(intArray(1).isEmpty())
assertTrue(byteArray().isEmpty())
assertFalse(byteArray(1).isEmpty())
assertTrue(shortArray().isEmpty())
assertFalse(shortArray(1).isEmpty())
assertTrue(longArray().isEmpty())
assertFalse(longArray(1).isEmpty())
assertTrue(charArray().isEmpty())
assertFalse(charArray('a').isEmpty())
assertTrue(floatArray().isEmpty())
assertFalse(floatArray(0.1).isEmpty())
assertTrue(doubleArray().isEmpty())
assertFalse(doubleArray(0.1).isEmpty())
assertTrue(booleanArray().isEmpty())
assertFalse(booleanArray(false).isEmpty())
}
test fun isNotEmpty() {
assertFalse(intArray().isNotEmpty())
assertTrue(intArray(1).isNotEmpty())
}
test fun min() {
expect(null, { intArray().min() })
expect(1, { intArray(1).min() })