Clean size/length/first/head/empty properties and functions.
This commit is contained in:
@@ -323,70 +323,70 @@ public inline fun String.any(predicate: (Char) -> Boolean): Boolean {
|
||||
* Returns the number of elements
|
||||
*/
|
||||
public fun <T> Array<out T>.count(): Int {
|
||||
return size
|
||||
return size()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of elements
|
||||
*/
|
||||
public fun BooleanArray.count(): Int {
|
||||
return size
|
||||
return size()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of elements
|
||||
*/
|
||||
public fun ByteArray.count(): Int {
|
||||
return size
|
||||
return size()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of elements
|
||||
*/
|
||||
public fun CharArray.count(): Int {
|
||||
return size
|
||||
return size()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of elements
|
||||
*/
|
||||
public fun DoubleArray.count(): Int {
|
||||
return size
|
||||
return size()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of elements
|
||||
*/
|
||||
public fun FloatArray.count(): Int {
|
||||
return size
|
||||
return size()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of elements
|
||||
*/
|
||||
public fun IntArray.count(): Int {
|
||||
return size
|
||||
return size()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of elements
|
||||
*/
|
||||
public fun LongArray.count(): Int {
|
||||
return size
|
||||
return size()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of elements
|
||||
*/
|
||||
public fun ShortArray.count(): Int {
|
||||
return size
|
||||
return size()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of elements
|
||||
*/
|
||||
public fun <T> Collection<T>.count(): Int {
|
||||
return size
|
||||
return size()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -402,7 +402,7 @@ public fun <T> Iterable<T>.count(): Int {
|
||||
* Returns the number of elements
|
||||
*/
|
||||
public fun <K, V> Map<K, V>.count(): Int {
|
||||
return size
|
||||
return size()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -418,7 +418,7 @@ public fun <T> Stream<T>.count(): Int {
|
||||
* Returns the number of elements
|
||||
*/
|
||||
public fun String.count(): Int {
|
||||
return size
|
||||
return length()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -650,7 +650,7 @@ public inline fun <R> String.fold(initial: R, operation: (R, Char) -> R): R {
|
||||
* Accumulates value starting with *initial* value and applying *operation* from right to left to each element and current accumulator value
|
||||
*/
|
||||
public inline fun <T, R> Array<out T>.foldRight(initial: R, operation: (T, R) -> R): R {
|
||||
var index = size - 1
|
||||
var index = lastIndex
|
||||
var accumulator = initial
|
||||
while (index >= 0) {
|
||||
accumulator = operation(get(index--), accumulator)
|
||||
@@ -662,7 +662,7 @@ public inline fun <T, R> Array<out T>.foldRight(initial: R, operation: (T, R) ->
|
||||
* Accumulates value starting with *initial* value and applying *operation* from right to left to each element and current accumulator value
|
||||
*/
|
||||
public inline fun <R> BooleanArray.foldRight(initial: R, operation: (Boolean, R) -> R): R {
|
||||
var index = size - 1
|
||||
var index = lastIndex
|
||||
var accumulator = initial
|
||||
while (index >= 0) {
|
||||
accumulator = operation(get(index--), accumulator)
|
||||
@@ -674,7 +674,7 @@ public inline fun <R> BooleanArray.foldRight(initial: R, operation: (Boolean, R)
|
||||
* Accumulates value starting with *initial* value and applying *operation* from right to left to each element and current accumulator value
|
||||
*/
|
||||
public inline fun <R> ByteArray.foldRight(initial: R, operation: (Byte, R) -> R): R {
|
||||
var index = size - 1
|
||||
var index = lastIndex
|
||||
var accumulator = initial
|
||||
while (index >= 0) {
|
||||
accumulator = operation(get(index--), accumulator)
|
||||
@@ -686,7 +686,7 @@ public inline fun <R> ByteArray.foldRight(initial: R, operation: (Byte, R) -> R)
|
||||
* Accumulates value starting with *initial* value and applying *operation* from right to left to each element and current accumulator value
|
||||
*/
|
||||
public inline fun <R> CharArray.foldRight(initial: R, operation: (Char, R) -> R): R {
|
||||
var index = size - 1
|
||||
var index = lastIndex
|
||||
var accumulator = initial
|
||||
while (index >= 0) {
|
||||
accumulator = operation(get(index--), accumulator)
|
||||
@@ -698,7 +698,7 @@ public inline fun <R> CharArray.foldRight(initial: R, operation: (Char, R) -> R)
|
||||
* Accumulates value starting with *initial* value and applying *operation* from right to left to each element and current accumulator value
|
||||
*/
|
||||
public inline fun <R> DoubleArray.foldRight(initial: R, operation: (Double, R) -> R): R {
|
||||
var index = size - 1
|
||||
var index = lastIndex
|
||||
var accumulator = initial
|
||||
while (index >= 0) {
|
||||
accumulator = operation(get(index--), accumulator)
|
||||
@@ -710,7 +710,7 @@ public inline fun <R> DoubleArray.foldRight(initial: R, operation: (Double, R) -
|
||||
* Accumulates value starting with *initial* value and applying *operation* from right to left to each element and current accumulator value
|
||||
*/
|
||||
public inline fun <R> FloatArray.foldRight(initial: R, operation: (Float, R) -> R): R {
|
||||
var index = size - 1
|
||||
var index = lastIndex
|
||||
var accumulator = initial
|
||||
while (index >= 0) {
|
||||
accumulator = operation(get(index--), accumulator)
|
||||
@@ -722,7 +722,7 @@ public inline fun <R> FloatArray.foldRight(initial: R, operation: (Float, R) ->
|
||||
* Accumulates value starting with *initial* value and applying *operation* from right to left to each element and current accumulator value
|
||||
*/
|
||||
public inline fun <R> IntArray.foldRight(initial: R, operation: (Int, R) -> R): R {
|
||||
var index = size - 1
|
||||
var index = lastIndex
|
||||
var accumulator = initial
|
||||
while (index >= 0) {
|
||||
accumulator = operation(get(index--), accumulator)
|
||||
@@ -734,7 +734,7 @@ public inline fun <R> IntArray.foldRight(initial: R, operation: (Int, R) -> R):
|
||||
* Accumulates value starting with *initial* value and applying *operation* from right to left to each element and current accumulator value
|
||||
*/
|
||||
public inline fun <R> LongArray.foldRight(initial: R, operation: (Long, R) -> R): R {
|
||||
var index = size - 1
|
||||
var index = lastIndex
|
||||
var accumulator = initial
|
||||
while (index >= 0) {
|
||||
accumulator = operation(get(index--), accumulator)
|
||||
@@ -746,7 +746,7 @@ public inline fun <R> LongArray.foldRight(initial: R, operation: (Long, R) -> R)
|
||||
* Accumulates value starting with *initial* value and applying *operation* from right to left to each element and current accumulator value
|
||||
*/
|
||||
public inline fun <R> ShortArray.foldRight(initial: R, operation: (Short, R) -> R): R {
|
||||
var index = size - 1
|
||||
var index = lastIndex
|
||||
var accumulator = initial
|
||||
while (index >= 0) {
|
||||
accumulator = operation(get(index--), accumulator)
|
||||
@@ -758,7 +758,7 @@ public inline fun <R> ShortArray.foldRight(initial: R, operation: (Short, R) ->
|
||||
* Accumulates value starting with *initial* value and applying *operation* from right to left to each element and current accumulator value
|
||||
*/
|
||||
public inline fun <T, R> List<T>.foldRight(initial: R, operation: (T, R) -> R): R {
|
||||
var index = size - 1
|
||||
var index = lastIndex
|
||||
var accumulator = initial
|
||||
while (index >= 0) {
|
||||
accumulator = operation(get(index--), accumulator)
|
||||
@@ -770,7 +770,7 @@ public inline fun <T, R> List<T>.foldRight(initial: R, operation: (T, R) -> R):
|
||||
* Accumulates value starting with *initial* value and applying *operation* from right to left to each element and current accumulator value
|
||||
*/
|
||||
public inline fun <R> String.foldRight(initial: R, operation: (Char, R) -> R): R {
|
||||
var index = size - 1
|
||||
var index = lastIndex
|
||||
var accumulator = initial
|
||||
while (index >= 0) {
|
||||
accumulator = operation(get(index--), accumulator)
|
||||
@@ -1499,7 +1499,7 @@ public fun String.min(): Char? {
|
||||
* Returns the first element yielding the smallest value of the given function or null if there are no elements
|
||||
*/
|
||||
public inline fun <R : Comparable<R>, T : Any> Array<out T>.minBy(f: (T) -> R): T? {
|
||||
if (size == 0) return null
|
||||
if (size() == 0) return null
|
||||
var minElem = this[0]
|
||||
var minValue = f(minElem)
|
||||
for (i in 1..lastIndex) {
|
||||
@@ -1517,7 +1517,7 @@ public inline fun <R : Comparable<R>, T : Any> Array<out T>.minBy(f: (T) -> R):
|
||||
* Returns the first element yielding the smallest value of the given function or null if there are no elements
|
||||
*/
|
||||
public inline fun <R : Comparable<R>> BooleanArray.minBy(f: (Boolean) -> R): Boolean? {
|
||||
if (size == 0) return null
|
||||
if (size() == 0) return null
|
||||
var minElem = this[0]
|
||||
var minValue = f(minElem)
|
||||
for (i in 1..lastIndex) {
|
||||
@@ -1535,7 +1535,7 @@ public inline fun <R : Comparable<R>> BooleanArray.minBy(f: (Boolean) -> R): Boo
|
||||
* Returns the first element yielding the smallest value of the given function or null if there are no elements
|
||||
*/
|
||||
public inline fun <R : Comparable<R>> ByteArray.minBy(f: (Byte) -> R): Byte? {
|
||||
if (size == 0) return null
|
||||
if (size() == 0) return null
|
||||
var minElem = this[0]
|
||||
var minValue = f(minElem)
|
||||
for (i in 1..lastIndex) {
|
||||
@@ -1553,7 +1553,7 @@ public inline fun <R : Comparable<R>> ByteArray.minBy(f: (Byte) -> R): Byte? {
|
||||
* Returns the first element yielding the smallest value of the given function or null if there are no elements
|
||||
*/
|
||||
public inline fun <R : Comparable<R>> CharArray.minBy(f: (Char) -> R): Char? {
|
||||
if (size == 0) return null
|
||||
if (size() == 0) return null
|
||||
var minElem = this[0]
|
||||
var minValue = f(minElem)
|
||||
for (i in 1..lastIndex) {
|
||||
@@ -1571,7 +1571,7 @@ public inline fun <R : Comparable<R>> CharArray.minBy(f: (Char) -> R): Char? {
|
||||
* Returns the first element yielding the smallest value of the given function or null if there are no elements
|
||||
*/
|
||||
public inline fun <R : Comparable<R>> DoubleArray.minBy(f: (Double) -> R): Double? {
|
||||
if (size == 0) return null
|
||||
if (size() == 0) return null
|
||||
var minElem = this[0]
|
||||
var minValue = f(minElem)
|
||||
for (i in 1..lastIndex) {
|
||||
@@ -1589,7 +1589,7 @@ public inline fun <R : Comparable<R>> DoubleArray.minBy(f: (Double) -> R): Doubl
|
||||
* Returns the first element yielding the smallest value of the given function or null if there are no elements
|
||||
*/
|
||||
public inline fun <R : Comparable<R>> FloatArray.minBy(f: (Float) -> R): Float? {
|
||||
if (size == 0) return null
|
||||
if (size() == 0) return null
|
||||
var minElem = this[0]
|
||||
var minValue = f(minElem)
|
||||
for (i in 1..lastIndex) {
|
||||
@@ -1607,7 +1607,7 @@ public inline fun <R : Comparable<R>> FloatArray.minBy(f: (Float) -> R): Float?
|
||||
* Returns the first element yielding the smallest value of the given function or null if there are no elements
|
||||
*/
|
||||
public inline fun <R : Comparable<R>> IntArray.minBy(f: (Int) -> R): Int? {
|
||||
if (size == 0) return null
|
||||
if (size() == 0) return null
|
||||
var minElem = this[0]
|
||||
var minValue = f(minElem)
|
||||
for (i in 1..lastIndex) {
|
||||
@@ -1625,7 +1625,7 @@ public inline fun <R : Comparable<R>> IntArray.minBy(f: (Int) -> R): Int? {
|
||||
* Returns the first element yielding the smallest value of the given function or null if there are no elements
|
||||
*/
|
||||
public inline fun <R : Comparable<R>> LongArray.minBy(f: (Long) -> R): Long? {
|
||||
if (size == 0) return null
|
||||
if (size() == 0) return null
|
||||
var minElem = this[0]
|
||||
var minValue = f(minElem)
|
||||
for (i in 1..lastIndex) {
|
||||
@@ -1643,7 +1643,7 @@ public inline fun <R : Comparable<R>> LongArray.minBy(f: (Long) -> R): Long? {
|
||||
* Returns the first element yielding the smallest value of the given function or null if there are no elements
|
||||
*/
|
||||
public inline fun <R : Comparable<R>> ShortArray.minBy(f: (Short) -> R): Short? {
|
||||
if (size == 0) return null
|
||||
if (size() == 0) return null
|
||||
var minElem = this[0]
|
||||
var minValue = f(minElem)
|
||||
for (i in 1..lastIndex) {
|
||||
@@ -2101,7 +2101,7 @@ public inline fun String.reduce(operation: (Char, Char) -> Char): Char {
|
||||
* Accumulates value starting with last element and applying *operation* from right to left to each element and current accumulator value
|
||||
*/
|
||||
public inline fun <T> Array<out T>.reduceRight(operation: (T, T) -> T): T {
|
||||
var index = size - 1
|
||||
var index = lastIndex
|
||||
if (index < 0) throw UnsupportedOperationException("Empty iterable can't be reduced")
|
||||
var accumulator = get(index--)
|
||||
while (index >= 0) {
|
||||
@@ -2114,7 +2114,7 @@ public inline fun <T> Array<out T>.reduceRight(operation: (T, T) -> T): T {
|
||||
* Accumulates value starting with last element and applying *operation* from right to left to each element and current accumulator value
|
||||
*/
|
||||
public inline fun BooleanArray.reduceRight(operation: (Boolean, Boolean) -> Boolean): Boolean {
|
||||
var index = size - 1
|
||||
var index = lastIndex
|
||||
if (index < 0) throw UnsupportedOperationException("Empty iterable can't be reduced")
|
||||
var accumulator = get(index--)
|
||||
while (index >= 0) {
|
||||
@@ -2127,7 +2127,7 @@ public inline fun BooleanArray.reduceRight(operation: (Boolean, Boolean) -> Bool
|
||||
* Accumulates value starting with last element and applying *operation* from right to left to each element and current accumulator value
|
||||
*/
|
||||
public inline fun ByteArray.reduceRight(operation: (Byte, Byte) -> Byte): Byte {
|
||||
var index = size - 1
|
||||
var index = lastIndex
|
||||
if (index < 0) throw UnsupportedOperationException("Empty iterable can't be reduced")
|
||||
var accumulator = get(index--)
|
||||
while (index >= 0) {
|
||||
@@ -2140,7 +2140,7 @@ public inline fun ByteArray.reduceRight(operation: (Byte, Byte) -> Byte): Byte {
|
||||
* Accumulates value starting with last element and applying *operation* from right to left to each element and current accumulator value
|
||||
*/
|
||||
public inline fun CharArray.reduceRight(operation: (Char, Char) -> Char): Char {
|
||||
var index = size - 1
|
||||
var index = lastIndex
|
||||
if (index < 0) throw UnsupportedOperationException("Empty iterable can't be reduced")
|
||||
var accumulator = get(index--)
|
||||
while (index >= 0) {
|
||||
@@ -2153,7 +2153,7 @@ public inline fun CharArray.reduceRight(operation: (Char, Char) -> Char): Char {
|
||||
* Accumulates value starting with last element and applying *operation* from right to left to each element and current accumulator value
|
||||
*/
|
||||
public inline fun DoubleArray.reduceRight(operation: (Double, Double) -> Double): Double {
|
||||
var index = size - 1
|
||||
var index = lastIndex
|
||||
if (index < 0) throw UnsupportedOperationException("Empty iterable can't be reduced")
|
||||
var accumulator = get(index--)
|
||||
while (index >= 0) {
|
||||
@@ -2166,7 +2166,7 @@ public inline fun DoubleArray.reduceRight(operation: (Double, Double) -> Double)
|
||||
* Accumulates value starting with last element and applying *operation* from right to left to each element and current accumulator value
|
||||
*/
|
||||
public inline fun FloatArray.reduceRight(operation: (Float, Float) -> Float): Float {
|
||||
var index = size - 1
|
||||
var index = lastIndex
|
||||
if (index < 0) throw UnsupportedOperationException("Empty iterable can't be reduced")
|
||||
var accumulator = get(index--)
|
||||
while (index >= 0) {
|
||||
@@ -2179,7 +2179,7 @@ public inline fun FloatArray.reduceRight(operation: (Float, Float) -> Float): Fl
|
||||
* Accumulates value starting with last element and applying *operation* from right to left to each element and current accumulator value
|
||||
*/
|
||||
public inline fun IntArray.reduceRight(operation: (Int, Int) -> Int): Int {
|
||||
var index = size - 1
|
||||
var index = lastIndex
|
||||
if (index < 0) throw UnsupportedOperationException("Empty iterable can't be reduced")
|
||||
var accumulator = get(index--)
|
||||
while (index >= 0) {
|
||||
@@ -2192,7 +2192,7 @@ public inline fun IntArray.reduceRight(operation: (Int, Int) -> Int): Int {
|
||||
* Accumulates value starting with last element and applying *operation* from right to left to each element and current accumulator value
|
||||
*/
|
||||
public inline fun LongArray.reduceRight(operation: (Long, Long) -> Long): Long {
|
||||
var index = size - 1
|
||||
var index = lastIndex
|
||||
if (index < 0) throw UnsupportedOperationException("Empty iterable can't be reduced")
|
||||
var accumulator = get(index--)
|
||||
while (index >= 0) {
|
||||
@@ -2205,7 +2205,7 @@ public inline fun LongArray.reduceRight(operation: (Long, Long) -> Long): Long {
|
||||
* Accumulates value starting with last element and applying *operation* from right to left to each element and current accumulator value
|
||||
*/
|
||||
public inline fun ShortArray.reduceRight(operation: (Short, Short) -> Short): Short {
|
||||
var index = size - 1
|
||||
var index = lastIndex
|
||||
if (index < 0) throw UnsupportedOperationException("Empty iterable can't be reduced")
|
||||
var accumulator = get(index--)
|
||||
while (index >= 0) {
|
||||
@@ -2218,7 +2218,7 @@ public inline fun ShortArray.reduceRight(operation: (Short, Short) -> Short): Sh
|
||||
* Accumulates value starting with last element and applying *operation* from right to left to each element and current accumulator value
|
||||
*/
|
||||
public inline fun <T> List<T>.reduceRight(operation: (T, T) -> T): T {
|
||||
var index = size - 1
|
||||
var index = lastIndex
|
||||
if (index < 0) throw UnsupportedOperationException("Empty iterable can't be reduced")
|
||||
var accumulator = get(index--)
|
||||
while (index >= 0) {
|
||||
@@ -2231,7 +2231,7 @@ public inline fun <T> List<T>.reduceRight(operation: (T, T) -> T): T {
|
||||
* Accumulates value starting with last element and applying *operation* from right to left to each element and current accumulator value
|
||||
*/
|
||||
public inline fun String.reduceRight(operation: (Char, Char) -> Char): Char {
|
||||
var index = size - 1
|
||||
var index = lastIndex
|
||||
if (index < 0) throw UnsupportedOperationException("Empty iterable can't be reduced")
|
||||
var accumulator = get(index--)
|
||||
while (index >= 0) {
|
||||
|
||||
@@ -11,63 +11,63 @@ import java.util.*
|
||||
* Returns true if the array is empty
|
||||
*/
|
||||
public fun <T> Array<out T>.isEmpty(): Boolean {
|
||||
return size == 0
|
||||
return size() == 0
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the array is empty
|
||||
*/
|
||||
public fun BooleanArray.isEmpty(): Boolean {
|
||||
return size == 0
|
||||
return size() == 0
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the array is empty
|
||||
*/
|
||||
public fun ByteArray.isEmpty(): Boolean {
|
||||
return size == 0
|
||||
return size() == 0
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the array is empty
|
||||
*/
|
||||
public fun CharArray.isEmpty(): Boolean {
|
||||
return size == 0
|
||||
return size() == 0
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the array is empty
|
||||
*/
|
||||
public fun DoubleArray.isEmpty(): Boolean {
|
||||
return size == 0
|
||||
return size() == 0
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the array is empty
|
||||
*/
|
||||
public fun FloatArray.isEmpty(): Boolean {
|
||||
return size == 0
|
||||
return size() == 0
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the array is empty
|
||||
*/
|
||||
public fun IntArray.isEmpty(): Boolean {
|
||||
return size == 0
|
||||
return size() == 0
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the array is empty
|
||||
*/
|
||||
public fun LongArray.isEmpty(): Boolean {
|
||||
return size == 0
|
||||
return size() == 0
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the array is empty
|
||||
*/
|
||||
public fun ShortArray.isEmpty(): Boolean {
|
||||
return size == 0
|
||||
return size() == 0
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -549,7 +549,7 @@ public fun String.elementAt(index: Int): Char {
|
||||
* Returns first element
|
||||
*/
|
||||
public fun <T> Array<out T>.first(): T {
|
||||
if (size == 0)
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Collection is empty")
|
||||
return this[0]
|
||||
}
|
||||
@@ -558,7 +558,7 @@ public fun <T> Array<out T>.first(): T {
|
||||
* Returns first element
|
||||
*/
|
||||
public fun BooleanArray.first(): Boolean {
|
||||
if (size == 0)
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Collection is empty")
|
||||
return this[0]
|
||||
}
|
||||
@@ -567,7 +567,7 @@ public fun BooleanArray.first(): Boolean {
|
||||
* Returns first element
|
||||
*/
|
||||
public fun ByteArray.first(): Byte {
|
||||
if (size == 0)
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Collection is empty")
|
||||
return this[0]
|
||||
}
|
||||
@@ -576,7 +576,7 @@ public fun ByteArray.first(): Byte {
|
||||
* Returns first element
|
||||
*/
|
||||
public fun CharArray.first(): Char {
|
||||
if (size == 0)
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Collection is empty")
|
||||
return this[0]
|
||||
}
|
||||
@@ -585,7 +585,7 @@ public fun CharArray.first(): Char {
|
||||
* Returns first element
|
||||
*/
|
||||
public fun DoubleArray.first(): Double {
|
||||
if (size == 0)
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Collection is empty")
|
||||
return this[0]
|
||||
}
|
||||
@@ -594,7 +594,7 @@ public fun DoubleArray.first(): Double {
|
||||
* Returns first element
|
||||
*/
|
||||
public fun FloatArray.first(): Float {
|
||||
if (size == 0)
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Collection is empty")
|
||||
return this[0]
|
||||
}
|
||||
@@ -603,7 +603,7 @@ public fun FloatArray.first(): Float {
|
||||
* Returns first element
|
||||
*/
|
||||
public fun IntArray.first(): Int {
|
||||
if (size == 0)
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Collection is empty")
|
||||
return this[0]
|
||||
}
|
||||
@@ -612,7 +612,7 @@ public fun IntArray.first(): Int {
|
||||
* Returns first element
|
||||
*/
|
||||
public fun LongArray.first(): Long {
|
||||
if (size == 0)
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Collection is empty")
|
||||
return this[0]
|
||||
}
|
||||
@@ -621,7 +621,7 @@ public fun LongArray.first(): Long {
|
||||
* Returns first element
|
||||
*/
|
||||
public fun ShortArray.first(): Short {
|
||||
if (size == 0)
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Collection is empty")
|
||||
return this[0]
|
||||
}
|
||||
@@ -632,7 +632,7 @@ public fun ShortArray.first(): Short {
|
||||
public fun <T> Iterable<T>.first(): T {
|
||||
when (this) {
|
||||
is List<*> -> {
|
||||
if (size == 0)
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Collection is empty")
|
||||
else
|
||||
return this[0] as T
|
||||
@@ -650,7 +650,7 @@ public fun <T> Iterable<T>.first(): T {
|
||||
* Returns first element
|
||||
*/
|
||||
public fun <T> List<T>.first(): T {
|
||||
if (size == 0)
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Collection is empty")
|
||||
return this[0]
|
||||
}
|
||||
@@ -661,7 +661,7 @@ public fun <T> List<T>.first(): T {
|
||||
public fun <T> Stream<T>.first(): T {
|
||||
when (this) {
|
||||
is List<*> -> {
|
||||
if (size == 0)
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Collection is empty")
|
||||
else
|
||||
return this[0] as T
|
||||
@@ -679,7 +679,7 @@ public fun <T> Stream<T>.first(): T {
|
||||
* Returns first element
|
||||
*/
|
||||
public fun String.first(): Char {
|
||||
if (size == 0)
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Collection is empty")
|
||||
return this[0]
|
||||
}
|
||||
@@ -784,63 +784,63 @@ public inline fun String.first(predicate: (Char) -> Boolean): Char {
|
||||
* Returns first element, or null if collection is empty
|
||||
*/
|
||||
public fun <T> Array<out T>.firstOrNull(): T? {
|
||||
return if (size > 0) this[0] else null
|
||||
return if (isEmpty()) null else this[0]
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns first element, or null if collection is empty
|
||||
*/
|
||||
public fun BooleanArray.firstOrNull(): Boolean? {
|
||||
return if (size > 0) this[0] else null
|
||||
return if (isEmpty()) null else this[0]
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns first element, or null if collection is empty
|
||||
*/
|
||||
public fun ByteArray.firstOrNull(): Byte? {
|
||||
return if (size > 0) this[0] else null
|
||||
return if (isEmpty()) null else this[0]
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns first element, or null if collection is empty
|
||||
*/
|
||||
public fun CharArray.firstOrNull(): Char? {
|
||||
return if (size > 0) this[0] else null
|
||||
return if (isEmpty()) null else this[0]
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns first element, or null if collection is empty
|
||||
*/
|
||||
public fun DoubleArray.firstOrNull(): Double? {
|
||||
return if (size > 0) this[0] else null
|
||||
return if (isEmpty()) null else this[0]
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns first element, or null if collection is empty
|
||||
*/
|
||||
public fun FloatArray.firstOrNull(): Float? {
|
||||
return if (size > 0) this[0] else null
|
||||
return if (isEmpty()) null else this[0]
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns first element, or null if collection is empty
|
||||
*/
|
||||
public fun IntArray.firstOrNull(): Int? {
|
||||
return if (size > 0) this[0] else null
|
||||
return if (isEmpty()) null else this[0]
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns first element, or null if collection is empty
|
||||
*/
|
||||
public fun LongArray.firstOrNull(): Long? {
|
||||
return if (size > 0) this[0] else null
|
||||
return if (isEmpty()) null else this[0]
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns first element, or null if collection is empty
|
||||
*/
|
||||
public fun ShortArray.firstOrNull(): Short? {
|
||||
return if (size > 0) this[0] else null
|
||||
return if (isEmpty()) null else this[0]
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -849,7 +849,7 @@ public fun ShortArray.firstOrNull(): Short? {
|
||||
public fun <T> Iterable<T>.firstOrNull(): T? {
|
||||
when (this) {
|
||||
is List<*> -> {
|
||||
if (size == 0)
|
||||
if (isEmpty())
|
||||
return null
|
||||
else
|
||||
return this[0] as T
|
||||
@@ -867,7 +867,7 @@ public fun <T> Iterable<T>.firstOrNull(): T? {
|
||||
* Returns first element, or null if collection is empty
|
||||
*/
|
||||
public fun <T> List<T>.firstOrNull(): T? {
|
||||
return if (size > 0) this[0] else null
|
||||
return if (isEmpty()) null else this[0]
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -876,7 +876,7 @@ public fun <T> List<T>.firstOrNull(): T? {
|
||||
public fun <T> Stream<T>.firstOrNull(): T? {
|
||||
when (this) {
|
||||
is List<*> -> {
|
||||
if (size == 0)
|
||||
if (isEmpty())
|
||||
return null
|
||||
else
|
||||
return this[0] as T
|
||||
@@ -894,7 +894,7 @@ public fun <T> Stream<T>.firstOrNull(): T? {
|
||||
* Returns first element, or null if collection is empty
|
||||
*/
|
||||
public fun String.firstOrNull(): Char? {
|
||||
return if (size > 0) this[0] else null
|
||||
return if (isEmpty()) null else this[0]
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1139,81 +1139,81 @@ public fun <T> Stream<T>.indexOf(element: T): Int {
|
||||
* Returns last element
|
||||
*/
|
||||
public fun <T> Array<out T>.last(): T {
|
||||
if (size == 0)
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Collection is empty")
|
||||
return this[size - 1]
|
||||
return this[lastIndex]
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns last element
|
||||
*/
|
||||
public fun BooleanArray.last(): Boolean {
|
||||
if (size == 0)
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Collection is empty")
|
||||
return this[size - 1]
|
||||
return this[lastIndex]
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns last element
|
||||
*/
|
||||
public fun ByteArray.last(): Byte {
|
||||
if (size == 0)
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Collection is empty")
|
||||
return this[size - 1]
|
||||
return this[lastIndex]
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns last element
|
||||
*/
|
||||
public fun CharArray.last(): Char {
|
||||
if (size == 0)
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Collection is empty")
|
||||
return this[size - 1]
|
||||
return this[lastIndex]
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns last element
|
||||
*/
|
||||
public fun DoubleArray.last(): Double {
|
||||
if (size == 0)
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Collection is empty")
|
||||
return this[size - 1]
|
||||
return this[lastIndex]
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns last element
|
||||
*/
|
||||
public fun FloatArray.last(): Float {
|
||||
if (size == 0)
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Collection is empty")
|
||||
return this[size - 1]
|
||||
return this[lastIndex]
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns last element
|
||||
*/
|
||||
public fun IntArray.last(): Int {
|
||||
if (size == 0)
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Collection is empty")
|
||||
return this[size - 1]
|
||||
return this[lastIndex]
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns last element
|
||||
*/
|
||||
public fun LongArray.last(): Long {
|
||||
if (size == 0)
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Collection is empty")
|
||||
return this[size - 1]
|
||||
return this[lastIndex]
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns last element
|
||||
*/
|
||||
public fun ShortArray.last(): Short {
|
||||
if (size == 0)
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Collection is empty")
|
||||
return this[size - 1]
|
||||
return this[lastIndex]
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1222,10 +1222,10 @@ public fun ShortArray.last(): Short {
|
||||
public fun <T> Iterable<T>.last(): T {
|
||||
when (this) {
|
||||
is List<*> -> {
|
||||
if (size == 0)
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Collection is empty")
|
||||
else
|
||||
return this[size - 1] as T
|
||||
return this[this.lastIndex] as T
|
||||
}
|
||||
else -> {
|
||||
val iterator = iterator()
|
||||
@@ -1243,41 +1243,31 @@ public fun <T> Iterable<T>.last(): T {
|
||||
* Returns last element
|
||||
*/
|
||||
public fun <T> List<T>.last(): T {
|
||||
if (size == 0)
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Collection is empty")
|
||||
return this[size - 1]
|
||||
return this[lastIndex]
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns last element
|
||||
*/
|
||||
public fun <T> Stream<T>.last(): T {
|
||||
when (this) {
|
||||
is List<*> -> {
|
||||
if (size == 0)
|
||||
throw NoSuchElementException("Collection is empty")
|
||||
else
|
||||
return this[size - 1] as T
|
||||
}
|
||||
else -> {
|
||||
val iterator = iterator()
|
||||
if (!iterator.hasNext())
|
||||
throw NoSuchElementException("Collection is empty")
|
||||
var last = iterator.next()
|
||||
while (iterator.hasNext())
|
||||
last = iterator.next()
|
||||
return last
|
||||
}
|
||||
}
|
||||
val iterator = iterator()
|
||||
if (!iterator.hasNext())
|
||||
throw NoSuchElementException("Collection is empty")
|
||||
var last = iterator.next()
|
||||
while (iterator.hasNext())
|
||||
last = iterator.next()
|
||||
return last
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns last element
|
||||
*/
|
||||
public fun String.last(): Char {
|
||||
if (size == 0)
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Collection is empty")
|
||||
return this[size - 1]
|
||||
return this[lastIndex]
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1640,63 +1630,63 @@ public fun <T> Stream<T>.lastIndexOf(element: T): Int {
|
||||
* Returns last element, or null if collection is empty
|
||||
*/
|
||||
public fun <T> Array<out T>.lastOrNull(): T? {
|
||||
return if (size > 0) this[size - 1] else null
|
||||
return if (isEmpty()) null else this[size() - 1]
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns last element, or null if collection is empty
|
||||
*/
|
||||
public fun BooleanArray.lastOrNull(): Boolean? {
|
||||
return if (size > 0) this[size - 1] else null
|
||||
return if (isEmpty()) null else this[size() - 1]
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns last element, or null if collection is empty
|
||||
*/
|
||||
public fun ByteArray.lastOrNull(): Byte? {
|
||||
return if (size > 0) this[size - 1] else null
|
||||
return if (isEmpty()) null else this[size() - 1]
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns last element, or null if collection is empty
|
||||
*/
|
||||
public fun CharArray.lastOrNull(): Char? {
|
||||
return if (size > 0) this[size - 1] else null
|
||||
return if (isEmpty()) null else this[size() - 1]
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns last element, or null if collection is empty
|
||||
*/
|
||||
public fun DoubleArray.lastOrNull(): Double? {
|
||||
return if (size > 0) this[size - 1] else null
|
||||
return if (isEmpty()) null else this[size() - 1]
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns last element, or null if collection is empty
|
||||
*/
|
||||
public fun FloatArray.lastOrNull(): Float? {
|
||||
return if (size > 0) this[size - 1] else null
|
||||
return if (isEmpty()) null else this[size() - 1]
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns last element, or null if collection is empty
|
||||
*/
|
||||
public fun IntArray.lastOrNull(): Int? {
|
||||
return if (size > 0) this[size - 1] else null
|
||||
return if (isEmpty()) null else this[size() - 1]
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns last element, or null if collection is empty
|
||||
*/
|
||||
public fun LongArray.lastOrNull(): Long? {
|
||||
return if (size > 0) this[size - 1] else null
|
||||
return if (isEmpty()) null else this[size() - 1]
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns last element, or null if collection is empty
|
||||
*/
|
||||
public fun ShortArray.lastOrNull(): Short? {
|
||||
return if (size > 0) this[size - 1] else null
|
||||
return if (isEmpty()) null else this[size() - 1]
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1704,7 +1694,7 @@ public fun ShortArray.lastOrNull(): Short? {
|
||||
*/
|
||||
public fun <T> Iterable<T>.lastOrNull(): T? {
|
||||
when (this) {
|
||||
is List<*> -> return if (size > 0) this[size - 1] as T else null
|
||||
is List<*> -> return if (isEmpty()) null else this[size() - 1] as T
|
||||
else -> {
|
||||
val iterator = iterator()
|
||||
if (!iterator.hasNext())
|
||||
@@ -1721,32 +1711,27 @@ public fun <T> Iterable<T>.lastOrNull(): T? {
|
||||
* Returns last element, or null if collection is empty
|
||||
*/
|
||||
public fun <T> List<T>.lastOrNull(): T? {
|
||||
return if (size > 0) this[size - 1] else null
|
||||
return if (isEmpty()) null else this[size() - 1]
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns last element, or null if collection is empty
|
||||
*/
|
||||
public fun <T> Stream<T>.lastOrNull(): T? {
|
||||
when (this) {
|
||||
is List<*> -> return if (size > 0) this[size - 1] as T else null
|
||||
else -> {
|
||||
val iterator = iterator()
|
||||
if (!iterator.hasNext())
|
||||
return null
|
||||
var last = iterator.next()
|
||||
while (iterator.hasNext())
|
||||
last = iterator.next()
|
||||
return last
|
||||
}
|
||||
}
|
||||
val iterator = iterator()
|
||||
if (!iterator.hasNext())
|
||||
return null
|
||||
var last = iterator.next()
|
||||
while (iterator.hasNext())
|
||||
last = iterator.next()
|
||||
return last
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns last element, or null if collection is empty
|
||||
*/
|
||||
public fun String.lastOrNull(): Char? {
|
||||
return if (size > 0) this[size - 1] else null
|
||||
return if (isEmpty()) null else this[length() - 1]
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1909,7 +1894,7 @@ public inline fun String.lastOrNull(predicate: (Char) -> Boolean): Char? {
|
||||
* Returns single element, or throws exception if there is no or more than one element
|
||||
*/
|
||||
public fun <T> Array<out T>.single(): T {
|
||||
return when (size) {
|
||||
return when (size()) {
|
||||
0 -> throw NoSuchElementException("Collection is empty")
|
||||
1 -> this[0]
|
||||
else -> throw IllegalArgumentException("Collection has more than one element")
|
||||
@@ -1920,7 +1905,7 @@ public fun <T> Array<out T>.single(): T {
|
||||
* Returns single element, or throws exception if there is no or more than one element
|
||||
*/
|
||||
public fun BooleanArray.single(): Boolean {
|
||||
return when (size) {
|
||||
return when (size()) {
|
||||
0 -> throw NoSuchElementException("Collection is empty")
|
||||
1 -> this[0]
|
||||
else -> throw IllegalArgumentException("Collection has more than one element")
|
||||
@@ -1931,7 +1916,7 @@ public fun BooleanArray.single(): Boolean {
|
||||
* Returns single element, or throws exception if there is no or more than one element
|
||||
*/
|
||||
public fun ByteArray.single(): Byte {
|
||||
return when (size) {
|
||||
return when (size()) {
|
||||
0 -> throw NoSuchElementException("Collection is empty")
|
||||
1 -> this[0]
|
||||
else -> throw IllegalArgumentException("Collection has more than one element")
|
||||
@@ -1942,7 +1927,7 @@ public fun ByteArray.single(): Byte {
|
||||
* Returns single element, or throws exception if there is no or more than one element
|
||||
*/
|
||||
public fun CharArray.single(): Char {
|
||||
return when (size) {
|
||||
return when (size()) {
|
||||
0 -> throw NoSuchElementException("Collection is empty")
|
||||
1 -> this[0]
|
||||
else -> throw IllegalArgumentException("Collection has more than one element")
|
||||
@@ -1953,7 +1938,7 @@ public fun CharArray.single(): Char {
|
||||
* Returns single element, or throws exception if there is no or more than one element
|
||||
*/
|
||||
public fun DoubleArray.single(): Double {
|
||||
return when (size) {
|
||||
return when (size()) {
|
||||
0 -> throw NoSuchElementException("Collection is empty")
|
||||
1 -> this[0]
|
||||
else -> throw IllegalArgumentException("Collection has more than one element")
|
||||
@@ -1964,7 +1949,7 @@ public fun DoubleArray.single(): Double {
|
||||
* Returns single element, or throws exception if there is no or more than one element
|
||||
*/
|
||||
public fun FloatArray.single(): Float {
|
||||
return when (size) {
|
||||
return when (size()) {
|
||||
0 -> throw NoSuchElementException("Collection is empty")
|
||||
1 -> this[0]
|
||||
else -> throw IllegalArgumentException("Collection has more than one element")
|
||||
@@ -1975,7 +1960,7 @@ public fun FloatArray.single(): Float {
|
||||
* Returns single element, or throws exception if there is no or more than one element
|
||||
*/
|
||||
public fun IntArray.single(): Int {
|
||||
return when (size) {
|
||||
return when (size()) {
|
||||
0 -> throw NoSuchElementException("Collection is empty")
|
||||
1 -> this[0]
|
||||
else -> throw IllegalArgumentException("Collection has more than one element")
|
||||
@@ -1986,7 +1971,7 @@ public fun IntArray.single(): Int {
|
||||
* Returns single element, or throws exception if there is no or more than one element
|
||||
*/
|
||||
public fun LongArray.single(): Long {
|
||||
return when (size) {
|
||||
return when (size()) {
|
||||
0 -> throw NoSuchElementException("Collection is empty")
|
||||
1 -> this[0]
|
||||
else -> throw IllegalArgumentException("Collection has more than one element")
|
||||
@@ -1997,7 +1982,7 @@ public fun LongArray.single(): Long {
|
||||
* Returns single element, or throws exception if there is no or more than one element
|
||||
*/
|
||||
public fun ShortArray.single(): Short {
|
||||
return when (size) {
|
||||
return when (size()) {
|
||||
0 -> throw NoSuchElementException("Collection is empty")
|
||||
1 -> this[0]
|
||||
else -> throw IllegalArgumentException("Collection has more than one element")
|
||||
@@ -2009,7 +1994,7 @@ public fun ShortArray.single(): Short {
|
||||
*/
|
||||
public fun <T> Iterable<T>.single(): T {
|
||||
when (this) {
|
||||
is List<*> -> return when (size) {
|
||||
is List<*> -> return when (size()) {
|
||||
0 -> throw NoSuchElementException("Collection is empty")
|
||||
1 -> this[0] as T
|
||||
else -> throw IllegalArgumentException("Collection has more than one element")
|
||||
@@ -2030,7 +2015,7 @@ public fun <T> Iterable<T>.single(): T {
|
||||
* Returns single element, or throws exception if there is no or more than one element
|
||||
*/
|
||||
public fun <T> List<T>.single(): T {
|
||||
return when (size) {
|
||||
return when (size()) {
|
||||
0 -> throw NoSuchElementException("Collection is empty")
|
||||
1 -> this[0]
|
||||
else -> throw IllegalArgumentException("Collection has more than one element")
|
||||
@@ -2042,7 +2027,7 @@ public fun <T> List<T>.single(): T {
|
||||
*/
|
||||
public fun <T> Stream<T>.single(): T {
|
||||
when (this) {
|
||||
is List<*> -> return when (size) {
|
||||
is List<*> -> return when (size()) {
|
||||
0 -> throw NoSuchElementException("Collection is empty")
|
||||
1 -> this[0] as T
|
||||
else -> throw IllegalArgumentException("Collection has more than one element")
|
||||
@@ -2063,7 +2048,7 @@ public fun <T> Stream<T>.single(): T {
|
||||
* Returns single element, or throws exception if there is no or more than one element
|
||||
*/
|
||||
public fun String.single(): Char {
|
||||
return when (size) {
|
||||
return when (length()) {
|
||||
0 -> throw NoSuchElementException("Collection is empty")
|
||||
1 -> this[0]
|
||||
else -> throw IllegalArgumentException("Collection has more than one element")
|
||||
@@ -2278,63 +2263,63 @@ public inline fun String.single(predicate: (Char) -> Boolean): Char {
|
||||
* Returns single element, or null if collection is empty, or throws exception if there is more than one element
|
||||
*/
|
||||
public fun <T> Array<out T>.singleOrNull(): T? {
|
||||
return if (size == 1) this[0] else null
|
||||
return if (size() == 1) this[0] else null
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns single element, or null if collection is empty, or throws exception if there is more than one element
|
||||
*/
|
||||
public fun BooleanArray.singleOrNull(): Boolean? {
|
||||
return if (size == 1) this[0] else null
|
||||
return if (size() == 1) this[0] else null
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns single element, or null if collection is empty, or throws exception if there is more than one element
|
||||
*/
|
||||
public fun ByteArray.singleOrNull(): Byte? {
|
||||
return if (size == 1) this[0] else null
|
||||
return if (size() == 1) this[0] else null
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns single element, or null if collection is empty, or throws exception if there is more than one element
|
||||
*/
|
||||
public fun CharArray.singleOrNull(): Char? {
|
||||
return if (size == 1) this[0] else null
|
||||
return if (size() == 1) this[0] else null
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns single element, or null if collection is empty, or throws exception if there is more than one element
|
||||
*/
|
||||
public fun DoubleArray.singleOrNull(): Double? {
|
||||
return if (size == 1) this[0] else null
|
||||
return if (size() == 1) this[0] else null
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns single element, or null if collection is empty, or throws exception if there is more than one element
|
||||
*/
|
||||
public fun FloatArray.singleOrNull(): Float? {
|
||||
return if (size == 1) this[0] else null
|
||||
return if (size() == 1) this[0] else null
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns single element, or null if collection is empty, or throws exception if there is more than one element
|
||||
*/
|
||||
public fun IntArray.singleOrNull(): Int? {
|
||||
return if (size == 1) this[0] else null
|
||||
return if (size() == 1) this[0] else null
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns single element, or null if collection is empty, or throws exception if there is more than one element
|
||||
*/
|
||||
public fun LongArray.singleOrNull(): Long? {
|
||||
return if (size == 1) this[0] else null
|
||||
return if (size() == 1) this[0] else null
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns single element, or null if collection is empty, or throws exception if there is more than one element
|
||||
*/
|
||||
public fun ShortArray.singleOrNull(): Short? {
|
||||
return if (size == 1) this[0] else null
|
||||
return if (size() == 1) this[0] else null
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2342,7 +2327,7 @@ public fun ShortArray.singleOrNull(): Short? {
|
||||
*/
|
||||
public fun <T> Iterable<T>.singleOrNull(): T? {
|
||||
when (this) {
|
||||
is List<*> -> return if (size == 1) this[0] as T else null
|
||||
is List<*> -> return if (size() == 1) this[0] as T else null
|
||||
else -> {
|
||||
val iterator = iterator()
|
||||
if (!iterator.hasNext())
|
||||
@@ -2359,7 +2344,7 @@ public fun <T> Iterable<T>.singleOrNull(): T? {
|
||||
* Returns single element, or null if collection is empty, or throws exception if there is more than one element
|
||||
*/
|
||||
public fun <T> List<T>.singleOrNull(): T? {
|
||||
return if (size == 1) this[0] else null
|
||||
return if (size() == 1) this[0] else null
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2367,7 +2352,7 @@ public fun <T> List<T>.singleOrNull(): T? {
|
||||
*/
|
||||
public fun <T> Stream<T>.singleOrNull(): T? {
|
||||
when (this) {
|
||||
is List<*> -> return if (size == 1) this[0] as T else null
|
||||
is List<*> -> return if (size() == 1) this[0] as T else null
|
||||
else -> {
|
||||
val iterator = iterator()
|
||||
if (!iterator.hasNext())
|
||||
@@ -2384,7 +2369,7 @@ public fun <T> Stream<T>.singleOrNull(): T? {
|
||||
* Returns single element, or null if collection is empty, or throws exception if there is more than one element
|
||||
*/
|
||||
public fun String.singleOrNull(): Char? {
|
||||
return if (size == 1) this[0] else null
|
||||
return if (length() == 1) this[0] else null
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -11,10 +11,10 @@ import java.util.*
|
||||
* Returns a list containing all elements except first *n* elements
|
||||
*/
|
||||
public fun <T> Array<out T>.drop(n: Int): List<T> {
|
||||
if (n >= size)
|
||||
if (n >= size())
|
||||
return ArrayList<T>()
|
||||
var count = 0
|
||||
val list = ArrayList<T>(size - n)
|
||||
val list = ArrayList<T>(size() - n)
|
||||
for (item in this) {
|
||||
if (count++ >= n) list.add(item)
|
||||
}
|
||||
@@ -25,10 +25,10 @@ public fun <T> Array<out T>.drop(n: Int): List<T> {
|
||||
* Returns a list containing all elements except first *n* elements
|
||||
*/
|
||||
public fun BooleanArray.drop(n: Int): List<Boolean> {
|
||||
if (n >= size)
|
||||
if (n >= size())
|
||||
return ArrayList<Boolean>()
|
||||
var count = 0
|
||||
val list = ArrayList<Boolean>(size - n)
|
||||
val list = ArrayList<Boolean>(size() - n)
|
||||
for (item in this) {
|
||||
if (count++ >= n) list.add(item)
|
||||
}
|
||||
@@ -39,10 +39,10 @@ public fun BooleanArray.drop(n: Int): List<Boolean> {
|
||||
* Returns a list containing all elements except first *n* elements
|
||||
*/
|
||||
public fun ByteArray.drop(n: Int): List<Byte> {
|
||||
if (n >= size)
|
||||
if (n >= size())
|
||||
return ArrayList<Byte>()
|
||||
var count = 0
|
||||
val list = ArrayList<Byte>(size - n)
|
||||
val list = ArrayList<Byte>(size() - n)
|
||||
for (item in this) {
|
||||
if (count++ >= n) list.add(item)
|
||||
}
|
||||
@@ -53,10 +53,10 @@ public fun ByteArray.drop(n: Int): List<Byte> {
|
||||
* Returns a list containing all elements except first *n* elements
|
||||
*/
|
||||
public fun CharArray.drop(n: Int): List<Char> {
|
||||
if (n >= size)
|
||||
if (n >= size())
|
||||
return ArrayList<Char>()
|
||||
var count = 0
|
||||
val list = ArrayList<Char>(size - n)
|
||||
val list = ArrayList<Char>(size() - n)
|
||||
for (item in this) {
|
||||
if (count++ >= n) list.add(item)
|
||||
}
|
||||
@@ -67,10 +67,10 @@ public fun CharArray.drop(n: Int): List<Char> {
|
||||
* Returns a list containing all elements except first *n* elements
|
||||
*/
|
||||
public fun DoubleArray.drop(n: Int): List<Double> {
|
||||
if (n >= size)
|
||||
if (n >= size())
|
||||
return ArrayList<Double>()
|
||||
var count = 0
|
||||
val list = ArrayList<Double>(size - n)
|
||||
val list = ArrayList<Double>(size() - n)
|
||||
for (item in this) {
|
||||
if (count++ >= n) list.add(item)
|
||||
}
|
||||
@@ -81,10 +81,10 @@ public fun DoubleArray.drop(n: Int): List<Double> {
|
||||
* Returns a list containing all elements except first *n* elements
|
||||
*/
|
||||
public fun FloatArray.drop(n: Int): List<Float> {
|
||||
if (n >= size)
|
||||
if (n >= size())
|
||||
return ArrayList<Float>()
|
||||
var count = 0
|
||||
val list = ArrayList<Float>(size - n)
|
||||
val list = ArrayList<Float>(size() - n)
|
||||
for (item in this) {
|
||||
if (count++ >= n) list.add(item)
|
||||
}
|
||||
@@ -95,10 +95,10 @@ public fun FloatArray.drop(n: Int): List<Float> {
|
||||
* Returns a list containing all elements except first *n* elements
|
||||
*/
|
||||
public fun IntArray.drop(n: Int): List<Int> {
|
||||
if (n >= size)
|
||||
if (n >= size())
|
||||
return ArrayList<Int>()
|
||||
var count = 0
|
||||
val list = ArrayList<Int>(size - n)
|
||||
val list = ArrayList<Int>(size() - n)
|
||||
for (item in this) {
|
||||
if (count++ >= n) list.add(item)
|
||||
}
|
||||
@@ -109,10 +109,10 @@ public fun IntArray.drop(n: Int): List<Int> {
|
||||
* Returns a list containing all elements except first *n* elements
|
||||
*/
|
||||
public fun LongArray.drop(n: Int): List<Long> {
|
||||
if (n >= size)
|
||||
if (n >= size())
|
||||
return ArrayList<Long>()
|
||||
var count = 0
|
||||
val list = ArrayList<Long>(size - n)
|
||||
val list = ArrayList<Long>(size() - n)
|
||||
for (item in this) {
|
||||
if (count++ >= n) list.add(item)
|
||||
}
|
||||
@@ -123,10 +123,10 @@ public fun LongArray.drop(n: Int): List<Long> {
|
||||
* Returns a list containing all elements except first *n* elements
|
||||
*/
|
||||
public fun ShortArray.drop(n: Int): List<Short> {
|
||||
if (n >= size)
|
||||
if (n >= size())
|
||||
return ArrayList<Short>()
|
||||
var count = 0
|
||||
val list = ArrayList<Short>(size - n)
|
||||
val list = ArrayList<Short>(size() - n)
|
||||
for (item in this) {
|
||||
if (count++ >= n) list.add(item)
|
||||
}
|
||||
@@ -137,10 +137,10 @@ public fun ShortArray.drop(n: Int): List<Short> {
|
||||
* Returns a list containing all elements except first *n* elements
|
||||
*/
|
||||
public fun <T> Collection<T>.drop(n: Int): List<T> {
|
||||
if (n >= size)
|
||||
if (n >= size())
|
||||
return ArrayList<T>()
|
||||
var count = 0
|
||||
val list = ArrayList<T>(size - n)
|
||||
val list = ArrayList<T>(size() - n)
|
||||
for (item in this) {
|
||||
if (count++ >= n) list.add(item)
|
||||
}
|
||||
@@ -170,7 +170,7 @@ public fun <T> Stream<T>.drop(n: Int): Stream<T> {
|
||||
* Returns a list containing all elements except first *n* elements
|
||||
*/
|
||||
public fun String.drop(n: Int): String {
|
||||
return substring(Math.min(n, size))
|
||||
return substring(Math.min(n, length()))
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -885,7 +885,7 @@ public fun String.slice(indices: Iterable<Int>): String {
|
||||
*/
|
||||
public fun <T> Array<out T>.take(n: Int): List<T> {
|
||||
var count = 0
|
||||
val realN = if (n > size) size else n
|
||||
val realN = if (n > size()) size() else n
|
||||
val list = ArrayList<T>(realN)
|
||||
for (item in this) {
|
||||
if (count++ == realN)
|
||||
@@ -900,7 +900,7 @@ public fun <T> Array<out T>.take(n: Int): List<T> {
|
||||
*/
|
||||
public fun BooleanArray.take(n: Int): List<Boolean> {
|
||||
var count = 0
|
||||
val realN = if (n > size) size else n
|
||||
val realN = if (n > size()) size() else n
|
||||
val list = ArrayList<Boolean>(realN)
|
||||
for (item in this) {
|
||||
if (count++ == realN)
|
||||
@@ -915,7 +915,7 @@ public fun BooleanArray.take(n: Int): List<Boolean> {
|
||||
*/
|
||||
public fun ByteArray.take(n: Int): List<Byte> {
|
||||
var count = 0
|
||||
val realN = if (n > size) size else n
|
||||
val realN = if (n > size()) size() else n
|
||||
val list = ArrayList<Byte>(realN)
|
||||
for (item in this) {
|
||||
if (count++ == realN)
|
||||
@@ -930,7 +930,7 @@ public fun ByteArray.take(n: Int): List<Byte> {
|
||||
*/
|
||||
public fun CharArray.take(n: Int): List<Char> {
|
||||
var count = 0
|
||||
val realN = if (n > size) size else n
|
||||
val realN = if (n > size()) size() else n
|
||||
val list = ArrayList<Char>(realN)
|
||||
for (item in this) {
|
||||
if (count++ == realN)
|
||||
@@ -945,7 +945,7 @@ public fun CharArray.take(n: Int): List<Char> {
|
||||
*/
|
||||
public fun DoubleArray.take(n: Int): List<Double> {
|
||||
var count = 0
|
||||
val realN = if (n > size) size else n
|
||||
val realN = if (n > size()) size() else n
|
||||
val list = ArrayList<Double>(realN)
|
||||
for (item in this) {
|
||||
if (count++ == realN)
|
||||
@@ -960,7 +960,7 @@ public fun DoubleArray.take(n: Int): List<Double> {
|
||||
*/
|
||||
public fun FloatArray.take(n: Int): List<Float> {
|
||||
var count = 0
|
||||
val realN = if (n > size) size else n
|
||||
val realN = if (n > size()) size() else n
|
||||
val list = ArrayList<Float>(realN)
|
||||
for (item in this) {
|
||||
if (count++ == realN)
|
||||
@@ -975,7 +975,7 @@ public fun FloatArray.take(n: Int): List<Float> {
|
||||
*/
|
||||
public fun IntArray.take(n: Int): List<Int> {
|
||||
var count = 0
|
||||
val realN = if (n > size) size else n
|
||||
val realN = if (n > size()) size() else n
|
||||
val list = ArrayList<Int>(realN)
|
||||
for (item in this) {
|
||||
if (count++ == realN)
|
||||
@@ -990,7 +990,7 @@ public fun IntArray.take(n: Int): List<Int> {
|
||||
*/
|
||||
public fun LongArray.take(n: Int): List<Long> {
|
||||
var count = 0
|
||||
val realN = if (n > size) size else n
|
||||
val realN = if (n > size()) size() else n
|
||||
val list = ArrayList<Long>(realN)
|
||||
for (item in this) {
|
||||
if (count++ == realN)
|
||||
@@ -1005,7 +1005,7 @@ public fun LongArray.take(n: Int): List<Long> {
|
||||
*/
|
||||
public fun ShortArray.take(n: Int): List<Short> {
|
||||
var count = 0
|
||||
val realN = if (n > size) size else n
|
||||
val realN = if (n > size()) size() else n
|
||||
val list = ArrayList<Short>(realN)
|
||||
for (item in this) {
|
||||
if (count++ == realN)
|
||||
@@ -1020,7 +1020,7 @@ public fun ShortArray.take(n: Int): List<Short> {
|
||||
*/
|
||||
public fun <T> Collection<T>.take(n: Int): List<T> {
|
||||
var count = 0
|
||||
val realN = if (n > size) size else n
|
||||
val realN = if (n > size()) size() else n
|
||||
val list = ArrayList<T>(realN)
|
||||
for (item in this) {
|
||||
if (count++ == realN)
|
||||
@@ -1055,7 +1055,7 @@ public fun <T> Stream<T>.take(n: Int): Stream<T> {
|
||||
* Returns a list containing first *n* elements
|
||||
*/
|
||||
public fun String.take(n: Int): String {
|
||||
return substring(0, Math.min(n, size))
|
||||
return substring(0, Math.min(n, length()))
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -261,7 +261,7 @@ public fun <T> Iterable<T>.subtract(other: Iterable<T>): Set<T> {
|
||||
* Returns a mutable set containing all distinct elements from the given collection.
|
||||
*/
|
||||
public fun <T> Array<out T>.toMutableSet(): MutableSet<T> {
|
||||
val set = LinkedHashSet<T>(size)
|
||||
val set = LinkedHashSet<T>(size())
|
||||
for (item in this) set.add(item)
|
||||
return set
|
||||
}
|
||||
@@ -270,7 +270,7 @@ public fun <T> Array<out T>.toMutableSet(): MutableSet<T> {
|
||||
* Returns a mutable set containing all distinct elements from the given collection.
|
||||
*/
|
||||
public fun BooleanArray.toMutableSet(): MutableSet<Boolean> {
|
||||
val set = LinkedHashSet<Boolean>(size)
|
||||
val set = LinkedHashSet<Boolean>(size())
|
||||
for (item in this) set.add(item)
|
||||
return set
|
||||
}
|
||||
@@ -279,7 +279,7 @@ public fun BooleanArray.toMutableSet(): MutableSet<Boolean> {
|
||||
* Returns a mutable set containing all distinct elements from the given collection.
|
||||
*/
|
||||
public fun ByteArray.toMutableSet(): MutableSet<Byte> {
|
||||
val set = LinkedHashSet<Byte>(size)
|
||||
val set = LinkedHashSet<Byte>(size())
|
||||
for (item in this) set.add(item)
|
||||
return set
|
||||
}
|
||||
@@ -288,7 +288,7 @@ public fun ByteArray.toMutableSet(): MutableSet<Byte> {
|
||||
* Returns a mutable set containing all distinct elements from the given collection.
|
||||
*/
|
||||
public fun CharArray.toMutableSet(): MutableSet<Char> {
|
||||
val set = LinkedHashSet<Char>(size)
|
||||
val set = LinkedHashSet<Char>(size())
|
||||
for (item in this) set.add(item)
|
||||
return set
|
||||
}
|
||||
@@ -297,7 +297,7 @@ public fun CharArray.toMutableSet(): MutableSet<Char> {
|
||||
* Returns a mutable set containing all distinct elements from the given collection.
|
||||
*/
|
||||
public fun DoubleArray.toMutableSet(): MutableSet<Double> {
|
||||
val set = LinkedHashSet<Double>(size)
|
||||
val set = LinkedHashSet<Double>(size())
|
||||
for (item in this) set.add(item)
|
||||
return set
|
||||
}
|
||||
@@ -306,7 +306,7 @@ public fun DoubleArray.toMutableSet(): MutableSet<Double> {
|
||||
* Returns a mutable set containing all distinct elements from the given collection.
|
||||
*/
|
||||
public fun FloatArray.toMutableSet(): MutableSet<Float> {
|
||||
val set = LinkedHashSet<Float>(size)
|
||||
val set = LinkedHashSet<Float>(size())
|
||||
for (item in this) set.add(item)
|
||||
return set
|
||||
}
|
||||
@@ -315,7 +315,7 @@ public fun FloatArray.toMutableSet(): MutableSet<Float> {
|
||||
* Returns a mutable set containing all distinct elements from the given collection.
|
||||
*/
|
||||
public fun IntArray.toMutableSet(): MutableSet<Int> {
|
||||
val set = LinkedHashSet<Int>(size)
|
||||
val set = LinkedHashSet<Int>(size())
|
||||
for (item in this) set.add(item)
|
||||
return set
|
||||
}
|
||||
@@ -324,7 +324,7 @@ public fun IntArray.toMutableSet(): MutableSet<Int> {
|
||||
* Returns a mutable set containing all distinct elements from the given collection.
|
||||
*/
|
||||
public fun LongArray.toMutableSet(): MutableSet<Long> {
|
||||
val set = LinkedHashSet<Long>(size)
|
||||
val set = LinkedHashSet<Long>(size())
|
||||
for (item in this) set.add(item)
|
||||
return set
|
||||
}
|
||||
@@ -333,7 +333,7 @@ public fun LongArray.toMutableSet(): MutableSet<Long> {
|
||||
* Returns a mutable set containing all distinct elements from the given collection.
|
||||
*/
|
||||
public fun ShortArray.toMutableSet(): MutableSet<Short> {
|
||||
val set = LinkedHashSet<Short>(size)
|
||||
val set = LinkedHashSet<Short>(size())
|
||||
for (item in this) set.add(item)
|
||||
return set
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.util.*
|
||||
* Returns an ArrayList of all elements
|
||||
*/
|
||||
public fun <T> Array<out T>.toArrayList(): ArrayList<T> {
|
||||
val list = ArrayList<T>(size)
|
||||
val list = ArrayList<T>(size())
|
||||
for (item in this) list.add(item)
|
||||
return list
|
||||
}
|
||||
@@ -20,7 +20,7 @@ public fun <T> Array<out T>.toArrayList(): ArrayList<T> {
|
||||
* Returns an ArrayList of all elements
|
||||
*/
|
||||
public fun BooleanArray.toArrayList(): ArrayList<Boolean> {
|
||||
val list = ArrayList<Boolean>(size)
|
||||
val list = ArrayList<Boolean>(size())
|
||||
for (item in this) list.add(item)
|
||||
return list
|
||||
}
|
||||
@@ -29,7 +29,7 @@ public fun BooleanArray.toArrayList(): ArrayList<Boolean> {
|
||||
* Returns an ArrayList of all elements
|
||||
*/
|
||||
public fun ByteArray.toArrayList(): ArrayList<Byte> {
|
||||
val list = ArrayList<Byte>(size)
|
||||
val list = ArrayList<Byte>(size())
|
||||
for (item in this) list.add(item)
|
||||
return list
|
||||
}
|
||||
@@ -38,7 +38,7 @@ public fun ByteArray.toArrayList(): ArrayList<Byte> {
|
||||
* Returns an ArrayList of all elements
|
||||
*/
|
||||
public fun CharArray.toArrayList(): ArrayList<Char> {
|
||||
val list = ArrayList<Char>(size)
|
||||
val list = ArrayList<Char>(size())
|
||||
for (item in this) list.add(item)
|
||||
return list
|
||||
}
|
||||
@@ -47,7 +47,7 @@ public fun CharArray.toArrayList(): ArrayList<Char> {
|
||||
* Returns an ArrayList of all elements
|
||||
*/
|
||||
public fun DoubleArray.toArrayList(): ArrayList<Double> {
|
||||
val list = ArrayList<Double>(size)
|
||||
val list = ArrayList<Double>(size())
|
||||
for (item in this) list.add(item)
|
||||
return list
|
||||
}
|
||||
@@ -56,7 +56,7 @@ public fun DoubleArray.toArrayList(): ArrayList<Double> {
|
||||
* Returns an ArrayList of all elements
|
||||
*/
|
||||
public fun FloatArray.toArrayList(): ArrayList<Float> {
|
||||
val list = ArrayList<Float>(size)
|
||||
val list = ArrayList<Float>(size())
|
||||
for (item in this) list.add(item)
|
||||
return list
|
||||
}
|
||||
@@ -65,7 +65,7 @@ public fun FloatArray.toArrayList(): ArrayList<Float> {
|
||||
* Returns an ArrayList of all elements
|
||||
*/
|
||||
public fun IntArray.toArrayList(): ArrayList<Int> {
|
||||
val list = ArrayList<Int>(size)
|
||||
val list = ArrayList<Int>(size())
|
||||
for (item in this) list.add(item)
|
||||
return list
|
||||
}
|
||||
@@ -74,7 +74,7 @@ public fun IntArray.toArrayList(): ArrayList<Int> {
|
||||
* Returns an ArrayList of all elements
|
||||
*/
|
||||
public fun LongArray.toArrayList(): ArrayList<Long> {
|
||||
val list = ArrayList<Long>(size)
|
||||
val list = ArrayList<Long>(size())
|
||||
for (item in this) list.add(item)
|
||||
return list
|
||||
}
|
||||
@@ -83,7 +83,7 @@ public fun LongArray.toArrayList(): ArrayList<Long> {
|
||||
* Returns an ArrayList of all elements
|
||||
*/
|
||||
public fun ShortArray.toArrayList(): ArrayList<Short> {
|
||||
val list = ArrayList<Short>(size)
|
||||
val list = ArrayList<Short>(size())
|
||||
for (item in this) list.add(item)
|
||||
return list
|
||||
}
|
||||
@@ -401,7 +401,7 @@ public fun String.toLinkedList(): LinkedList<Char> {
|
||||
* Returns a List containing all key-value pairs
|
||||
*/
|
||||
public fun <K, V> Map<K, V>.toList(): List<Pair<K, V>> {
|
||||
val result = ArrayList<Pair<K, V>>(size)
|
||||
val result = ArrayList<Pair<K, V>>(size())
|
||||
for (item in this)
|
||||
result.add(item.key to item.value)
|
||||
return result
|
||||
@@ -418,7 +418,7 @@ public fun <T> Array<out T>.toList(): List<T> {
|
||||
* Returns a List containing all elements
|
||||
*/
|
||||
public fun BooleanArray.toList(): List<Boolean> {
|
||||
val list = ArrayList<Boolean>(size)
|
||||
val list = ArrayList<Boolean>(size())
|
||||
for (item in this) list.add(item)
|
||||
return list
|
||||
}
|
||||
@@ -427,7 +427,7 @@ public fun BooleanArray.toList(): List<Boolean> {
|
||||
* Returns a List containing all elements
|
||||
*/
|
||||
public fun ByteArray.toList(): List<Byte> {
|
||||
val list = ArrayList<Byte>(size)
|
||||
val list = ArrayList<Byte>(size())
|
||||
for (item in this) list.add(item)
|
||||
return list
|
||||
}
|
||||
@@ -436,7 +436,7 @@ public fun ByteArray.toList(): List<Byte> {
|
||||
* Returns a List containing all elements
|
||||
*/
|
||||
public fun CharArray.toList(): List<Char> {
|
||||
val list = ArrayList<Char>(size)
|
||||
val list = ArrayList<Char>(size())
|
||||
for (item in this) list.add(item)
|
||||
return list
|
||||
}
|
||||
@@ -445,7 +445,7 @@ public fun CharArray.toList(): List<Char> {
|
||||
* Returns a List containing all elements
|
||||
*/
|
||||
public fun DoubleArray.toList(): List<Double> {
|
||||
val list = ArrayList<Double>(size)
|
||||
val list = ArrayList<Double>(size())
|
||||
for (item in this) list.add(item)
|
||||
return list
|
||||
}
|
||||
@@ -454,7 +454,7 @@ public fun DoubleArray.toList(): List<Double> {
|
||||
* Returns a List containing all elements
|
||||
*/
|
||||
public fun FloatArray.toList(): List<Float> {
|
||||
val list = ArrayList<Float>(size)
|
||||
val list = ArrayList<Float>(size())
|
||||
for (item in this) list.add(item)
|
||||
return list
|
||||
}
|
||||
@@ -463,7 +463,7 @@ public fun FloatArray.toList(): List<Float> {
|
||||
* Returns a List containing all elements
|
||||
*/
|
||||
public fun IntArray.toList(): List<Int> {
|
||||
val list = ArrayList<Int>(size)
|
||||
val list = ArrayList<Int>(size())
|
||||
for (item in this) list.add(item)
|
||||
return list
|
||||
}
|
||||
@@ -472,7 +472,7 @@ public fun IntArray.toList(): List<Int> {
|
||||
* Returns a List containing all elements
|
||||
*/
|
||||
public fun LongArray.toList(): List<Long> {
|
||||
val list = ArrayList<Long>(size)
|
||||
val list = ArrayList<Long>(size())
|
||||
for (item in this) list.add(item)
|
||||
return list
|
||||
}
|
||||
@@ -481,7 +481,7 @@ public fun LongArray.toList(): List<Long> {
|
||||
* Returns a List containing all elements
|
||||
*/
|
||||
public fun ShortArray.toList(): List<Short> {
|
||||
val list = ArrayList<Short>(size)
|
||||
val list = ArrayList<Short>(size())
|
||||
for (item in this) list.add(item)
|
||||
return list
|
||||
}
|
||||
|
||||
@@ -10,56 +10,56 @@ import java.util.*
|
||||
/**
|
||||
* Searches array or range of array for provided element index using binary search algorithm. Array is expected to be sorted.
|
||||
*/
|
||||
public fun <T> Array<out T>.binarySearch(element: T, fromIndex: Int = 0, toIndex: Int = size): Int {
|
||||
public fun <T> Array<out T>.binarySearch(element: T, fromIndex: Int = 0, toIndex: Int = size()): Int {
|
||||
return Arrays.binarySearch(this, fromIndex, toIndex, element)
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches array or range of array for provided element index using binary search algorithm. Array is expected to be sorted.
|
||||
*/
|
||||
public fun ByteArray.binarySearch(element: Byte, fromIndex: Int = 0, toIndex: Int = size): Int {
|
||||
public fun ByteArray.binarySearch(element: Byte, fromIndex: Int = 0, toIndex: Int = size()): Int {
|
||||
return Arrays.binarySearch(this, fromIndex, toIndex, element)
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches array or range of array for provided element index using binary search algorithm. Array is expected to be sorted.
|
||||
*/
|
||||
public fun CharArray.binarySearch(element: Char, fromIndex: Int = 0, toIndex: Int = size): Int {
|
||||
public fun CharArray.binarySearch(element: Char, fromIndex: Int = 0, toIndex: Int = size()): Int {
|
||||
return Arrays.binarySearch(this, fromIndex, toIndex, element)
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches array or range of array for provided element index using binary search algorithm. Array is expected to be sorted.
|
||||
*/
|
||||
public fun DoubleArray.binarySearch(element: Double, fromIndex: Int = 0, toIndex: Int = size): Int {
|
||||
public fun DoubleArray.binarySearch(element: Double, fromIndex: Int = 0, toIndex: Int = size()): Int {
|
||||
return Arrays.binarySearch(this, fromIndex, toIndex, element)
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches array or range of array for provided element index using binary search algorithm. Array is expected to be sorted.
|
||||
*/
|
||||
public fun FloatArray.binarySearch(element: Float, fromIndex: Int = 0, toIndex: Int = size): Int {
|
||||
public fun FloatArray.binarySearch(element: Float, fromIndex: Int = 0, toIndex: Int = size()): Int {
|
||||
return Arrays.binarySearch(this, fromIndex, toIndex, element)
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches array or range of array for provided element index using binary search algorithm. Array is expected to be sorted.
|
||||
*/
|
||||
public fun IntArray.binarySearch(element: Int, fromIndex: Int = 0, toIndex: Int = size): Int {
|
||||
public fun IntArray.binarySearch(element: Int, fromIndex: Int = 0, toIndex: Int = size()): Int {
|
||||
return Arrays.binarySearch(this, fromIndex, toIndex, element)
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches array or range of array for provided element index using binary search algorithm. Array is expected to be sorted.
|
||||
*/
|
||||
public fun LongArray.binarySearch(element: Long, fromIndex: Int = 0, toIndex: Int = size): Int {
|
||||
public fun LongArray.binarySearch(element: Long, fromIndex: Int = 0, toIndex: Int = size()): Int {
|
||||
return Arrays.binarySearch(this, fromIndex, toIndex, element)
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches array or range of array for provided element index using binary search algorithm. Array is expected to be sorted.
|
||||
*/
|
||||
public fun ShortArray.binarySearch(element: Short, fromIndex: Int = 0, toIndex: Int = size): Int {
|
||||
public fun ShortArray.binarySearch(element: Short, fromIndex: Int = 0, toIndex: Int = size()): Int {
|
||||
return Arrays.binarySearch(this, fromIndex, toIndex, element)
|
||||
}
|
||||
|
||||
@@ -67,63 +67,63 @@ public fun ShortArray.binarySearch(element: Short, fromIndex: Int = 0, toIndex:
|
||||
* Returns new array which is a copy of the original array
|
||||
*/
|
||||
public fun <T> Array<out T>.copyOf(): Array<T> {
|
||||
return Arrays.copyOf(this, size) as Array<T>
|
||||
return Arrays.copyOf(this, size()) as Array<T>
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns new array which is a copy of the original array
|
||||
*/
|
||||
public fun BooleanArray.copyOf(): BooleanArray {
|
||||
return Arrays.copyOf(this, size)
|
||||
return Arrays.copyOf(this, size())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns new array which is a copy of the original array
|
||||
*/
|
||||
public fun ByteArray.copyOf(): ByteArray {
|
||||
return Arrays.copyOf(this, size)
|
||||
return Arrays.copyOf(this, size())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns new array which is a copy of the original array
|
||||
*/
|
||||
public fun CharArray.copyOf(): CharArray {
|
||||
return Arrays.copyOf(this, size)
|
||||
return Arrays.copyOf(this, size())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns new array which is a copy of the original array
|
||||
*/
|
||||
public fun DoubleArray.copyOf(): DoubleArray {
|
||||
return Arrays.copyOf(this, size)
|
||||
return Arrays.copyOf(this, size())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns new array which is a copy of the original array
|
||||
*/
|
||||
public fun FloatArray.copyOf(): FloatArray {
|
||||
return Arrays.copyOf(this, size)
|
||||
return Arrays.copyOf(this, size())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns new array which is a copy of the original array
|
||||
*/
|
||||
public fun IntArray.copyOf(): IntArray {
|
||||
return Arrays.copyOf(this, size)
|
||||
return Arrays.copyOf(this, size())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns new array which is a copy of the original array
|
||||
*/
|
||||
public fun LongArray.copyOf(): LongArray {
|
||||
return Arrays.copyOf(this, size)
|
||||
return Arrays.copyOf(this, size())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns new array which is a copy of the original array
|
||||
*/
|
||||
public fun ShortArray.copyOf(): ShortArray {
|
||||
return Arrays.copyOf(this, size)
|
||||
return Arrays.copyOf(this, size())
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -417,56 +417,56 @@ public fun <T, C : MutableCollection<in R>, R : T> Stream<T>.filterIsInstanceTo(
|
||||
/**
|
||||
* Sorts array or range in array inplace
|
||||
*/
|
||||
public fun <T> Array<out T>.sort(fromIndex: Int = 0, toIndex: Int = size): Unit {
|
||||
public fun <T> Array<out T>.sort(fromIndex: Int = 0, toIndex: Int = size()): Unit {
|
||||
Arrays.sort(this, fromIndex, toIndex)
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts array or range in array inplace
|
||||
*/
|
||||
public fun ByteArray.sort(fromIndex: Int = 0, toIndex: Int = size): Unit {
|
||||
public fun ByteArray.sort(fromIndex: Int = 0, toIndex: Int = size()): Unit {
|
||||
Arrays.sort(this, fromIndex, toIndex)
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts array or range in array inplace
|
||||
*/
|
||||
public fun CharArray.sort(fromIndex: Int = 0, toIndex: Int = size): Unit {
|
||||
public fun CharArray.sort(fromIndex: Int = 0, toIndex: Int = size()): Unit {
|
||||
Arrays.sort(this, fromIndex, toIndex)
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts array or range in array inplace
|
||||
*/
|
||||
public fun DoubleArray.sort(fromIndex: Int = 0, toIndex: Int = size): Unit {
|
||||
public fun DoubleArray.sort(fromIndex: Int = 0, toIndex: Int = size()): Unit {
|
||||
Arrays.sort(this, fromIndex, toIndex)
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts array or range in array inplace
|
||||
*/
|
||||
public fun FloatArray.sort(fromIndex: Int = 0, toIndex: Int = size): Unit {
|
||||
public fun FloatArray.sort(fromIndex: Int = 0, toIndex: Int = size()): Unit {
|
||||
Arrays.sort(this, fromIndex, toIndex)
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts array or range in array inplace
|
||||
*/
|
||||
public fun IntArray.sort(fromIndex: Int = 0, toIndex: Int = size): Unit {
|
||||
public fun IntArray.sort(fromIndex: Int = 0, toIndex: Int = size()): Unit {
|
||||
Arrays.sort(this, fromIndex, toIndex)
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts array or range in array inplace
|
||||
*/
|
||||
public fun LongArray.sort(fromIndex: Int = 0, toIndex: Int = size): Unit {
|
||||
public fun LongArray.sort(fromIndex: Int = 0, toIndex: Int = size()): Unit {
|
||||
Arrays.sort(this, fromIndex, toIndex)
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts array or range in array inplace
|
||||
*/
|
||||
public fun ShortArray.sort(fromIndex: Int = 0, toIndex: Int = size): Unit {
|
||||
public fun ShortArray.sort(fromIndex: Int = 0, toIndex: Int = size()): Unit {
|
||||
Arrays.sort(this, fromIndex, toIndex)
|
||||
}
|
||||
|
||||
|
||||
@@ -79,3 +79,68 @@ public val BooleanArray.size: Int get() = size()
|
||||
|
||||
deprecated("Use compareValuesBy() instead")
|
||||
public fun <T : Any> compareBy(a: T?, b: T?, vararg functions: (T) -> Comparable<*>?): Int = compareValuesBy(a, b, *functions)
|
||||
|
||||
|
||||
/**
|
||||
* Returns the first item in the list or null if the list is empty
|
||||
*
|
||||
* @includeFunctionBody ../../test/collections/ListSpecificTest.kt first
|
||||
*/
|
||||
deprecated("Use firstOrNull() function instead")
|
||||
public val <T> List<T>.first: T?
|
||||
get() = this.firstOrNull()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the last item in the list or null if the list is empty
|
||||
*
|
||||
* @includeFunctionBody ../../test/collections/ListSpecificTest.kt last
|
||||
*/
|
||||
deprecated("Use lastOrNull() function instead")
|
||||
public val <T> List<T>.last: T?
|
||||
get() {
|
||||
val s = this.size()
|
||||
return if (s > 0) this[s - 1] else null
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the first item in the list or null if the list is empty
|
||||
*
|
||||
* @includeFunctionBody ../../test/collections/ListSpecificTest.kt head
|
||||
*/
|
||||
deprecated("Use firstOrNull() function instead")
|
||||
public val <T> List<T>.head: T?
|
||||
get() = firstOrNull()
|
||||
|
||||
/**
|
||||
* Returns all elements in this collection apart from the first one
|
||||
*
|
||||
* @includeFunctionBody ../../test/collections/ListSpecificTest.kt tail
|
||||
*/
|
||||
deprecated("Use drop(1) function call instead")
|
||||
public val <T> List<T>.tail: List<T>
|
||||
get() {
|
||||
return drop(1)
|
||||
}
|
||||
|
||||
/** Returns true if this collection is empty */
|
||||
deprecated("Use isEmpty() function call instead")
|
||||
public val Collection<*>.empty: Boolean
|
||||
get() = isEmpty()
|
||||
|
||||
/** Returns the size of the collection */
|
||||
deprecated("Use size() function call instead")
|
||||
public val Collection<*>.size: Int
|
||||
get() = size()
|
||||
|
||||
|
||||
/** Returns the size of the map */
|
||||
deprecated("Use size() function call instead")
|
||||
public val Map<*, *>.size: Int
|
||||
get() = size()
|
||||
|
||||
/** Returns true if this map is empty */
|
||||
deprecated("Use isEmpty() function call instead")
|
||||
public val Map<*, *>.empty: Boolean
|
||||
get() = isEmpty()
|
||||
|
||||
@@ -37,3 +37,8 @@ public /*inline*/ fun <T> callable(action: () -> T): Callable<T> {
|
||||
public override fun call() = action()
|
||||
}
|
||||
}
|
||||
|
||||
deprecated("Use length() instead")
|
||||
public val String.size: Int
|
||||
get() = length()
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ import java.util.Comparator
|
||||
* Compares two values using the sequence of functions to calculate a result of comparison.
|
||||
*/
|
||||
public fun <T : Any> compareValuesBy(a: T?, b: T?, vararg functions: (T) -> Comparable<*>?): Int {
|
||||
require(functions.size > 0)
|
||||
require(functions.size() > 0)
|
||||
if (a identityEquals b) return 0
|
||||
if (a == null) return -1
|
||||
if (b == null) return 1
|
||||
|
||||
@@ -11,56 +11,56 @@ public inline fun <reified T> Array(size: Int, init: (Int) -> T): Array<T> {
|
||||
}
|
||||
|
||||
public val BooleanArray.lastIndex: Int
|
||||
get() = this.size - 1
|
||||
get() = size() - 1
|
||||
|
||||
public val ByteArray.lastIndex: Int
|
||||
get() = this.size - 1
|
||||
get() = size() - 1
|
||||
|
||||
public val ShortArray.lastIndex: Int
|
||||
get() = this.size - 1
|
||||
get() = size() - 1
|
||||
|
||||
public val IntArray.lastIndex: Int
|
||||
get() = this.size - 1
|
||||
get() = size() - 1
|
||||
|
||||
public val LongArray.lastIndex: Int
|
||||
get() = this.size - 1
|
||||
get() = size() - 1
|
||||
|
||||
public val FloatArray.lastIndex: Int
|
||||
get() = this.size - 1
|
||||
get() = size() - 1
|
||||
|
||||
public val DoubleArray.lastIndex: Int
|
||||
get() = this.size - 1
|
||||
get() = size() - 1
|
||||
|
||||
public val CharArray.lastIndex: Int
|
||||
get() = this.size - 1
|
||||
get() = size() - 1
|
||||
|
||||
public val Array<*>.lastIndex: Int
|
||||
get() = this.size - 1
|
||||
get() = size() - 1
|
||||
|
||||
|
||||
public val BooleanArray.indices: IntRange
|
||||
get() = IntRange(0, this.size - 1)
|
||||
get() = IntRange(0, lastIndex)
|
||||
|
||||
public val ByteArray.indices: IntRange
|
||||
get() = IntRange(0, this.size - 1)
|
||||
get() = IntRange(0, lastIndex)
|
||||
|
||||
public val ShortArray.indices: IntRange
|
||||
get() = IntRange(0, this.size - 1)
|
||||
get() = IntRange(0, lastIndex)
|
||||
|
||||
public val IntArray.indices: IntRange
|
||||
get() = IntRange(0, this.size - 1)
|
||||
get() = IntRange(0, lastIndex)
|
||||
|
||||
public val LongArray.indices: IntRange
|
||||
get() = IntRange(0, this.size - 1)
|
||||
get() = IntRange(0, lastIndex)
|
||||
|
||||
public val FloatArray.indices: IntRange
|
||||
get() = IntRange(0, this.size - 1)
|
||||
get() = IntRange(0, lastIndex)
|
||||
|
||||
public val DoubleArray.indices: IntRange
|
||||
get() = IntRange(0, this.size - 1)
|
||||
get() = IntRange(0, lastIndex)
|
||||
|
||||
public val CharArray.indices: IntRange
|
||||
get() = IntRange(0, this.size - 1)
|
||||
get() = IntRange(0, lastIndex)
|
||||
|
||||
public val Array<*>.indices: IntRange
|
||||
get() = IntRange(0, this.size - 1)
|
||||
get() = IntRange(0, lastIndex)
|
||||
|
||||
@@ -17,8 +17,8 @@ private class ImmutableArrayList<T>(
|
||||
throw IllegalArgumentException("Negative length ($length)")
|
||||
}
|
||||
// possible when builder is used from different threads
|
||||
if (offset + length > array.size) {
|
||||
throw IllegalArgumentException("offset ($offset) + length ($length) > array.length (${array.size})")
|
||||
if (offset + length > array.size()) {
|
||||
throw IllegalArgumentException("offset ($offset) + length ($length) > array.length (${array.size()})")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,8 +79,8 @@ public class ImmutableArrayListBuilder<T>() {
|
||||
}
|
||||
|
||||
public fun ensureCapacity(capacity: Int) {
|
||||
if (array.size < capacity) {
|
||||
val newSize = Math.max(capacity, Math.max(array.size * 2, 11))
|
||||
if (array.size() < capacity) {
|
||||
val newSize = Math.max(capacity, Math.max(array.size() * 2, 11))
|
||||
array = array.copyOf(newSize)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,13 +11,13 @@ private val stdlib_emptyMap : Map<Any, Any> = stdlib_emptyMapClass()
|
||||
private fun stdlib_emptyMap<K,V>() = stdlib_emptyMap as Map<K,V>
|
||||
|
||||
/** Returns a new read-only list of given elements */
|
||||
public fun listOf<T>(vararg values: T): List<T> = if (values.size == 0) stdlib_emptyList() else arrayListOf(*values)
|
||||
public fun listOf<T>(vararg values: T): List<T> = if (values.size() == 0) stdlib_emptyList() else arrayListOf(*values)
|
||||
|
||||
/** Returns an empty list */
|
||||
public fun listOf<T>(): List<T> = stdlib_emptyList()
|
||||
|
||||
/** Returns a new read-only map of given pairs, where the first value is the key, and the second is value */
|
||||
public fun mapOf<K, V>(vararg values: Pair<K, V>): Map<K, V> = if (values.size == 0) stdlib_emptyMap() else linkedMapOf(*values)
|
||||
public fun mapOf<K, V>(vararg values: Pair<K, V>): Map<K, V> = if (values.size() == 0) stdlib_emptyMap() else linkedMapOf(*values)
|
||||
|
||||
/** Returns an empty read-only map */
|
||||
public fun mapOf<K, V>(): Map<K, V> = stdlib_emptyMap()
|
||||
@@ -29,10 +29,10 @@ public fun setOf<T>(vararg values: T): Set<T> = values.toCollection(LinkedHashSe
|
||||
public fun linkedListOf<T>(vararg values: T): LinkedList<T> = values.toCollection(LinkedList<T>())
|
||||
|
||||
/** Returns a new ArrayList with a variable number of initial elements */
|
||||
public fun arrayListOf<T>(vararg values: T): ArrayList<T> = values.toCollection(ArrayList(values.size))
|
||||
public fun arrayListOf<T>(vararg values: T): ArrayList<T> = values.toCollection(ArrayList(values.size()))
|
||||
|
||||
/** Returns a new HashSet with a variable number of initial elements */
|
||||
public fun hashSetOf<T>(vararg values: T): HashSet<T> = values.toCollection(HashSet(values.size))
|
||||
public fun hashSetOf<T>(vararg values: T): HashSet<T> = values.toCollection(HashSet(values.size()))
|
||||
|
||||
/**
|
||||
* Returns a new [[HashMap]] populated with the given pairs where the first value in each pair
|
||||
@@ -41,7 +41,7 @@ public fun hashSetOf<T>(vararg values: T): HashSet<T> = values.toCollection(Hash
|
||||
* @includeFunctionBody ../../test/collections/MapTest.kt createUsingPairs
|
||||
*/
|
||||
public fun <K, V> hashMapOf(vararg values: Pair<K, V>): HashMap<K, V> {
|
||||
val answer = HashMap<K, V>(values.size)
|
||||
val answer = HashMap<K, V>(values.size())
|
||||
answer.putAll(*values)
|
||||
return answer
|
||||
}
|
||||
@@ -54,25 +54,26 @@ public fun <K, V> hashMapOf(vararg values: Pair<K, V>): HashMap<K, V> {
|
||||
* @includeFunctionBody ../../test/collections/MapTest.kt createLinkedMap
|
||||
*/
|
||||
public fun <K, V> linkedMapOf(vararg values: Pair<K, V>): LinkedHashMap<K, V> {
|
||||
val answer = LinkedHashMap<K, V>(values.size)
|
||||
val answer = LinkedHashMap<K, V>(values.size())
|
||||
answer.putAll(*values)
|
||||
return answer
|
||||
}
|
||||
|
||||
/** Returns the size of the collection */
|
||||
public val Collection<*>.size: Int
|
||||
get() = size()
|
||||
|
||||
/** Returns true if this collection is empty */
|
||||
public val Collection<*>.empty: Boolean
|
||||
get() = isEmpty()
|
||||
|
||||
public val Collection<*>.indices: IntRange
|
||||
get() = 0..size - 1
|
||||
get() = 0..size() - 1
|
||||
|
||||
public val Int.indices: IntRange
|
||||
get() = 0..this - 1
|
||||
|
||||
/**
|
||||
* Returns the index of the last item in the list or -1 if the list is empty
|
||||
*
|
||||
* @includeFunctionBody ../../test/collections/ListSpecificTest.kt lastIndex
|
||||
*/
|
||||
public val <T> List<T>.lastIndex: Int
|
||||
get() = this.size() - 1
|
||||
|
||||
|
||||
/** Returns true if the collection is not empty */
|
||||
public fun <T> Collection<T>.isNotEmpty(): Boolean = !this.isEmpty()
|
||||
|
||||
@@ -87,49 +88,3 @@ public fun <T> Collection<T>?.orEmpty(): Collection<T> = this ?: stdlib_emptyLis
|
||||
|
||||
/** Returns the List if its not null otherwise returns the empty list */
|
||||
public fun <T> List<T>?.orEmpty(): List<T> = this ?: stdlib_emptyList()
|
||||
|
||||
/**
|
||||
* Returns the first item in the list or null if the list is empty
|
||||
*
|
||||
* @includeFunctionBody ../../test/collections/ListSpecificTest.kt first
|
||||
*/
|
||||
public val <T> List<T>.first: T?
|
||||
get() = this.head
|
||||
|
||||
|
||||
/**
|
||||
* Returns the last item in the list or null if the list is empty
|
||||
*
|
||||
* @includeFunctionBody ../../test/collections/ListSpecificTest.kt last
|
||||
*/
|
||||
public val <T> List<T>.last: T?
|
||||
get() {
|
||||
val s = this.size
|
||||
return if (s > 0) this[s - 1] else null
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index of the last item in the list or -1 if the list is empty
|
||||
*
|
||||
* @includeFunctionBody ../../test/collections/ListSpecificTest.kt lastIndex
|
||||
*/
|
||||
public val <T> List<T>.lastIndex: Int
|
||||
get() = this.size - 1
|
||||
|
||||
/**
|
||||
* Returns the first item in the list or null if the list is empty
|
||||
*
|
||||
* @includeFunctionBody ../../test/collections/ListSpecificTest.kt head
|
||||
*/
|
||||
public val <T> List<T>.head: T?
|
||||
get() = if (this.isNotEmpty()) this[0] else null
|
||||
|
||||
/**
|
||||
* Returns all elements in this collection apart from the first one
|
||||
*
|
||||
* @includeFunctionBody ../../test/collections/ListSpecificTest.kt tail
|
||||
*/
|
||||
public val <T> List<T>.tail: List<T>
|
||||
get() {
|
||||
return this.drop(1)
|
||||
}
|
||||
|
||||
@@ -4,14 +4,6 @@ import java.util.*
|
||||
|
||||
// Map APIs
|
||||
|
||||
/** Returns the size of the map */
|
||||
public val Map<*, *>.size: Int
|
||||
get() = size()
|
||||
|
||||
/** Returns true if this map is empty */
|
||||
public val Map<*, *>.empty: Boolean
|
||||
get() = isEmpty()
|
||||
|
||||
/** Returns the [[Map]] if its not null otherwise it returns the empty [[Map]] */
|
||||
public fun <K,V> Map<K,V>?.orEmpty() : Map<K,V>
|
||||
= if (this != null) this else stdlib_emptyMap()
|
||||
|
||||
@@ -123,7 +123,7 @@ public var Element.classSet: MutableSet<String>
|
||||
val answer = LinkedHashSet<String>()
|
||||
val array = this.classes.split("""\s""")
|
||||
for (s in array) {
|
||||
if (s.size > 0) {
|
||||
if (s.length() > 0) {
|
||||
answer.add(s)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,8 +59,8 @@ public fun File.relativePath(descendant: File): String {
|
||||
val prefix = directory.canonicalPath
|
||||
val answer = descendant.canonicalPath
|
||||
return if (answer.startsWith(prefix)) {
|
||||
val prefixSize = prefix.size
|
||||
if (answer.size > prefixSize) {
|
||||
val prefixSize = prefix.length()
|
||||
if (answer.length() > prefixSize) {
|
||||
answer.substring(prefixSize + 1)
|
||||
} else ""
|
||||
} else {
|
||||
|
||||
@@ -69,6 +69,12 @@ public val CharSequence.length: Int
|
||||
|
||||
public fun CharSequence.get(index: Int): Char = this.charAt(index)
|
||||
|
||||
/**
|
||||
* Returns the index of the last character in the String or -1 if the String is empty
|
||||
*/
|
||||
public val String.lastIndex: Int
|
||||
get() = this.length() - 1
|
||||
|
||||
/**
|
||||
* Returns a subsequence specified by given set of indices.
|
||||
*/
|
||||
|
||||
@@ -122,9 +122,6 @@ public fun String.toUpperCase(locale: java.util.Locale): String = (this as java.
|
||||
public val CharSequence.size: Int
|
||||
get() = this.length
|
||||
|
||||
public val String.size: Int
|
||||
get() = length()
|
||||
|
||||
public fun String.toBoolean(): Boolean = java.lang.Boolean.parseBoolean(this)
|
||||
public fun String.toShort(): Short = java.lang.Short.parseShort(this)
|
||||
public fun String.toInt(): Int = java.lang.Integer.parseInt(this)
|
||||
|
||||
@@ -40,6 +40,6 @@ class ExceptionTest {
|
||||
}
|
||||
|
||||
val bytes = assertNotNull(byteBuffer.toByteArray())
|
||||
assertTrue(bytes.size > 10)
|
||||
assertTrue(bytes.size() > 10)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,13 +10,13 @@ import org.junit.Test as test
|
||||
class OldStdlibTest() {
|
||||
test fun testCollectionEmpty() {
|
||||
assertNot {
|
||||
listOf(0, 1, 2).empty
|
||||
listOf(0, 1, 2).isEmpty()
|
||||
}
|
||||
}
|
||||
|
||||
test fun testCollectionSize() {
|
||||
assertTrue {
|
||||
listOf(0, 1, 2).size == 3
|
||||
listOf(0, 1, 2).size() == 3
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,8 +40,8 @@ class PairTest {
|
||||
}
|
||||
|
||||
test fun pairHashSet() {
|
||||
val s = hashSet(Pair(1, "a"), Pair(1, "b"), Pair(1, "a"))
|
||||
assertEquals(2, s.size)
|
||||
val s = hashSetOf(Pair(1, "a"), Pair(1, "b"), Pair(1, "a"))
|
||||
assertEquals(2, s.size())
|
||||
assertTrue(s.contains(p))
|
||||
}
|
||||
}
|
||||
@@ -85,8 +85,8 @@ class TripleTest {
|
||||
}
|
||||
|
||||
test fun tripleHashSet() {
|
||||
val s = hashSet(Triple(1, "a", 0.07), Triple(1, "b", 0.07), Triple(1, "a", 0.07))
|
||||
assertEquals(2, s.size)
|
||||
val s = hashSetOf(Triple(1, "a", 0.07), Triple(1, "b", 0.07), Triple(1, "a", 0.07))
|
||||
assertEquals(2, s.size())
|
||||
assertTrue(s.contains(t))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,13 +201,13 @@ class ArraysJVMTest {
|
||||
test fun orEmptyNull() {
|
||||
val x: Array<String>? = null
|
||||
val xArray: Array<String> = x.orEmpty()
|
||||
expect(0) { xArray.size }
|
||||
expect(0) { xArray.size() }
|
||||
}
|
||||
|
||||
test fun orEmptyNotNull() {
|
||||
val x: Array<String>? = array("1", "2")
|
||||
val xArray: Array<String> = x.orEmpty()
|
||||
expect(2) { xArray.size }
|
||||
expect(2) { xArray.size() }
|
||||
expect("1") { xArray[0] }
|
||||
expect("2") { xArray[1] }
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ class ArraysTest {
|
||||
val arr = ByteArray(2)
|
||||
|
||||
val expected: Byte = 0
|
||||
assertEquals(arr.size, 2)
|
||||
assertEquals(arr.size(), 2)
|
||||
assertEquals(expected, arr[0])
|
||||
assertEquals(expected, arr[1])
|
||||
}
|
||||
@@ -46,7 +46,7 @@ class ArraysTest {
|
||||
val arr = ShortArray(2)
|
||||
|
||||
val expected: Short = 0
|
||||
assertEquals(arr.size, 2)
|
||||
assertEquals(arr.size(), 2)
|
||||
assertEquals(expected, arr[0])
|
||||
assertEquals(expected, arr[1])
|
||||
}
|
||||
@@ -54,7 +54,7 @@ class ArraysTest {
|
||||
test fun intArray() {
|
||||
val arr = IntArray(2)
|
||||
|
||||
assertEquals(arr.size, 2)
|
||||
assertEquals(arr.size(), 2)
|
||||
assertEquals(0, arr[0])
|
||||
assertEquals(0, arr[1])
|
||||
}
|
||||
@@ -63,7 +63,7 @@ class ArraysTest {
|
||||
val arr = LongArray(2)
|
||||
|
||||
val expected: Long = 0
|
||||
assertEquals(arr.size, 2)
|
||||
assertEquals(arr.size(), 2)
|
||||
assertEquals(expected, arr[0])
|
||||
assertEquals(expected, arr[1])
|
||||
}
|
||||
@@ -72,7 +72,7 @@ class ArraysTest {
|
||||
val arr = FloatArray(2)
|
||||
|
||||
val expected: Float = 0.0.toFloat()
|
||||
assertEquals(arr.size, 2)
|
||||
assertEquals(arr.size(), 2)
|
||||
assertEquals(expected, arr[0])
|
||||
assertEquals(expected, arr[1])
|
||||
}
|
||||
@@ -80,7 +80,7 @@ class ArraysTest {
|
||||
test fun doubleArray() {
|
||||
val arr = DoubleArray(2)
|
||||
|
||||
assertEquals(arr.size, 2)
|
||||
assertEquals(arr.size(), 2)
|
||||
assertEquals(0.0, arr[0])
|
||||
assertEquals(0.0, arr[1])
|
||||
}
|
||||
@@ -89,14 +89,14 @@ class ArraysTest {
|
||||
val arr = CharArray(2)
|
||||
|
||||
val expected: Char = '\u0000'
|
||||
assertEquals(arr.size, 2)
|
||||
assertEquals(arr.size(), 2)
|
||||
assertEquals(expected, arr[0])
|
||||
assertEquals(expected, arr[1])
|
||||
}
|
||||
|
||||
test fun booleanArray() {
|
||||
val arr = BooleanArray(2)
|
||||
assertEquals(arr.size, 2)
|
||||
assertEquals(arr.size(), 2)
|
||||
assertEquals(false, arr[0])
|
||||
assertEquals(false, arr[1])
|
||||
}
|
||||
|
||||
@@ -18,14 +18,14 @@ class CollectionJVMTest {
|
||||
}
|
||||
|
||||
|
||||
test fun filterIntolinkedListOf() {
|
||||
test fun filterIntoLinkedList() {
|
||||
val data = arrayListOf("foo", "bar")
|
||||
val foo = data.filterTo(linkedListOf<String>()) { it.startsWith("f") }
|
||||
|
||||
assertTrue {
|
||||
foo.all { it.startsWith("f") }
|
||||
}
|
||||
assertEquals(1, foo.size)
|
||||
assertEquals(1, foo.size())
|
||||
assertEquals(linkedListOf("foo"), foo)
|
||||
|
||||
assertTrue {
|
||||
@@ -40,7 +40,7 @@ class CollectionJVMTest {
|
||||
assertTrue {
|
||||
foo.all { !it.startsWith("f") }
|
||||
}
|
||||
assertEquals(1, foo.size)
|
||||
assertEquals(1, foo.size())
|
||||
assertEquals(linkedListOf("bar"), foo)
|
||||
|
||||
assertTrue {
|
||||
@@ -52,7 +52,7 @@ class CollectionJVMTest {
|
||||
val data = arrayListOf(null, "foo", null, "bar")
|
||||
val foo = data.filterNotNullTo(linkedListOf<String>())
|
||||
|
||||
assertEquals(2, foo.size)
|
||||
assertEquals(2, foo.size())
|
||||
assertEquals(linkedListOf("foo", "bar"), foo)
|
||||
|
||||
assertTrue {
|
||||
@@ -63,7 +63,7 @@ class CollectionJVMTest {
|
||||
test fun filterIntoSortedSet() {
|
||||
val data = arrayListOf("foo", "bar")
|
||||
val sorted = data.filterTo(sortedSetOf<String>()) { it.length == 3 }
|
||||
assertEquals(2, sorted.size)
|
||||
assertEquals(2, sorted.size())
|
||||
assertEquals(sortedSetOf("bar", "foo"), sorted)
|
||||
assertTrue {
|
||||
sorted is TreeSet<String>
|
||||
@@ -93,7 +93,7 @@ class CollectionJVMTest {
|
||||
val data = arrayListOf("foo", "bar")
|
||||
val arr = data.toArray()
|
||||
println("Got array ${arr}")
|
||||
assertEquals(2, arr.size)
|
||||
assertEquals(2, arr.size())
|
||||
todo {
|
||||
assertTrue {
|
||||
arr is Array<String>
|
||||
|
||||
@@ -27,7 +27,7 @@ class CollectionTest {
|
||||
val data = arrayListOf(null, "foo", null, "bar")
|
||||
val foo = data.filterNotNull()
|
||||
|
||||
assertEquals(2, foo.size)
|
||||
assertEquals(2, foo.size())
|
||||
assertEquals(arrayListOf("foo", "bar"), foo)
|
||||
|
||||
assertTrue {
|
||||
@@ -38,7 +38,7 @@ class CollectionTest {
|
||||
test fun mapNotNull() {
|
||||
val data = arrayListOf(null, "foo", null, "bar")
|
||||
val foo = data.mapNotNull { it.length }
|
||||
assertEquals(2, foo.size)
|
||||
assertEquals(2, foo.size())
|
||||
assertEquals(arrayListOf(3, 3), foo)
|
||||
|
||||
assertTrue {
|
||||
@@ -53,7 +53,7 @@ class CollectionTest {
|
||||
assertTrue {
|
||||
foo.all { it.startsWith("f") }
|
||||
}
|
||||
assertEquals(1, foo.size)
|
||||
assertEquals(1, foo.size())
|
||||
assertEquals(hashSetOf("foo"), foo)
|
||||
|
||||
assertTrue {
|
||||
@@ -83,7 +83,7 @@ class CollectionTest {
|
||||
test fun foldWithDifferentTypes() {
|
||||
expect(7) {
|
||||
val numbers = arrayListOf("a", "ab", "abc")
|
||||
numbers.fold(1) { a, b -> a + b.size }
|
||||
numbers.fold(1) { a, b -> a + b.length() }
|
||||
}
|
||||
|
||||
expect("1234") {
|
||||
@@ -136,7 +136,7 @@ class CollectionTest {
|
||||
|
||||
test fun partition() {
|
||||
val data = arrayListOf("foo", "bar", "something", "xyz")
|
||||
val pair = data.partition { it.size == 3 }
|
||||
val pair = data.partition { it.length() == 3 }
|
||||
|
||||
assertEquals(arrayListOf("foo", "bar", "xyz"), pair.first, "pair.first")
|
||||
assertEquals(arrayListOf("something"), pair.second, "pair.second")
|
||||
@@ -181,7 +181,7 @@ class CollectionTest {
|
||||
assertEquals(4, listOfPairs[3].first)
|
||||
|
||||
val l3 = byLength.getOrElse(3, { ArrayList<String>() })
|
||||
assertEquals(2, l3.size)
|
||||
assertEquals(2, l3.size())
|
||||
}
|
||||
|
||||
test fun plusRanges() {
|
||||
@@ -281,14 +281,14 @@ class CollectionTest {
|
||||
test fun takeWhile() {
|
||||
val coll = arrayListOf("foo", "bar", "abc")
|
||||
assertEquals(arrayListOf("foo"), coll.takeWhile { it.startsWith("f") })
|
||||
assertEquals(arrayListOf("foo", "bar", "abc"), coll.takeWhile { it.size == 3 })
|
||||
assertEquals(arrayListOf("foo", "bar", "abc"), coll.takeWhile { it.length() == 3 })
|
||||
}
|
||||
|
||||
test fun copyToArray() {
|
||||
val data = arrayListOf("foo", "bar")
|
||||
val arr = data.copyToArray()
|
||||
println("Got array ${arr}")
|
||||
assertEquals(2, arr.size)
|
||||
assertEquals(2, arr.size())
|
||||
todo {
|
||||
assertTrue {
|
||||
arr is Array<String>
|
||||
@@ -347,7 +347,7 @@ class CollectionTest {
|
||||
val indices = data.indices
|
||||
assertEquals(0, indices.start)
|
||||
assertEquals(1, indices.end)
|
||||
assertEquals(indices, data.size.indices)
|
||||
assertEquals(indices, data.size().indices)
|
||||
}
|
||||
|
||||
test fun contains() {
|
||||
|
||||
@@ -19,7 +19,7 @@ class ImmutableArrayListTest() : TestCase() {
|
||||
fun testGet() {
|
||||
for (length in 0 .. 55) {
|
||||
val list = buildIntArray(length, 19)
|
||||
assertEquals(length, list.size)
|
||||
assertEquals(length, list.size())
|
||||
checkList(list, length, 19)
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,7 @@ class ImmutableArrayListTest() : TestCase() {
|
||||
|
||||
|
||||
private fun checkList(list: List<Int>, expectedLength: Int, expectedFirstValue: Int) {
|
||||
assertEquals(expectedLength, list.size)
|
||||
assertEquals(expectedLength, list.size())
|
||||
for (i in 0 .. expectedLength - 1) {
|
||||
assertEquals(expectedFirstValue + i, list[i])
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ abstract class IterableTests<T : Iterable<String>>(val data: T, val empty: T) {
|
||||
val foo = data.filter { it.startsWith("f") }
|
||||
expect(true) { foo is List<String> }
|
||||
expect(true) { foo.all { it.startsWith("f") } }
|
||||
expect(1) { foo.size }
|
||||
expect(1) { foo.size() }
|
||||
assertEquals(listOf("foo"), foo)
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ abstract class IterableTests<T : Iterable<String>>(val data: T, val empty: T) {
|
||||
val notFoo = data.filterNot { it.startsWith("f") }
|
||||
expect(true) { notFoo is List<String> }
|
||||
expect(true) { notFoo.none { it.startsWith("f") } }
|
||||
expect(1) { notFoo.size }
|
||||
expect(1) { notFoo.size() }
|
||||
assertEquals(listOf("bar"), notFoo)
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ abstract class IterableTests<T : Iterable<String>>(val data: T, val empty: T) {
|
||||
assertTrue {
|
||||
lengths.all { it == 3 }
|
||||
}
|
||||
assertEquals(2, lengths.size)
|
||||
assertEquals(2, lengths.size())
|
||||
assertEquals(arrayListOf(3, 3), lengths)
|
||||
}
|
||||
|
||||
@@ -220,7 +220,7 @@ abstract class IterableTests<T : Iterable<String>>(val data: T, val empty: T) {
|
||||
Test
|
||||
fun reduce() {
|
||||
val reduced = data.reduce {a, b -> a + b }
|
||||
assertEquals(6, reduced.size)
|
||||
assertEquals(6, reduced.length())
|
||||
assertTrue(reduced == "foobar" || reduced == "barfoo")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ class ListSpecificTest {
|
||||
|
||||
Test fun tail() {
|
||||
val data = arrayListOf("foo", "bar", "whatnot")
|
||||
val actual = data.tail
|
||||
val actual = data.drop(1)
|
||||
val expected = arrayListOf("bar", "whatnot")
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
@@ -30,14 +30,7 @@ class ListSpecificTest {
|
||||
}
|
||||
|
||||
Test fun utils() {
|
||||
assertNull(empty.head)
|
||||
assertNull(empty.first)
|
||||
assertNull(empty.last)
|
||||
assertEquals(-1, empty.lastIndex)
|
||||
|
||||
assertEquals("foo", data.head)
|
||||
assertEquals("foo", data.first)
|
||||
assertEquals("bar", data.last)
|
||||
assertEquals(1, data.lastIndex)
|
||||
}
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ class DomBuilderTest() {
|
||||
}
|
||||
|
||||
}
|
||||
val grandChild = doc["grandChild"].first
|
||||
val grandChild = doc["grandChild"].firstOrNull()
|
||||
if (grandChild != null) {
|
||||
assertEquals("Hello World!", grandChild.text)
|
||||
assertEquals(" bar tiny", grandChild.attribute("class"))
|
||||
@@ -96,7 +96,7 @@ class DomBuilderTest() {
|
||||
|
||||
assertTrue(classSet.contains("bar"))
|
||||
assertTrue(classSet.contains("tiny"))
|
||||
assertTrue(classSet.size == 2 )
|
||||
assertTrue(classSet.size() == 2 )
|
||||
assertFalse(classSet.contains("doesNotExist"))
|
||||
|
||||
// lets add a new class and some existing classes
|
||||
@@ -114,12 +114,12 @@ class DomBuilderTest() {
|
||||
} else {
|
||||
fail("Not an Element $grandChild")
|
||||
}
|
||||
val child = doc["child"].first
|
||||
val child = doc["child"].firstOrNull()
|
||||
if (child != null) {
|
||||
val gc1 = child.childElements("grandChild")
|
||||
assertEquals(1, gc1.size, "Expected a single child but found $gc1")
|
||||
assertEquals(1, gc1.size(), "Expected a single child but found $gc1")
|
||||
val gc2 = child.childElements("grandChild2")
|
||||
assertEquals(1, gc2.size, "Expected a single child but found $gc2")
|
||||
assertEquals(1, gc2.size(), "Expected a single child but found $gc2")
|
||||
} else {
|
||||
fail("No child found!")
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ class FilesTest {
|
||||
File.createTempFile("temp3", ".kt", dir)
|
||||
|
||||
val result = dir.listFiles { it.getName().endsWith(".kt") }
|
||||
assertEquals(2, result!!.size)
|
||||
assertEquals(2, result!!.size())
|
||||
}
|
||||
|
||||
test fun recurse() {
|
||||
|
||||
@@ -5,7 +5,7 @@ fun testSize(): Int {
|
||||
val a2 = array("foo")
|
||||
val a3 = array("foo", "bar")
|
||||
|
||||
return a1.size + a2.size + a3.size
|
||||
return a1.size() + a2.size() + a3.size()
|
||||
}
|
||||
|
||||
fun testToListToString(): String {
|
||||
|
||||
@@ -11,9 +11,9 @@ class JsArrayTest {
|
||||
val a2 = array("foo")
|
||||
val a3 = array("foo", "bar")
|
||||
|
||||
assertEquals(0, a1.size)
|
||||
assertEquals(1, a2.size)
|
||||
assertEquals(2, a3.size)
|
||||
assertEquals(0, a1.size())
|
||||
assertEquals(1, a2.size())
|
||||
assertEquals(2, a3.size())
|
||||
|
||||
assertEquals("[]", a1.toList().toString())
|
||||
assertEquals("[foo]", a2.toList().toString())
|
||||
@@ -25,7 +25,7 @@ class JsArrayTest {
|
||||
var c: Collection<String> = array("A", "B", "C").toList()
|
||||
var a = ArrayList(c)
|
||||
|
||||
assertEquals(3, a.size)
|
||||
assertEquals(3, a.size())
|
||||
assertEquals("A", a[0])
|
||||
assertEquals("B", a[1])
|
||||
assertEquals("C", a[2])
|
||||
|
||||
@@ -138,8 +138,8 @@ abstract class MapJsTest {
|
||||
assertFalse(data.isEmpty())
|
||||
assertFalse(data.empty)
|
||||
|
||||
assertEquals(KEYS.size, data.size())
|
||||
assertEquals(KEYS.size, data.size)
|
||||
assertEquals(KEYS.size(), data.size())
|
||||
assertEquals(KEYS.size(), data.size)
|
||||
}
|
||||
|
||||
// #KT-3035
|
||||
@@ -200,7 +200,7 @@ abstract class MapJsTest {
|
||||
val map = createTestMap()
|
||||
val newMap = emptyMutableMap()
|
||||
newMap.putAll(map)
|
||||
assertEquals(KEYS.size, newMap.size)
|
||||
assertEquals(KEYS.size(), newMap.size)
|
||||
}
|
||||
|
||||
test fun mapRemove() {
|
||||
|
||||
@@ -48,14 +48,14 @@ class StringJVMTest {
|
||||
test fun testSplitByChar() {
|
||||
val s = "ab\n[|^$&\\]^cd"
|
||||
var list = s.split('b');
|
||||
assertEquals(2, list.size)
|
||||
assertEquals(2, list.size())
|
||||
assertEquals("a", list[0])
|
||||
assertEquals("\n[|^$&\\]^cd", list[1])
|
||||
list = s.split('^')
|
||||
assertEquals(3, list.size)
|
||||
assertEquals(3, list.size())
|
||||
assertEquals("cd", list[2])
|
||||
list = s.split('.')
|
||||
assertEquals(1, list.size)
|
||||
assertEquals(1, list.size())
|
||||
assertEquals(s, list[0])
|
||||
}
|
||||
|
||||
@@ -113,14 +113,14 @@ class StringJVMTest {
|
||||
|
||||
test fun find() {
|
||||
val data = "a1b2c3"
|
||||
assertEquals('1', data.find { it.isDigit() })
|
||||
assertNull(data.find { it.isUpperCase() })
|
||||
assertEquals('1', data.first { it.isDigit() })
|
||||
assertNull(data.firstOrNull { it.isUpperCase() })
|
||||
}
|
||||
|
||||
test fun findNot() {
|
||||
val data = "1a2b3c"
|
||||
assertEquals('a', data.findNot { it.isDigit() })
|
||||
assertNull(data.findNot { it.isJavaLetterOrDigit() })
|
||||
assertEquals('a', data.filterNot { it.isDigit() }.firstOrNull())
|
||||
assertNull(data.filterNot { it.isJavaLetterOrDigit() }.firstOrNull())
|
||||
}
|
||||
|
||||
test fun partition() {
|
||||
@@ -165,7 +165,7 @@ class StringJVMTest {
|
||||
test fun flatMap() {
|
||||
val data = "abcd"
|
||||
val result = data.flatMap { listOf(it) }
|
||||
assertEquals(data.size, result.count())
|
||||
assertEquals(data.length(), result.count())
|
||||
assertEquals(data.toCharList(), result)
|
||||
}
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ class NoInternalVisibilityInStdLibTest {
|
||||
val byPackage = byFile.keySet().groupBy { it.getPackageFqName() }
|
||||
|
||||
val message = StringBuilder {
|
||||
appendln("There are ${internalDescriptors.size} descriptors that have internal visibility:")
|
||||
appendln("There are ${internalDescriptors.size()} descriptors that have internal visibility:")
|
||||
for ((packageFqName, files) in byPackage) {
|
||||
|
||||
appendln("In package ${packageFqName}:")
|
||||
|
||||
@@ -95,8 +95,11 @@ fun aggregates(): List<GenericFunction> {
|
||||
return count
|
||||
"""
|
||||
}
|
||||
body(Strings, Maps, Collections, ArraysOfObjects, ArraysOfPrimitives) {
|
||||
"return size"
|
||||
body(Strings) {
|
||||
"return length()"
|
||||
}
|
||||
body(Maps, Collections, ArraysOfObjects, ArraysOfPrimitives) {
|
||||
"return size()"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,7 +161,7 @@ fun aggregates(): List<GenericFunction> {
|
||||
}
|
||||
body(ArraysOfObjects, ArraysOfPrimitives) {
|
||||
"""
|
||||
if (size == 0) return null
|
||||
if (size() == 0) return null
|
||||
|
||||
var minElem = this[0]
|
||||
var minValue = f(minElem)
|
||||
@@ -330,7 +333,7 @@ fun aggregates(): List<GenericFunction> {
|
||||
returns("R")
|
||||
body {
|
||||
"""
|
||||
var index = size - 1
|
||||
var index = lastIndex
|
||||
var accumulator = initial
|
||||
while (index >= 0) {
|
||||
accumulator = operation(get(index--), accumulator)
|
||||
@@ -368,7 +371,7 @@ fun aggregates(): List<GenericFunction> {
|
||||
returns("T")
|
||||
body {
|
||||
"""
|
||||
var index = size - 1
|
||||
var index = lastIndex
|
||||
if (index < 0) throw UnsupportedOperationException("Empty iterable can't be reduced")
|
||||
|
||||
var accumulator = get(index--)
|
||||
|
||||
@@ -10,7 +10,7 @@ fun arrays(): List<GenericFunction> {
|
||||
doc { "Returns true if the array is empty" }
|
||||
returns("Boolean")
|
||||
body {
|
||||
"return size == 0"
|
||||
"return size() == 0"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -159,7 +159,7 @@ fun elements(): List<GenericFunction> {
|
||||
"""
|
||||
when (this) {
|
||||
is List<*> -> {
|
||||
if (size == 0)
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Collection is empty")
|
||||
else
|
||||
return this[0] as T
|
||||
@@ -175,7 +175,7 @@ fun elements(): List<GenericFunction> {
|
||||
}
|
||||
body(Strings, Lists, ArraysOfObjects, ArraysOfPrimitives) {
|
||||
"""
|
||||
if (size == 0)
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Collection is empty")
|
||||
return this[0]
|
||||
"""
|
||||
@@ -188,7 +188,7 @@ fun elements(): List<GenericFunction> {
|
||||
"""
|
||||
when (this) {
|
||||
is List<*> -> {
|
||||
if (size == 0)
|
||||
if (isEmpty())
|
||||
return null
|
||||
else
|
||||
return this[0] as T
|
||||
@@ -204,7 +204,7 @@ fun elements(): List<GenericFunction> {
|
||||
}
|
||||
body(Strings, Lists, ArraysOfObjects, ArraysOfPrimitives) {
|
||||
"""
|
||||
return if (size > 0) this[0] else null
|
||||
return if (isEmpty()) null else this[0]
|
||||
"""
|
||||
}
|
||||
}
|
||||
@@ -242,10 +242,10 @@ fun elements(): List<GenericFunction> {
|
||||
"""
|
||||
when (this) {
|
||||
is List<*> -> {
|
||||
if (size == 0)
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Collection is empty")
|
||||
else
|
||||
return this[size - 1] as T
|
||||
return this[this.lastIndex] as T
|
||||
}
|
||||
else -> {
|
||||
val iterator = iterator()
|
||||
@@ -259,11 +259,22 @@ fun elements(): List<GenericFunction> {
|
||||
}
|
||||
"""
|
||||
}
|
||||
body(Streams) {
|
||||
"""
|
||||
val iterator = iterator()
|
||||
if (!iterator.hasNext())
|
||||
throw NoSuchElementException("Collection is empty")
|
||||
var last = iterator.next()
|
||||
while (iterator.hasNext())
|
||||
last = iterator.next()
|
||||
return last
|
||||
"""
|
||||
}
|
||||
body(Strings, Lists, ArraysOfObjects, ArraysOfPrimitives) {
|
||||
"""
|
||||
if (size == 0)
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Collection is empty")
|
||||
return this[size - 1]
|
||||
return this[lastIndex]
|
||||
"""
|
||||
}
|
||||
}
|
||||
@@ -274,7 +285,7 @@ fun elements(): List<GenericFunction> {
|
||||
body {
|
||||
"""
|
||||
when (this) {
|
||||
is List<*> -> return if (size > 0) this[size - 1] as T else null
|
||||
is List<*> -> return if (isEmpty()) null else this[size() - 1] as T
|
||||
else -> {
|
||||
val iterator = iterator()
|
||||
if (!iterator.hasNext())
|
||||
@@ -287,9 +298,25 @@ fun elements(): List<GenericFunction> {
|
||||
}
|
||||
"""
|
||||
}
|
||||
body(Strings, Lists, ArraysOfObjects, ArraysOfPrimitives) {
|
||||
body(Streams) {
|
||||
"""
|
||||
return if (size > 0) this[size - 1] else null
|
||||
val iterator = iterator()
|
||||
if (!iterator.hasNext())
|
||||
return null
|
||||
var last = iterator.next()
|
||||
while (iterator.hasNext())
|
||||
last = iterator.next()
|
||||
return last
|
||||
"""
|
||||
}
|
||||
body(Strings) {
|
||||
"""
|
||||
return if (isEmpty()) null else this[length() - 1]
|
||||
"""
|
||||
}
|
||||
body(Lists, ArraysOfObjects, ArraysOfPrimitives) {
|
||||
"""
|
||||
return if (isEmpty()) null else this[size() - 1]
|
||||
"""
|
||||
}
|
||||
}
|
||||
@@ -331,14 +358,13 @@ fun elements(): List<GenericFunction> {
|
||||
}
|
||||
}
|
||||
|
||||
val bucks = '$'
|
||||
templates add f("single()") {
|
||||
doc { "Returns single element, or throws exception if there is no or more than one element" }
|
||||
returns("T")
|
||||
body {
|
||||
"""
|
||||
when (this) {
|
||||
is List<*> -> return when (size) {
|
||||
is List<*> -> return when (size()) {
|
||||
0 -> throw NoSuchElementException("Collection is empty")
|
||||
1 -> this[0] as T
|
||||
else -> throw IllegalArgumentException("Collection has more than one element")
|
||||
@@ -355,9 +381,18 @@ fun elements(): List<GenericFunction> {
|
||||
}
|
||||
"""
|
||||
}
|
||||
body(Strings, Lists, ArraysOfObjects, ArraysOfPrimitives) {
|
||||
body(Strings) {
|
||||
"""
|
||||
return when (size) {
|
||||
return when (length()) {
|
||||
0 -> throw NoSuchElementException("Collection is empty")
|
||||
1 -> this[0]
|
||||
else -> throw IllegalArgumentException("Collection has more than one element")
|
||||
}
|
||||
"""
|
||||
}
|
||||
body(Lists, ArraysOfObjects, ArraysOfPrimitives) {
|
||||
"""
|
||||
return when (size()) {
|
||||
0 -> throw NoSuchElementException("Collection is empty")
|
||||
1 -> this[0]
|
||||
else -> throw IllegalArgumentException("Collection has more than one element")
|
||||
@@ -372,7 +407,7 @@ fun elements(): List<GenericFunction> {
|
||||
body {
|
||||
"""
|
||||
when (this) {
|
||||
is List<*> -> return if (size == 1) this[0] as T else null
|
||||
is List<*> -> return if (size() == 1) this[0] as T else null
|
||||
else -> {
|
||||
val iterator = iterator()
|
||||
if (!iterator.hasNext())
|
||||
@@ -385,9 +420,14 @@ fun elements(): List<GenericFunction> {
|
||||
}
|
||||
"""
|
||||
}
|
||||
body(Strings, Lists, ArraysOfObjects, ArraysOfPrimitives) {
|
||||
body(Strings) {
|
||||
"""
|
||||
return if (size == 1) this[0] else null
|
||||
return if (length() == 1) this[0] else null
|
||||
"""
|
||||
}
|
||||
body(Lists, ArraysOfObjects, ArraysOfPrimitives) {
|
||||
"""
|
||||
return if (size() == 1) this[0] else null
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,16 +27,16 @@ fun filtering(): List<GenericFunction> {
|
||||
"""
|
||||
}
|
||||
|
||||
body(Strings) { "return substring(Math.min(n, size))" }
|
||||
body(Strings) { "return substring(Math.min(n, length()))" }
|
||||
returns(Strings) { "String" }
|
||||
|
||||
body(Collections, ArraysOfObjects, ArraysOfPrimitives) {
|
||||
"""
|
||||
if (n >= size)
|
||||
if (n >= size())
|
||||
return ArrayList<T>()
|
||||
|
||||
var count = 0
|
||||
val list = ArrayList<T>(size - n)
|
||||
val list = ArrayList<T>(size() - n)
|
||||
for (item in this) {
|
||||
if (count++ >= n) list.add(item)
|
||||
}
|
||||
@@ -61,7 +61,7 @@ fun filtering(): List<GenericFunction> {
|
||||
"""
|
||||
}
|
||||
|
||||
body(Strings) { "return substring(0, Math.min(n, size))" }
|
||||
body(Strings) { "return substring(0, Math.min(n, length()))" }
|
||||
returns(Strings) { "String" }
|
||||
|
||||
doc(Streams) { "Returns a stream containing first *n* elements" }
|
||||
@@ -76,7 +76,7 @@ fun filtering(): List<GenericFunction> {
|
||||
body(Collections, ArraysOfObjects, ArraysOfPrimitives) {
|
||||
"""
|
||||
var count = 0
|
||||
val realN = if (n > size) size else n
|
||||
val realN = if (n > size()) size() else n
|
||||
val list = ArrayList<T>(realN)
|
||||
for (item in this) {
|
||||
if (count++ == realN)
|
||||
|
||||
@@ -19,7 +19,7 @@ fun sets(): List<GenericFunction> {
|
||||
}
|
||||
body(ArraysOfObjects, ArraysOfPrimitives) {
|
||||
"""
|
||||
val set = LinkedHashSet<T>(size)
|
||||
val set = LinkedHashSet<T>(size())
|
||||
for (item in this) set.add(item)
|
||||
return set
|
||||
"""
|
||||
|
||||
@@ -52,7 +52,7 @@ fun snapshots(): List<GenericFunction> {
|
||||
*/
|
||||
body(ArraysOfObjects, ArraysOfPrimitives) {
|
||||
"""
|
||||
val list = ArrayList<T>(size)
|
||||
val list = ArrayList<T>(size())
|
||||
for (item in this) list.add(item)
|
||||
return list
|
||||
"""
|
||||
@@ -65,7 +65,7 @@ fun snapshots(): List<GenericFunction> {
|
||||
returns("List<Pair<K, V>>")
|
||||
body {
|
||||
"""
|
||||
val result = ArrayList<Pair<K, V>>(size)
|
||||
val result = ArrayList<Pair<K, V>>(size())
|
||||
for (item in this)
|
||||
result.add(item.key to item.value)
|
||||
return result
|
||||
@@ -93,7 +93,7 @@ fun snapshots(): List<GenericFunction> {
|
||||
*/
|
||||
body(ArraysOfPrimitives) {
|
||||
"""
|
||||
val list = ArrayList<T>(size)
|
||||
val list = ArrayList<T>(size())
|
||||
for (item in this) list.add(item)
|
||||
return list
|
||||
"""
|
||||
|
||||
@@ -19,10 +19,10 @@ fun specialJVM(): List<GenericFunction> {
|
||||
doc { "Returns new array which is a copy of the original array" }
|
||||
returns("SELF")
|
||||
body {
|
||||
"return Arrays.copyOf(this, size)"
|
||||
"return Arrays.copyOf(this, size())"
|
||||
}
|
||||
body(ArraysOfObjects) {
|
||||
"return Arrays.copyOf(this, size) as Array<T>"
|
||||
"return Arrays.copyOf(this, size()) as Array<T>"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ fun specialJVM(): List<GenericFunction> {
|
||||
}
|
||||
}
|
||||
|
||||
templates add f("binarySearch(element: T, fromIndex: Int = 0, toIndex: Int = size)") {
|
||||
templates add f("binarySearch(element: T, fromIndex: Int = 0, toIndex: Int = size())") {
|
||||
only(ArraysOfObjects, ArraysOfPrimitives)
|
||||
exclude(PrimitiveType.Boolean)
|
||||
doc { "Searches array or range of array for provided element index using binary search algorithm. Array is expected to be sorted." }
|
||||
@@ -63,7 +63,7 @@ fun specialJVM(): List<GenericFunction> {
|
||||
}
|
||||
}
|
||||
|
||||
templates add f("sort(fromIndex: Int = 0, toIndex: Int = size)") {
|
||||
templates add f("sort(fromIndex: Int = 0, toIndex: Int = size())") {
|
||||
only(ArraysOfObjects, ArraysOfPrimitives)
|
||||
exclude(PrimitiveType.Boolean)
|
||||
doc { "Sorts array or range in array inplace" }
|
||||
|
||||
Reference in New Issue
Block a user