Review and correct exception messages.
This commit is contained in:
@@ -802,7 +802,7 @@ public inline fun CharArray.findLast(predicate: (Char) -> Boolean): Char? {
|
||||
*/
|
||||
public fun <T> Array<out T>.first(): T {
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Collection is empty.")
|
||||
throw NoSuchElementException("Array is empty.")
|
||||
return this[0]
|
||||
}
|
||||
|
||||
@@ -812,7 +812,7 @@ public fun <T> Array<out T>.first(): T {
|
||||
*/
|
||||
public fun ByteArray.first(): Byte {
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Collection is empty.")
|
||||
throw NoSuchElementException("Array is empty.")
|
||||
return this[0]
|
||||
}
|
||||
|
||||
@@ -822,7 +822,7 @@ public fun ByteArray.first(): Byte {
|
||||
*/
|
||||
public fun ShortArray.first(): Short {
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Collection is empty.")
|
||||
throw NoSuchElementException("Array is empty.")
|
||||
return this[0]
|
||||
}
|
||||
|
||||
@@ -832,7 +832,7 @@ public fun ShortArray.first(): Short {
|
||||
*/
|
||||
public fun IntArray.first(): Int {
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Collection is empty.")
|
||||
throw NoSuchElementException("Array is empty.")
|
||||
return this[0]
|
||||
}
|
||||
|
||||
@@ -842,7 +842,7 @@ public fun IntArray.first(): Int {
|
||||
*/
|
||||
public fun LongArray.first(): Long {
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Collection is empty.")
|
||||
throw NoSuchElementException("Array is empty.")
|
||||
return this[0]
|
||||
}
|
||||
|
||||
@@ -852,7 +852,7 @@ public fun LongArray.first(): Long {
|
||||
*/
|
||||
public fun FloatArray.first(): Float {
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Collection is empty.")
|
||||
throw NoSuchElementException("Array is empty.")
|
||||
return this[0]
|
||||
}
|
||||
|
||||
@@ -862,7 +862,7 @@ public fun FloatArray.first(): Float {
|
||||
*/
|
||||
public fun DoubleArray.first(): Double {
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Collection is empty.")
|
||||
throw NoSuchElementException("Array is empty.")
|
||||
return this[0]
|
||||
}
|
||||
|
||||
@@ -872,7 +872,7 @@ public fun DoubleArray.first(): Double {
|
||||
*/
|
||||
public fun BooleanArray.first(): Boolean {
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Collection is empty.")
|
||||
throw NoSuchElementException("Array is empty.")
|
||||
return this[0]
|
||||
}
|
||||
|
||||
@@ -882,7 +882,7 @@ public fun BooleanArray.first(): Boolean {
|
||||
*/
|
||||
public fun CharArray.first(): Char {
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Collection is empty.")
|
||||
throw NoSuchElementException("Array is empty.")
|
||||
return this[0]
|
||||
}
|
||||
|
||||
@@ -892,7 +892,7 @@ public fun CharArray.first(): Char {
|
||||
*/
|
||||
public inline fun <T> Array<out T>.first(predicate: (T) -> Boolean): T {
|
||||
for (element in this) if (predicate(element)) return element
|
||||
throw NoSuchElementException("No element matching predicate was found.")
|
||||
throw NoSuchElementException("Array contains no element matching the predicate.")
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -901,7 +901,7 @@ public inline fun <T> Array<out T>.first(predicate: (T) -> Boolean): T {
|
||||
*/
|
||||
public inline fun ByteArray.first(predicate: (Byte) -> Boolean): Byte {
|
||||
for (element in this) if (predicate(element)) return element
|
||||
throw NoSuchElementException("No element matching predicate was found.")
|
||||
throw NoSuchElementException("Array contains no element matching the predicate.")
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -910,7 +910,7 @@ public inline fun ByteArray.first(predicate: (Byte) -> Boolean): Byte {
|
||||
*/
|
||||
public inline fun ShortArray.first(predicate: (Short) -> Boolean): Short {
|
||||
for (element in this) if (predicate(element)) return element
|
||||
throw NoSuchElementException("No element matching predicate was found.")
|
||||
throw NoSuchElementException("Array contains no element matching the predicate.")
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -919,7 +919,7 @@ public inline fun ShortArray.first(predicate: (Short) -> Boolean): Short {
|
||||
*/
|
||||
public inline fun IntArray.first(predicate: (Int) -> Boolean): Int {
|
||||
for (element in this) if (predicate(element)) return element
|
||||
throw NoSuchElementException("No element matching predicate was found.")
|
||||
throw NoSuchElementException("Array contains no element matching the predicate.")
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -928,7 +928,7 @@ public inline fun IntArray.first(predicate: (Int) -> Boolean): Int {
|
||||
*/
|
||||
public inline fun LongArray.first(predicate: (Long) -> Boolean): Long {
|
||||
for (element in this) if (predicate(element)) return element
|
||||
throw NoSuchElementException("No element matching predicate was found.")
|
||||
throw NoSuchElementException("Array contains no element matching the predicate.")
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -937,7 +937,7 @@ public inline fun LongArray.first(predicate: (Long) -> Boolean): Long {
|
||||
*/
|
||||
public inline fun FloatArray.first(predicate: (Float) -> Boolean): Float {
|
||||
for (element in this) if (predicate(element)) return element
|
||||
throw NoSuchElementException("No element matching predicate was found.")
|
||||
throw NoSuchElementException("Array contains no element matching the predicate.")
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -946,7 +946,7 @@ public inline fun FloatArray.first(predicate: (Float) -> Boolean): Float {
|
||||
*/
|
||||
public inline fun DoubleArray.first(predicate: (Double) -> Boolean): Double {
|
||||
for (element in this) if (predicate(element)) return element
|
||||
throw NoSuchElementException("No element matching predicate was found.")
|
||||
throw NoSuchElementException("Array contains no element matching the predicate.")
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -955,7 +955,7 @@ public inline fun DoubleArray.first(predicate: (Double) -> Boolean): Double {
|
||||
*/
|
||||
public inline fun BooleanArray.first(predicate: (Boolean) -> Boolean): Boolean {
|
||||
for (element in this) if (predicate(element)) return element
|
||||
throw NoSuchElementException("No element matching predicate was found.")
|
||||
throw NoSuchElementException("Array contains no element matching the predicate.")
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -964,7 +964,7 @@ public inline fun BooleanArray.first(predicate: (Boolean) -> Boolean): Boolean {
|
||||
*/
|
||||
public inline fun CharArray.first(predicate: (Char) -> Boolean): Char {
|
||||
for (element in this) if (predicate(element)) return element
|
||||
throw NoSuchElementException("No element matching predicate was found.")
|
||||
throw NoSuchElementException("Array contains no element matching the predicate.")
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1575,7 +1575,7 @@ public inline fun CharArray.indexOfLast(predicate: (Char) -> Boolean): Int {
|
||||
*/
|
||||
public fun <T> Array<out T>.last(): T {
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Collection is empty.")
|
||||
throw NoSuchElementException("Array is empty.")
|
||||
return this[lastIndex]
|
||||
}
|
||||
|
||||
@@ -1585,7 +1585,7 @@ public fun <T> Array<out T>.last(): T {
|
||||
*/
|
||||
public fun ByteArray.last(): Byte {
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Collection is empty.")
|
||||
throw NoSuchElementException("Array is empty.")
|
||||
return this[lastIndex]
|
||||
}
|
||||
|
||||
@@ -1595,7 +1595,7 @@ public fun ByteArray.last(): Byte {
|
||||
*/
|
||||
public fun ShortArray.last(): Short {
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Collection is empty.")
|
||||
throw NoSuchElementException("Array is empty.")
|
||||
return this[lastIndex]
|
||||
}
|
||||
|
||||
@@ -1605,7 +1605,7 @@ public fun ShortArray.last(): Short {
|
||||
*/
|
||||
public fun IntArray.last(): Int {
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Collection is empty.")
|
||||
throw NoSuchElementException("Array is empty.")
|
||||
return this[lastIndex]
|
||||
}
|
||||
|
||||
@@ -1615,7 +1615,7 @@ public fun IntArray.last(): Int {
|
||||
*/
|
||||
public fun LongArray.last(): Long {
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Collection is empty.")
|
||||
throw NoSuchElementException("Array is empty.")
|
||||
return this[lastIndex]
|
||||
}
|
||||
|
||||
@@ -1625,7 +1625,7 @@ public fun LongArray.last(): Long {
|
||||
*/
|
||||
public fun FloatArray.last(): Float {
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Collection is empty.")
|
||||
throw NoSuchElementException("Array is empty.")
|
||||
return this[lastIndex]
|
||||
}
|
||||
|
||||
@@ -1635,7 +1635,7 @@ public fun FloatArray.last(): Float {
|
||||
*/
|
||||
public fun DoubleArray.last(): Double {
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Collection is empty.")
|
||||
throw NoSuchElementException("Array is empty.")
|
||||
return this[lastIndex]
|
||||
}
|
||||
|
||||
@@ -1645,7 +1645,7 @@ public fun DoubleArray.last(): Double {
|
||||
*/
|
||||
public fun BooleanArray.last(): Boolean {
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Collection is empty.")
|
||||
throw NoSuchElementException("Array is empty.")
|
||||
return this[lastIndex]
|
||||
}
|
||||
|
||||
@@ -1655,7 +1655,7 @@ public fun BooleanArray.last(): Boolean {
|
||||
*/
|
||||
public fun CharArray.last(): Char {
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Collection is empty.")
|
||||
throw NoSuchElementException("Array is empty.")
|
||||
return this[lastIndex]
|
||||
}
|
||||
|
||||
@@ -1668,7 +1668,7 @@ public inline fun <T> Array<out T>.last(predicate: (T) -> Boolean): T {
|
||||
val element = this[index]
|
||||
if (predicate(element)) return element
|
||||
}
|
||||
throw NoSuchElementException("Collection doesn't contain any element matching the predicate.")
|
||||
throw NoSuchElementException("Array contains no element matching the predicate.")
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1680,7 +1680,7 @@ public inline fun ByteArray.last(predicate: (Byte) -> Boolean): Byte {
|
||||
val element = this[index]
|
||||
if (predicate(element)) return element
|
||||
}
|
||||
throw NoSuchElementException("Collection doesn't contain any element matching the predicate.")
|
||||
throw NoSuchElementException("Array contains no element matching the predicate.")
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1692,7 +1692,7 @@ public inline fun ShortArray.last(predicate: (Short) -> Boolean): Short {
|
||||
val element = this[index]
|
||||
if (predicate(element)) return element
|
||||
}
|
||||
throw NoSuchElementException("Collection doesn't contain any element matching the predicate.")
|
||||
throw NoSuchElementException("Array contains no element matching the predicate.")
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1704,7 +1704,7 @@ public inline fun IntArray.last(predicate: (Int) -> Boolean): Int {
|
||||
val element = this[index]
|
||||
if (predicate(element)) return element
|
||||
}
|
||||
throw NoSuchElementException("Collection doesn't contain any element matching the predicate.")
|
||||
throw NoSuchElementException("Array contains no element matching the predicate.")
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1716,7 +1716,7 @@ public inline fun LongArray.last(predicate: (Long) -> Boolean): Long {
|
||||
val element = this[index]
|
||||
if (predicate(element)) return element
|
||||
}
|
||||
throw NoSuchElementException("Collection doesn't contain any element matching the predicate.")
|
||||
throw NoSuchElementException("Array contains no element matching the predicate.")
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1728,7 +1728,7 @@ public inline fun FloatArray.last(predicate: (Float) -> Boolean): Float {
|
||||
val element = this[index]
|
||||
if (predicate(element)) return element
|
||||
}
|
||||
throw NoSuchElementException("Collection doesn't contain any element matching the predicate.")
|
||||
throw NoSuchElementException("Array contains no element matching the predicate.")
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1740,7 +1740,7 @@ public inline fun DoubleArray.last(predicate: (Double) -> Boolean): Double {
|
||||
val element = this[index]
|
||||
if (predicate(element)) return element
|
||||
}
|
||||
throw NoSuchElementException("Collection doesn't contain any element matching the predicate.")
|
||||
throw NoSuchElementException("Array contains no element matching the predicate.")
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1752,7 +1752,7 @@ public inline fun BooleanArray.last(predicate: (Boolean) -> Boolean): Boolean {
|
||||
val element = this[index]
|
||||
if (predicate(element)) return element
|
||||
}
|
||||
throw NoSuchElementException("Collection doesn't contain any element matching the predicate.")
|
||||
throw NoSuchElementException("Array contains no element matching the predicate.")
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1764,7 +1764,7 @@ public inline fun CharArray.last(predicate: (Char) -> Boolean): Char {
|
||||
val element = this[index]
|
||||
if (predicate(element)) return element
|
||||
}
|
||||
throw NoSuchElementException("Collection doesn't contain any element matching the predicate.")
|
||||
throw NoSuchElementException("Array contains no element matching the predicate.")
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2050,9 +2050,9 @@ public inline fun CharArray.lastOrNull(predicate: (Char) -> Boolean): Char? {
|
||||
*/
|
||||
public fun <T> Array<out T>.single(): T {
|
||||
return when (size) {
|
||||
0 -> throw NoSuchElementException("Collection is empty.")
|
||||
0 -> throw NoSuchElementException("Array is empty.")
|
||||
1 -> this[0]
|
||||
else -> throw IllegalArgumentException("Collection has more than one element.")
|
||||
else -> throw IllegalArgumentException("Array has more than one element.")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2061,9 +2061,9 @@ public fun <T> Array<out T>.single(): T {
|
||||
*/
|
||||
public fun ByteArray.single(): Byte {
|
||||
return when (size) {
|
||||
0 -> throw NoSuchElementException("Collection is empty.")
|
||||
0 -> throw NoSuchElementException("Array is empty.")
|
||||
1 -> this[0]
|
||||
else -> throw IllegalArgumentException("Collection has more than one element.")
|
||||
else -> throw IllegalArgumentException("Array has more than one element.")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2072,9 +2072,9 @@ public fun ByteArray.single(): Byte {
|
||||
*/
|
||||
public fun ShortArray.single(): Short {
|
||||
return when (size) {
|
||||
0 -> throw NoSuchElementException("Collection is empty.")
|
||||
0 -> throw NoSuchElementException("Array is empty.")
|
||||
1 -> this[0]
|
||||
else -> throw IllegalArgumentException("Collection has more than one element.")
|
||||
else -> throw IllegalArgumentException("Array has more than one element.")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2083,9 +2083,9 @@ public fun ShortArray.single(): Short {
|
||||
*/
|
||||
public fun IntArray.single(): Int {
|
||||
return when (size) {
|
||||
0 -> throw NoSuchElementException("Collection is empty.")
|
||||
0 -> throw NoSuchElementException("Array is empty.")
|
||||
1 -> this[0]
|
||||
else -> throw IllegalArgumentException("Collection has more than one element.")
|
||||
else -> throw IllegalArgumentException("Array has more than one element.")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2094,9 +2094,9 @@ public fun IntArray.single(): Int {
|
||||
*/
|
||||
public fun LongArray.single(): Long {
|
||||
return when (size) {
|
||||
0 -> throw NoSuchElementException("Collection is empty.")
|
||||
0 -> throw NoSuchElementException("Array is empty.")
|
||||
1 -> this[0]
|
||||
else -> throw IllegalArgumentException("Collection has more than one element.")
|
||||
else -> throw IllegalArgumentException("Array has more than one element.")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2105,9 +2105,9 @@ public fun LongArray.single(): Long {
|
||||
*/
|
||||
public fun FloatArray.single(): Float {
|
||||
return when (size) {
|
||||
0 -> throw NoSuchElementException("Collection is empty.")
|
||||
0 -> throw NoSuchElementException("Array is empty.")
|
||||
1 -> this[0]
|
||||
else -> throw IllegalArgumentException("Collection has more than one element.")
|
||||
else -> throw IllegalArgumentException("Array has more than one element.")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2116,9 +2116,9 @@ public fun FloatArray.single(): Float {
|
||||
*/
|
||||
public fun DoubleArray.single(): Double {
|
||||
return when (size) {
|
||||
0 -> throw NoSuchElementException("Collection is empty.")
|
||||
0 -> throw NoSuchElementException("Array is empty.")
|
||||
1 -> this[0]
|
||||
else -> throw IllegalArgumentException("Collection has more than one element.")
|
||||
else -> throw IllegalArgumentException("Array has more than one element.")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2127,9 +2127,9 @@ public fun DoubleArray.single(): Double {
|
||||
*/
|
||||
public fun BooleanArray.single(): Boolean {
|
||||
return when (size) {
|
||||
0 -> throw NoSuchElementException("Collection is empty.")
|
||||
0 -> throw NoSuchElementException("Array is empty.")
|
||||
1 -> this[0]
|
||||
else -> throw IllegalArgumentException("Collection has more than one element.")
|
||||
else -> throw IllegalArgumentException("Array has more than one element.")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2138,9 +2138,9 @@ public fun BooleanArray.single(): Boolean {
|
||||
*/
|
||||
public fun CharArray.single(): Char {
|
||||
return when (size) {
|
||||
0 -> throw NoSuchElementException("Collection is empty.")
|
||||
0 -> throw NoSuchElementException("Array is empty.")
|
||||
1 -> this[0]
|
||||
else -> throw IllegalArgumentException("Collection has more than one element.")
|
||||
else -> throw IllegalArgumentException("Array has more than one element.")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2152,12 +2152,12 @@ public inline fun <T> Array<out T>.single(predicate: (T) -> Boolean): T {
|
||||
var found = false
|
||||
for (element in this) {
|
||||
if (predicate(element)) {
|
||||
if (found) throw IllegalArgumentException("Collection contains more than one matching element.")
|
||||
if (found) throw IllegalArgumentException("Array contains more than one matching element.")
|
||||
single = element
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if (!found) throw NoSuchElementException("Collection doesn't contain any element matching predicate.")
|
||||
if (!found) throw NoSuchElementException("Array contains no element matching the predicate.")
|
||||
return single as T
|
||||
}
|
||||
|
||||
@@ -2169,12 +2169,12 @@ public inline fun ByteArray.single(predicate: (Byte) -> Boolean): Byte {
|
||||
var found = false
|
||||
for (element in this) {
|
||||
if (predicate(element)) {
|
||||
if (found) throw IllegalArgumentException("Collection contains more than one matching element.")
|
||||
if (found) throw IllegalArgumentException("Array contains more than one matching element.")
|
||||
single = element
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if (!found) throw NoSuchElementException("Collection doesn't contain any element matching predicate.")
|
||||
if (!found) throw NoSuchElementException("Array contains no element matching the predicate.")
|
||||
return single as Byte
|
||||
}
|
||||
|
||||
@@ -2186,12 +2186,12 @@ public inline fun ShortArray.single(predicate: (Short) -> Boolean): Short {
|
||||
var found = false
|
||||
for (element in this) {
|
||||
if (predicate(element)) {
|
||||
if (found) throw IllegalArgumentException("Collection contains more than one matching element.")
|
||||
if (found) throw IllegalArgumentException("Array contains more than one matching element.")
|
||||
single = element
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if (!found) throw NoSuchElementException("Collection doesn't contain any element matching predicate.")
|
||||
if (!found) throw NoSuchElementException("Array contains no element matching the predicate.")
|
||||
return single as Short
|
||||
}
|
||||
|
||||
@@ -2203,12 +2203,12 @@ public inline fun IntArray.single(predicate: (Int) -> Boolean): Int {
|
||||
var found = false
|
||||
for (element in this) {
|
||||
if (predicate(element)) {
|
||||
if (found) throw IllegalArgumentException("Collection contains more than one matching element.")
|
||||
if (found) throw IllegalArgumentException("Array contains more than one matching element.")
|
||||
single = element
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if (!found) throw NoSuchElementException("Collection doesn't contain any element matching predicate.")
|
||||
if (!found) throw NoSuchElementException("Array contains no element matching the predicate.")
|
||||
return single as Int
|
||||
}
|
||||
|
||||
@@ -2220,12 +2220,12 @@ public inline fun LongArray.single(predicate: (Long) -> Boolean): Long {
|
||||
var found = false
|
||||
for (element in this) {
|
||||
if (predicate(element)) {
|
||||
if (found) throw IllegalArgumentException("Collection contains more than one matching element.")
|
||||
if (found) throw IllegalArgumentException("Array contains more than one matching element.")
|
||||
single = element
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if (!found) throw NoSuchElementException("Collection doesn't contain any element matching predicate.")
|
||||
if (!found) throw NoSuchElementException("Array contains no element matching the predicate.")
|
||||
return single as Long
|
||||
}
|
||||
|
||||
@@ -2237,12 +2237,12 @@ public inline fun FloatArray.single(predicate: (Float) -> Boolean): Float {
|
||||
var found = false
|
||||
for (element in this) {
|
||||
if (predicate(element)) {
|
||||
if (found) throw IllegalArgumentException("Collection contains more than one matching element.")
|
||||
if (found) throw IllegalArgumentException("Array contains more than one matching element.")
|
||||
single = element
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if (!found) throw NoSuchElementException("Collection doesn't contain any element matching predicate.")
|
||||
if (!found) throw NoSuchElementException("Array contains no element matching the predicate.")
|
||||
return single as Float
|
||||
}
|
||||
|
||||
@@ -2254,12 +2254,12 @@ public inline fun DoubleArray.single(predicate: (Double) -> Boolean): Double {
|
||||
var found = false
|
||||
for (element in this) {
|
||||
if (predicate(element)) {
|
||||
if (found) throw IllegalArgumentException("Collection contains more than one matching element.")
|
||||
if (found) throw IllegalArgumentException("Array contains more than one matching element.")
|
||||
single = element
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if (!found) throw NoSuchElementException("Collection doesn't contain any element matching predicate.")
|
||||
if (!found) throw NoSuchElementException("Array contains no element matching the predicate.")
|
||||
return single as Double
|
||||
}
|
||||
|
||||
@@ -2271,12 +2271,12 @@ public inline fun BooleanArray.single(predicate: (Boolean) -> Boolean): Boolean
|
||||
var found = false
|
||||
for (element in this) {
|
||||
if (predicate(element)) {
|
||||
if (found) throw IllegalArgumentException("Collection contains more than one matching element.")
|
||||
if (found) throw IllegalArgumentException("Array contains more than one matching element.")
|
||||
single = element
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if (!found) throw NoSuchElementException("Collection doesn't contain any element matching predicate.")
|
||||
if (!found) throw NoSuchElementException("Array contains no element matching the predicate.")
|
||||
return single as Boolean
|
||||
}
|
||||
|
||||
@@ -2288,12 +2288,12 @@ public inline fun CharArray.single(predicate: (Char) -> Boolean): Char {
|
||||
var found = false
|
||||
for (element in this) {
|
||||
if (predicate(element)) {
|
||||
if (found) throw IllegalArgumentException("Collection contains more than one matching element.")
|
||||
if (found) throw IllegalArgumentException("Array contains more than one matching element.")
|
||||
single = element
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if (!found) throw NoSuchElementException("Collection doesn't contain any element matching predicate.")
|
||||
if (!found) throw NoSuchElementException("Array contains no element matching the predicate.")
|
||||
return single as Char
|
||||
}
|
||||
|
||||
@@ -2517,7 +2517,7 @@ public inline fun CharArray.singleOrNull(predicate: (Char) -> Boolean): Char? {
|
||||
* Returns a list containing all elements except first [n] elements.
|
||||
*/
|
||||
public fun <T> Array<out T>.drop(n: Int): List<T> {
|
||||
require(n >= 0, { "Requested element count $n is less than zero." })
|
||||
require(n >= 0) { "Requested element count $n is less than zero." }
|
||||
if (n == 0)
|
||||
return toList()
|
||||
if (n >= size)
|
||||
@@ -2533,7 +2533,7 @@ public fun <T> Array<out T>.drop(n: Int): List<T> {
|
||||
* Returns a list containing all elements except first [n] elements.
|
||||
*/
|
||||
public fun ByteArray.drop(n: Int): List<Byte> {
|
||||
require(n >= 0, { "Requested element count $n is less than zero." })
|
||||
require(n >= 0) { "Requested element count $n is less than zero." }
|
||||
if (n == 0)
|
||||
return toList()
|
||||
if (n >= size)
|
||||
@@ -2549,7 +2549,7 @@ public fun ByteArray.drop(n: Int): List<Byte> {
|
||||
* Returns a list containing all elements except first [n] elements.
|
||||
*/
|
||||
public fun ShortArray.drop(n: Int): List<Short> {
|
||||
require(n >= 0, { "Requested element count $n is less than zero." })
|
||||
require(n >= 0) { "Requested element count $n is less than zero." }
|
||||
if (n == 0)
|
||||
return toList()
|
||||
if (n >= size)
|
||||
@@ -2565,7 +2565,7 @@ public fun ShortArray.drop(n: Int): List<Short> {
|
||||
* Returns a list containing all elements except first [n] elements.
|
||||
*/
|
||||
public fun IntArray.drop(n: Int): List<Int> {
|
||||
require(n >= 0, { "Requested element count $n is less than zero." })
|
||||
require(n >= 0) { "Requested element count $n is less than zero." }
|
||||
if (n == 0)
|
||||
return toList()
|
||||
if (n >= size)
|
||||
@@ -2581,7 +2581,7 @@ 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> {
|
||||
require(n >= 0, { "Requested element count $n is less than zero." })
|
||||
require(n >= 0) { "Requested element count $n is less than zero." }
|
||||
if (n == 0)
|
||||
return toList()
|
||||
if (n >= size)
|
||||
@@ -2597,7 +2597,7 @@ public fun LongArray.drop(n: Int): List<Long> {
|
||||
* Returns a list containing all elements except first [n] elements.
|
||||
*/
|
||||
public fun FloatArray.drop(n: Int): List<Float> {
|
||||
require(n >= 0, { "Requested element count $n is less than zero." })
|
||||
require(n >= 0) { "Requested element count $n is less than zero." }
|
||||
if (n == 0)
|
||||
return toList()
|
||||
if (n >= size)
|
||||
@@ -2613,7 +2613,7 @@ public fun FloatArray.drop(n: Int): List<Float> {
|
||||
* Returns a list containing all elements except first [n] elements.
|
||||
*/
|
||||
public fun DoubleArray.drop(n: Int): List<Double> {
|
||||
require(n >= 0, { "Requested element count $n is less than zero." })
|
||||
require(n >= 0) { "Requested element count $n is less than zero." }
|
||||
if (n == 0)
|
||||
return toList()
|
||||
if (n >= size)
|
||||
@@ -2629,7 +2629,7 @@ public fun DoubleArray.drop(n: Int): List<Double> {
|
||||
* Returns a list containing all elements except first [n] elements.
|
||||
*/
|
||||
public fun BooleanArray.drop(n: Int): List<Boolean> {
|
||||
require(n >= 0, { "Requested element count $n is less than zero." })
|
||||
require(n >= 0) { "Requested element count $n is less than zero." }
|
||||
if (n == 0)
|
||||
return toList()
|
||||
if (n >= size)
|
||||
@@ -2645,7 +2645,7 @@ public fun BooleanArray.drop(n: Int): List<Boolean> {
|
||||
* Returns a list containing all elements except first [n] elements.
|
||||
*/
|
||||
public fun CharArray.drop(n: Int): List<Char> {
|
||||
require(n >= 0, { "Requested element count $n is less than zero." })
|
||||
require(n >= 0) { "Requested element count $n is less than zero." }
|
||||
if (n == 0)
|
||||
return toList()
|
||||
if (n >= size)
|
||||
@@ -2661,7 +2661,7 @@ public fun CharArray.drop(n: Int): List<Char> {
|
||||
* Returns a list containing all elements except last [n] elements.
|
||||
*/
|
||||
public fun <T> Array<out T>.dropLast(n: Int): List<T> {
|
||||
require(n >= 0, { "Requested element count $n is less than zero." })
|
||||
require(n >= 0) { "Requested element count $n is less than zero." }
|
||||
return take((size - n).coerceAtLeast(0))
|
||||
}
|
||||
|
||||
@@ -2669,7 +2669,7 @@ public fun <T> Array<out T>.dropLast(n: Int): List<T> {
|
||||
* Returns a list containing all elements except last [n] elements.
|
||||
*/
|
||||
public fun ByteArray.dropLast(n: Int): List<Byte> {
|
||||
require(n >= 0, { "Requested element count $n is less than zero." })
|
||||
require(n >= 0) { "Requested element count $n is less than zero." }
|
||||
return take((size - n).coerceAtLeast(0))
|
||||
}
|
||||
|
||||
@@ -2677,7 +2677,7 @@ public fun ByteArray.dropLast(n: Int): List<Byte> {
|
||||
* Returns a list containing all elements except last [n] elements.
|
||||
*/
|
||||
public fun ShortArray.dropLast(n: Int): List<Short> {
|
||||
require(n >= 0, { "Requested element count $n is less than zero." })
|
||||
require(n >= 0) { "Requested element count $n is less than zero." }
|
||||
return take((size - n).coerceAtLeast(0))
|
||||
}
|
||||
|
||||
@@ -2685,7 +2685,7 @@ public fun ShortArray.dropLast(n: Int): List<Short> {
|
||||
* Returns a list containing all elements except last [n] elements.
|
||||
*/
|
||||
public fun IntArray.dropLast(n: Int): List<Int> {
|
||||
require(n >= 0, { "Requested element count $n is less than zero." })
|
||||
require(n >= 0) { "Requested element count $n is less than zero." }
|
||||
return take((size - n).coerceAtLeast(0))
|
||||
}
|
||||
|
||||
@@ -2693,7 +2693,7 @@ public fun IntArray.dropLast(n: Int): List<Int> {
|
||||
* Returns a list containing all elements except last [n] elements.
|
||||
*/
|
||||
public fun LongArray.dropLast(n: Int): List<Long> {
|
||||
require(n >= 0, { "Requested element count $n is less than zero." })
|
||||
require(n >= 0) { "Requested element count $n is less than zero." }
|
||||
return take((size - n).coerceAtLeast(0))
|
||||
}
|
||||
|
||||
@@ -2701,7 +2701,7 @@ public fun LongArray.dropLast(n: Int): List<Long> {
|
||||
* Returns a list containing all elements except last [n] elements.
|
||||
*/
|
||||
public fun FloatArray.dropLast(n: Int): List<Float> {
|
||||
require(n >= 0, { "Requested element count $n is less than zero." })
|
||||
require(n >= 0) { "Requested element count $n is less than zero." }
|
||||
return take((size - n).coerceAtLeast(0))
|
||||
}
|
||||
|
||||
@@ -2709,7 +2709,7 @@ public fun FloatArray.dropLast(n: Int): List<Float> {
|
||||
* Returns a list containing all elements except last [n] elements.
|
||||
*/
|
||||
public fun DoubleArray.dropLast(n: Int): List<Double> {
|
||||
require(n >= 0, { "Requested element count $n is less than zero." })
|
||||
require(n >= 0) { "Requested element count $n is less than zero." }
|
||||
return take((size - n).coerceAtLeast(0))
|
||||
}
|
||||
|
||||
@@ -2717,7 +2717,7 @@ public fun DoubleArray.dropLast(n: Int): List<Double> {
|
||||
* Returns a list containing all elements except last [n] elements.
|
||||
*/
|
||||
public fun BooleanArray.dropLast(n: Int): List<Boolean> {
|
||||
require(n >= 0, { "Requested element count $n is less than zero." })
|
||||
require(n >= 0) { "Requested element count $n is less than zero." }
|
||||
return take((size - n).coerceAtLeast(0))
|
||||
}
|
||||
|
||||
@@ -2725,7 +2725,7 @@ public fun BooleanArray.dropLast(n: Int): List<Boolean> {
|
||||
* Returns a list containing all elements except last [n] elements.
|
||||
*/
|
||||
public fun CharArray.dropLast(n: Int): List<Char> {
|
||||
require(n >= 0, { "Requested element count $n is less than zero." })
|
||||
require(n >= 0) { "Requested element count $n is less than zero." }
|
||||
return take((size - n).coerceAtLeast(0))
|
||||
}
|
||||
|
||||
@@ -3981,7 +3981,7 @@ public fun CharArray.take(n: Int): List<Char> {
|
||||
* Returns a list containing last [n] elements.
|
||||
*/
|
||||
public fun <T> Array<out T>.takeLast(n: Int): List<T> {
|
||||
require(n >= 0, { "Requested element count $n is less than zero." })
|
||||
require(n >= 0) { "Requested element count $n is less than zero." }
|
||||
if (n == 0) return emptyList()
|
||||
val size = size
|
||||
if (n >= size) return toList()
|
||||
@@ -3995,7 +3995,7 @@ public fun <T> Array<out T>.takeLast(n: Int): List<T> {
|
||||
* Returns a list containing last [n] elements.
|
||||
*/
|
||||
public fun ByteArray.takeLast(n: Int): List<Byte> {
|
||||
require(n >= 0, { "Requested element count $n is less than zero." })
|
||||
require(n >= 0) { "Requested element count $n is less than zero." }
|
||||
if (n == 0) return emptyList()
|
||||
val size = size
|
||||
if (n >= size) return toList()
|
||||
@@ -4009,7 +4009,7 @@ public fun ByteArray.takeLast(n: Int): List<Byte> {
|
||||
* Returns a list containing last [n] elements.
|
||||
*/
|
||||
public fun ShortArray.takeLast(n: Int): List<Short> {
|
||||
require(n >= 0, { "Requested element count $n is less than zero." })
|
||||
require(n >= 0) { "Requested element count $n is less than zero." }
|
||||
if (n == 0) return emptyList()
|
||||
val size = size
|
||||
if (n >= size) return toList()
|
||||
@@ -4023,7 +4023,7 @@ public fun ShortArray.takeLast(n: Int): List<Short> {
|
||||
* Returns a list containing last [n] elements.
|
||||
*/
|
||||
public fun IntArray.takeLast(n: Int): List<Int> {
|
||||
require(n >= 0, { "Requested element count $n is less than zero." })
|
||||
require(n >= 0) { "Requested element count $n is less than zero." }
|
||||
if (n == 0) return emptyList()
|
||||
val size = size
|
||||
if (n >= size) return toList()
|
||||
@@ -4037,7 +4037,7 @@ public fun IntArray.takeLast(n: Int): List<Int> {
|
||||
* Returns a list containing last [n] elements.
|
||||
*/
|
||||
public fun LongArray.takeLast(n: Int): List<Long> {
|
||||
require(n >= 0, { "Requested element count $n is less than zero." })
|
||||
require(n >= 0) { "Requested element count $n is less than zero." }
|
||||
if (n == 0) return emptyList()
|
||||
val size = size
|
||||
if (n >= size) return toList()
|
||||
@@ -4051,7 +4051,7 @@ public fun LongArray.takeLast(n: Int): List<Long> {
|
||||
* Returns a list containing last [n] elements.
|
||||
*/
|
||||
public fun FloatArray.takeLast(n: Int): List<Float> {
|
||||
require(n >= 0, { "Requested element count $n is less than zero." })
|
||||
require(n >= 0) { "Requested element count $n is less than zero." }
|
||||
if (n == 0) return emptyList()
|
||||
val size = size
|
||||
if (n >= size) return toList()
|
||||
@@ -4065,7 +4065,7 @@ public fun FloatArray.takeLast(n: Int): List<Float> {
|
||||
* Returns a list containing last [n] elements.
|
||||
*/
|
||||
public fun DoubleArray.takeLast(n: Int): List<Double> {
|
||||
require(n >= 0, { "Requested element count $n is less than zero." })
|
||||
require(n >= 0) { "Requested element count $n is less than zero." }
|
||||
if (n == 0) return emptyList()
|
||||
val size = size
|
||||
if (n >= size) return toList()
|
||||
@@ -4079,7 +4079,7 @@ public fun DoubleArray.takeLast(n: Int): List<Double> {
|
||||
* Returns a list containing last [n] elements.
|
||||
*/
|
||||
public fun BooleanArray.takeLast(n: Int): List<Boolean> {
|
||||
require(n >= 0, { "Requested element count $n is less than zero." })
|
||||
require(n >= 0) { "Requested element count $n is less than zero." }
|
||||
if (n == 0) return emptyList()
|
||||
val size = size
|
||||
if (n >= size) return toList()
|
||||
@@ -4093,7 +4093,7 @@ public fun BooleanArray.takeLast(n: Int): List<Boolean> {
|
||||
* Returns a list containing last [n] elements.
|
||||
*/
|
||||
public fun CharArray.takeLast(n: Int): List<Char> {
|
||||
require(n >= 0, { "Requested element count $n is less than zero." })
|
||||
require(n >= 0) { "Requested element count $n is less than zero." }
|
||||
if (n == 0) return emptyList()
|
||||
val size = size
|
||||
if (n >= size) return toList()
|
||||
@@ -10351,7 +10351,7 @@ public inline fun CharArray.reduceIndexed(operation: (Int, Char, Char) -> Char):
|
||||
*/
|
||||
public inline fun <S, T: S> Array<out T>.reduceRight(operation: (T, S) -> S): S {
|
||||
var index = lastIndex
|
||||
if (index < 0) throw UnsupportedOperationException("Empty iterable can't be reduced.")
|
||||
if (index < 0) throw UnsupportedOperationException("Empty array can't be reduced.")
|
||||
var accumulator: S = get(index--)
|
||||
while (index >= 0) {
|
||||
accumulator = operation(get(index--), accumulator)
|
||||
@@ -10364,7 +10364,7 @@ public inline fun <S, T: S> Array<out T>.reduceRight(operation: (T, S) -> S): S
|
||||
*/
|
||||
public inline fun ByteArray.reduceRight(operation: (Byte, Byte) -> Byte): Byte {
|
||||
var index = lastIndex
|
||||
if (index < 0) throw UnsupportedOperationException("Empty iterable can't be reduced.")
|
||||
if (index < 0) throw UnsupportedOperationException("Empty array can't be reduced.")
|
||||
var accumulator = get(index--)
|
||||
while (index >= 0) {
|
||||
accumulator = operation(get(index--), accumulator)
|
||||
@@ -10377,7 +10377,7 @@ public inline fun ByteArray.reduceRight(operation: (Byte, Byte) -> Byte): Byte {
|
||||
*/
|
||||
public inline fun ShortArray.reduceRight(operation: (Short, Short) -> Short): Short {
|
||||
var index = lastIndex
|
||||
if (index < 0) throw UnsupportedOperationException("Empty iterable can't be reduced.")
|
||||
if (index < 0) throw UnsupportedOperationException("Empty array can't be reduced.")
|
||||
var accumulator = get(index--)
|
||||
while (index >= 0) {
|
||||
accumulator = operation(get(index--), accumulator)
|
||||
@@ -10390,7 +10390,7 @@ public inline fun ShortArray.reduceRight(operation: (Short, Short) -> Short): Sh
|
||||
*/
|
||||
public inline fun IntArray.reduceRight(operation: (Int, Int) -> Int): Int {
|
||||
var index = lastIndex
|
||||
if (index < 0) throw UnsupportedOperationException("Empty iterable can't be reduced.")
|
||||
if (index < 0) throw UnsupportedOperationException("Empty array can't be reduced.")
|
||||
var accumulator = get(index--)
|
||||
while (index >= 0) {
|
||||
accumulator = operation(get(index--), accumulator)
|
||||
@@ -10403,7 +10403,7 @@ public inline fun IntArray.reduceRight(operation: (Int, Int) -> Int): Int {
|
||||
*/
|
||||
public inline fun LongArray.reduceRight(operation: (Long, Long) -> Long): Long {
|
||||
var index = lastIndex
|
||||
if (index < 0) throw UnsupportedOperationException("Empty iterable can't be reduced.")
|
||||
if (index < 0) throw UnsupportedOperationException("Empty array can't be reduced.")
|
||||
var accumulator = get(index--)
|
||||
while (index >= 0) {
|
||||
accumulator = operation(get(index--), accumulator)
|
||||
@@ -10416,7 +10416,7 @@ public inline fun LongArray.reduceRight(operation: (Long, Long) -> Long): Long {
|
||||
*/
|
||||
public inline fun FloatArray.reduceRight(operation: (Float, Float) -> Float): Float {
|
||||
var index = lastIndex
|
||||
if (index < 0) throw UnsupportedOperationException("Empty iterable can't be reduced.")
|
||||
if (index < 0) throw UnsupportedOperationException("Empty array can't be reduced.")
|
||||
var accumulator = get(index--)
|
||||
while (index >= 0) {
|
||||
accumulator = operation(get(index--), accumulator)
|
||||
@@ -10429,7 +10429,7 @@ public inline fun FloatArray.reduceRight(operation: (Float, Float) -> Float): Fl
|
||||
*/
|
||||
public inline fun DoubleArray.reduceRight(operation: (Double, Double) -> Double): Double {
|
||||
var index = lastIndex
|
||||
if (index < 0) throw UnsupportedOperationException("Empty iterable can't be reduced.")
|
||||
if (index < 0) throw UnsupportedOperationException("Empty array can't be reduced.")
|
||||
var accumulator = get(index--)
|
||||
while (index >= 0) {
|
||||
accumulator = operation(get(index--), accumulator)
|
||||
@@ -10442,7 +10442,7 @@ public inline fun DoubleArray.reduceRight(operation: (Double, Double) -> Double)
|
||||
*/
|
||||
public inline fun BooleanArray.reduceRight(operation: (Boolean, Boolean) -> Boolean): Boolean {
|
||||
var index = lastIndex
|
||||
if (index < 0) throw UnsupportedOperationException("Empty iterable can't be reduced.")
|
||||
if (index < 0) throw UnsupportedOperationException("Empty array can't be reduced.")
|
||||
var accumulator = get(index--)
|
||||
while (index >= 0) {
|
||||
accumulator = operation(get(index--), accumulator)
|
||||
@@ -10455,7 +10455,7 @@ public inline fun BooleanArray.reduceRight(operation: (Boolean, Boolean) -> Bool
|
||||
*/
|
||||
public inline fun CharArray.reduceRight(operation: (Char, Char) -> Char): Char {
|
||||
var index = lastIndex
|
||||
if (index < 0) throw UnsupportedOperationException("Empty iterable can't be reduced.")
|
||||
if (index < 0) throw UnsupportedOperationException("Empty array can't be reduced.")
|
||||
var accumulator = get(index--)
|
||||
while (index >= 0) {
|
||||
accumulator = operation(get(index--), accumulator)
|
||||
|
||||
@@ -161,12 +161,7 @@ public inline fun <T> List<T>.findLast(predicate: (T) -> Boolean): T? {
|
||||
*/
|
||||
public fun <T> Iterable<T>.first(): T {
|
||||
when (this) {
|
||||
is List -> {
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Collection is empty.")
|
||||
else
|
||||
return this[0]
|
||||
}
|
||||
is List -> return this.first()
|
||||
else -> {
|
||||
val iterator = iterator()
|
||||
if (!iterator.hasNext())
|
||||
@@ -182,7 +177,7 @@ public fun <T> Iterable<T>.first(): T {
|
||||
*/
|
||||
public fun <T> List<T>.first(): T {
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Collection is empty.")
|
||||
throw NoSuchElementException("List is empty.")
|
||||
return this[0]
|
||||
}
|
||||
|
||||
@@ -192,7 +187,7 @@ public fun <T> List<T>.first(): T {
|
||||
*/
|
||||
public inline fun <T> Iterable<T>.first(predicate: (T) -> Boolean): T {
|
||||
for (element in this) if (predicate(element)) return element
|
||||
throw NoSuchElementException("No element matching predicate was found.")
|
||||
throw NoSuchElementException("Collection contains no element matching the predicate.")
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -323,12 +318,7 @@ public inline fun <T> List<T>.indexOfLast(predicate: (T) -> Boolean): Int {
|
||||
*/
|
||||
public fun <T> Iterable<T>.last(): T {
|
||||
when (this) {
|
||||
is List -> {
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Collection is empty.")
|
||||
else
|
||||
return this[this.lastIndex]
|
||||
}
|
||||
is List -> return this.last()
|
||||
else -> {
|
||||
val iterator = iterator()
|
||||
if (!iterator.hasNext())
|
||||
@@ -347,7 +337,7 @@ public fun <T> Iterable<T>.last(): T {
|
||||
*/
|
||||
public fun <T> List<T>.last(): T {
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Collection is empty.")
|
||||
throw NoSuchElementException("List is empty.")
|
||||
return this[lastIndex]
|
||||
}
|
||||
|
||||
@@ -366,7 +356,7 @@ public inline fun <T> Iterable<T>.last(predicate: (T) -> Boolean): T {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if (!found) throw NoSuchElementException("Collection doesn't contain any element matching the predicate.")
|
||||
if (!found) throw NoSuchElementException("Collection contains no element matching the predicate.")
|
||||
return last as T
|
||||
}
|
||||
|
||||
@@ -379,7 +369,7 @@ public inline fun <T> List<T>.last(predicate: (T) -> Boolean): T {
|
||||
val element = this[index]
|
||||
if (predicate(element)) return element
|
||||
}
|
||||
throw NoSuchElementException("Collection doesn't contain any element matching the predicate.")
|
||||
throw NoSuchElementException("List contains no element matching the predicate.")
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -460,11 +450,7 @@ public inline fun <T> List<T>.lastOrNull(predicate: (T) -> Boolean): T? {
|
||||
*/
|
||||
public fun <T> Iterable<T>.single(): T {
|
||||
when (this) {
|
||||
is List -> return when (size) {
|
||||
0 -> throw NoSuchElementException("Collection is empty.")
|
||||
1 -> this[0]
|
||||
else -> throw IllegalArgumentException("Collection has more than one element.")
|
||||
}
|
||||
is List -> return this.single()
|
||||
else -> {
|
||||
val iterator = iterator()
|
||||
if (!iterator.hasNext())
|
||||
@@ -482,9 +468,9 @@ public fun <T> Iterable<T>.single(): T {
|
||||
*/
|
||||
public fun <T> List<T>.single(): T {
|
||||
return when (size) {
|
||||
0 -> throw NoSuchElementException("Collection is empty.")
|
||||
0 -> throw NoSuchElementException("List is empty.")
|
||||
1 -> this[0]
|
||||
else -> throw IllegalArgumentException("Collection has more than one element.")
|
||||
else -> throw IllegalArgumentException("List has more than one element.")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -501,7 +487,7 @@ public inline fun <T> Iterable<T>.single(predicate: (T) -> Boolean): T {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if (!found) throw NoSuchElementException("Collection doesn't contain any element matching predicate.")
|
||||
if (!found) throw NoSuchElementException("Collection contains no element matching the predicate.")
|
||||
return single as T
|
||||
}
|
||||
|
||||
@@ -551,7 +537,7 @@ public inline fun <T> Iterable<T>.singleOrNull(predicate: (T) -> Boolean): T? {
|
||||
* Returns a list containing all elements except first [n] elements.
|
||||
*/
|
||||
public fun <T> Iterable<T>.drop(n: Int): List<T> {
|
||||
require(n >= 0, { "Requested element count $n is less than zero." })
|
||||
require(n >= 0) { "Requested element count $n is less than zero." }
|
||||
if (n == 0) return toList()
|
||||
val list: ArrayList<T>
|
||||
if (this is Collection<*>) {
|
||||
@@ -580,7 +566,7 @@ public fun <T> Iterable<T>.drop(n: Int): List<T> {
|
||||
* Returns a list containing all elements except last [n] elements.
|
||||
*/
|
||||
public fun <T> List<T>.dropLast(n: Int): List<T> {
|
||||
require(n >= 0, { "Requested element count $n is less than zero." })
|
||||
require(n >= 0) { "Requested element count $n is less than zero." }
|
||||
return take((size - n).coerceAtLeast(0))
|
||||
}
|
||||
|
||||
@@ -703,7 +689,7 @@ public fun <T> List<T>.slice(indices: Iterable<Int>): List<T> {
|
||||
* Returns a list containing first [n] elements.
|
||||
*/
|
||||
public fun <T> Iterable<T>.take(n: Int): List<T> {
|
||||
require(n >= 0, { "Requested element count $n is less than zero." })
|
||||
require(n >= 0) { "Requested element count $n is less than zero." }
|
||||
if (n == 0) return emptyList()
|
||||
if (this is Collection<T> && n >= size) return toList()
|
||||
var count = 0
|
||||
@@ -720,7 +706,7 @@ public fun <T> Iterable<T>.take(n: Int): List<T> {
|
||||
* Returns a list containing last [n] elements.
|
||||
*/
|
||||
public fun <T> List<T>.takeLast(n: Int): List<T> {
|
||||
require(n >= 0, { "Requested element count $n is less than zero." })
|
||||
require(n >= 0) { "Requested element count $n is less than zero." }
|
||||
if (n == 0) return emptyList()
|
||||
val size = size
|
||||
if (n >= size) return toList()
|
||||
@@ -1509,7 +1495,7 @@ public inline fun <T> Iterable<T>.none(predicate: (T) -> Boolean): Boolean {
|
||||
*/
|
||||
public inline fun <S, T: S> Iterable<T>.reduce(operation: (S, T) -> S): S {
|
||||
val iterator = this.iterator()
|
||||
if (!iterator.hasNext()) throw UnsupportedOperationException("Empty iterable can't be reduced.")
|
||||
if (!iterator.hasNext()) throw UnsupportedOperationException("Empty collection can't be reduced.")
|
||||
var accumulator: S = iterator.next()
|
||||
while (iterator.hasNext()) {
|
||||
accumulator = operation(accumulator, iterator.next())
|
||||
@@ -1525,7 +1511,7 @@ public inline fun <S, T: S> Iterable<T>.reduce(operation: (S, T) -> S): S {
|
||||
*/
|
||||
public inline fun <S, T: S> Iterable<T>.reduceIndexed(operation: (Int, S, T) -> S): S {
|
||||
val iterator = this.iterator()
|
||||
if (!iterator.hasNext()) throw UnsupportedOperationException("Empty iterable can't be reduced.")
|
||||
if (!iterator.hasNext()) throw UnsupportedOperationException("Empty collection can't be reduced.")
|
||||
var index = 1
|
||||
var accumulator: S = iterator.next()
|
||||
while (iterator.hasNext()) {
|
||||
@@ -1539,7 +1525,7 @@ public inline fun <S, T: S> Iterable<T>.reduceIndexed(operation: (Int, S, T) ->
|
||||
*/
|
||||
public inline fun <S, T: S> List<T>.reduceRight(operation: (T, S) -> S): S {
|
||||
var index = lastIndex
|
||||
if (index < 0) throw UnsupportedOperationException("Empty iterable can't be reduced.")
|
||||
if (index < 0) throw UnsupportedOperationException("Empty list can't be reduced.")
|
||||
var accumulator: S = get(index--)
|
||||
while (index >= 0) {
|
||||
accumulator = operation(get(index--), accumulator)
|
||||
|
||||
@@ -92,7 +92,7 @@ public fun <T> Sequence<T>.first(): T {
|
||||
*/
|
||||
public inline fun <T> Sequence<T>.first(predicate: (T) -> Boolean): T {
|
||||
for (element in this) if (predicate(element)) return element
|
||||
throw NoSuchElementException("No element matching predicate was found.")
|
||||
throw NoSuchElementException("Sequence contains no element matching the predicate.")
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -180,7 +180,7 @@ public inline fun <T> Sequence<T>.last(predicate: (T) -> Boolean): T {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if (!found) throw NoSuchElementException("Collection doesn't contain any element matching the predicate.")
|
||||
if (!found) throw NoSuchElementException("Sequence contains no element matching the predicate.")
|
||||
return last as T
|
||||
}
|
||||
|
||||
@@ -245,12 +245,12 @@ public inline fun <T> Sequence<T>.single(predicate: (T) -> Boolean): T {
|
||||
var found = false
|
||||
for (element in this) {
|
||||
if (predicate(element)) {
|
||||
if (found) throw IllegalArgumentException("Collection contains more than one matching element.")
|
||||
if (found) throw IllegalArgumentException("Sequence contains more than one matching element.")
|
||||
single = element
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if (!found) throw NoSuchElementException("Collection doesn't contain any element matching predicate.")
|
||||
if (!found) throw NoSuchElementException("Sequence contains no element matching the predicate.")
|
||||
return single as T
|
||||
}
|
||||
|
||||
@@ -288,7 +288,7 @@ public inline fun <T> Sequence<T>.singleOrNull(predicate: (T) -> Boolean): T? {
|
||||
* Returns a sequence containing all elements except first [n] elements.
|
||||
*/
|
||||
public fun <T> Sequence<T>.drop(n: Int): Sequence<T> {
|
||||
require(n >= 0, { "Requested element count $n is less than zero." })
|
||||
require(n >= 0) { "Requested element count $n is less than zero." }
|
||||
return when {
|
||||
n == 0 -> this
|
||||
this is DropTakeSequence -> this.drop(n)
|
||||
@@ -375,7 +375,7 @@ public inline fun <T, C : MutableCollection<in T>> Sequence<T>.filterTo(destinat
|
||||
* Returns a sequence containing first [n] elements.
|
||||
*/
|
||||
public fun <T> Sequence<T>.take(n: Int): Sequence<T> {
|
||||
require(n >= 0, { "Requested element count $n is less than zero." })
|
||||
require(n >= 0) { "Requested element count $n is less than zero." }
|
||||
return when {
|
||||
n == 0 -> emptySequence()
|
||||
this is DropTakeSequence -> this.take(n)
|
||||
@@ -931,7 +931,7 @@ public inline fun <T> Sequence<T>.none(predicate: (T) -> Boolean): Boolean {
|
||||
*/
|
||||
public inline fun <S, T: S> Sequence<T>.reduce(operation: (S, T) -> S): S {
|
||||
val iterator = this.iterator()
|
||||
if (!iterator.hasNext()) throw UnsupportedOperationException("Empty iterable can't be reduced.")
|
||||
if (!iterator.hasNext()) throw UnsupportedOperationException("Empty sequence can't be reduced.")
|
||||
var accumulator: S = iterator.next()
|
||||
while (iterator.hasNext()) {
|
||||
accumulator = operation(accumulator, iterator.next())
|
||||
@@ -947,7 +947,7 @@ public inline fun <S, T: S> Sequence<T>.reduce(operation: (S, T) -> S): S {
|
||||
*/
|
||||
public inline fun <S, T: S> Sequence<T>.reduceIndexed(operation: (Int, S, T) -> S): S {
|
||||
val iterator = this.iterator()
|
||||
if (!iterator.hasNext()) throw UnsupportedOperationException("Empty iterable can't be reduced.")
|
||||
if (!iterator.hasNext()) throw UnsupportedOperationException("Empty sequence can't be reduced.")
|
||||
var index = 1
|
||||
var accumulator: S = iterator.next()
|
||||
while (iterator.hasNext()) {
|
||||
|
||||
@@ -59,7 +59,7 @@ public inline fun CharSequence.findLast(predicate: (Char) -> Boolean): Char? {
|
||||
*/
|
||||
public fun CharSequence.first(): Char {
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Collection is empty.")
|
||||
throw NoSuchElementException("Char sequence is empty.")
|
||||
return this[0]
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ public fun CharSequence.first(): Char {
|
||||
*/
|
||||
public inline fun CharSequence.first(predicate: (Char) -> Boolean): Char {
|
||||
for (element in this) if (predicate(element)) return element
|
||||
throw NoSuchElementException("No element matching predicate was found.")
|
||||
throw NoSuchElementException("Char sequence contains no character matching the predicate.")
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -132,7 +132,7 @@ public inline fun CharSequence.indexOfLast(predicate: (Char) -> Boolean): Int {
|
||||
*/
|
||||
public fun CharSequence.last(): Char {
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("Collection is empty.")
|
||||
throw NoSuchElementException("Char sequence is empty.")
|
||||
return this[lastIndex]
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ public inline fun CharSequence.last(predicate: (Char) -> Boolean): Char {
|
||||
val element = this[index]
|
||||
if (predicate(element)) return element
|
||||
}
|
||||
throw NoSuchElementException("Collection doesn't contain any element matching the predicate.")
|
||||
throw NoSuchElementException("Char sequence contains no character matching the predicate.")
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -171,9 +171,9 @@ public inline fun CharSequence.lastOrNull(predicate: (Char) -> Boolean): Char? {
|
||||
*/
|
||||
public fun CharSequence.single(): Char {
|
||||
return when (length) {
|
||||
0 -> throw NoSuchElementException("Collection is empty.")
|
||||
0 -> throw NoSuchElementException("Char sequence is empty.")
|
||||
1 -> this[0]
|
||||
else -> throw IllegalArgumentException("Collection has more than one element.")
|
||||
else -> throw IllegalArgumentException("Char sequence has more than one element.")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,12 +185,12 @@ public inline fun CharSequence.single(predicate: (Char) -> Boolean): Char {
|
||||
var found = false
|
||||
for (element in this) {
|
||||
if (predicate(element)) {
|
||||
if (found) throw IllegalArgumentException("Collection contains more than one matching element.")
|
||||
if (found) throw IllegalArgumentException("Char sequence contains more than one matching element.")
|
||||
single = element
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if (!found) throw NoSuchElementException("Collection doesn't contain any element matching predicate.")
|
||||
if (!found) throw NoSuchElementException("Char sequence contains no character matching the predicate.")
|
||||
return single as Char
|
||||
}
|
||||
|
||||
@@ -222,7 +222,7 @@ public inline fun CharSequence.singleOrNull(predicate: (Char) -> Boolean): Char?
|
||||
* Returns a subsequence of this char sequence with the first [n] characters removed.
|
||||
*/
|
||||
public fun CharSequence.drop(n: Int): CharSequence {
|
||||
require(n >= 0, { "Requested character count $n is less than zero." })
|
||||
require(n >= 0) { "Requested character count $n is less than zero." }
|
||||
return subSequence(n.coerceAtMost(length), length)
|
||||
}
|
||||
|
||||
@@ -230,7 +230,7 @@ public fun CharSequence.drop(n: Int): CharSequence {
|
||||
* Returns a string with the first [n] characters removed.
|
||||
*/
|
||||
public fun String.drop(n: Int): String {
|
||||
require(n >= 0, { "Requested character count $n is less than zero." })
|
||||
require(n >= 0) { "Requested character count $n is less than zero." }
|
||||
return substring(n.coerceAtMost(length))
|
||||
}
|
||||
|
||||
@@ -238,7 +238,7 @@ public fun String.drop(n: Int): String {
|
||||
* Returns a subsequence of this char sequence with the last [n] characters removed.
|
||||
*/
|
||||
public fun CharSequence.dropLast(n: Int): CharSequence {
|
||||
require(n >= 0, { "Requested character count $n is less than zero." })
|
||||
require(n >= 0) { "Requested character count $n is less than zero." }
|
||||
return take((length - n).coerceAtLeast(0))
|
||||
}
|
||||
|
||||
@@ -246,7 +246,7 @@ public fun CharSequence.dropLast(n: Int): CharSequence {
|
||||
* Returns a string with the last [n] characters removed.
|
||||
*/
|
||||
public fun String.dropLast(n: Int): String {
|
||||
require(n >= 0, { "Requested character count $n is less than zero." })
|
||||
require(n >= 0) { "Requested character count $n is less than zero." }
|
||||
return take((length - n).coerceAtLeast(0))
|
||||
}
|
||||
|
||||
@@ -408,7 +408,7 @@ public inline fun String.slice(indices: Iterable<Int>): String {
|
||||
* Returns a subsequence of this char sequence containing the first [n] characters from this char sequence, or the entire char sequence if this char sequence is shorter.
|
||||
*/
|
||||
public fun CharSequence.take(n: Int): CharSequence {
|
||||
require(n >= 0, { "Requested character count $n is less than zero." })
|
||||
require(n >= 0) { "Requested character count $n is less than zero." }
|
||||
return subSequence(0, n.coerceAtMost(length))
|
||||
}
|
||||
|
||||
@@ -416,7 +416,7 @@ public fun CharSequence.take(n: Int): CharSequence {
|
||||
* Returns a string containing the first [n] characters from this string, or the entire string if this string is shorter.
|
||||
*/
|
||||
public fun String.take(n: Int): String {
|
||||
require(n >= 0, { "Requested character count $n is less than zero." })
|
||||
require(n >= 0) { "Requested character count $n is less than zero." }
|
||||
return substring(0, n.coerceAtMost(length))
|
||||
}
|
||||
|
||||
@@ -424,7 +424,7 @@ public fun String.take(n: Int): String {
|
||||
* Returns a subsequence of this char sequence containing the last [n] characters from this char sequence, or the entire char sequence if this char sequence is shorter.
|
||||
*/
|
||||
public fun CharSequence.takeLast(n: Int): CharSequence {
|
||||
require(n >= 0, { "Requested character count $n is less than zero." })
|
||||
require(n >= 0) { "Requested character count $n is less than zero." }
|
||||
val length = length
|
||||
return subSequence(length - n.coerceAtMost(length), length)
|
||||
}
|
||||
@@ -433,7 +433,7 @@ public fun CharSequence.takeLast(n: Int): CharSequence {
|
||||
* Returns a string containing the last [n] characters from this string, or the entire string if this string is shorter.
|
||||
*/
|
||||
public fun String.takeLast(n: Int): String {
|
||||
require(n >= 0, { "Requested character count $n is less than zero." })
|
||||
require(n >= 0) { "Requested character count $n is less than zero." }
|
||||
val length = length
|
||||
return substring(length - n.coerceAtMost(length))
|
||||
}
|
||||
@@ -1014,7 +1014,7 @@ public inline fun CharSequence.reduceIndexed(operation: (Int, Char, Char) -> Cha
|
||||
*/
|
||||
public inline fun CharSequence.reduceRight(operation: (Char, Char) -> Char): Char {
|
||||
var index = lastIndex
|
||||
if (index < 0) throw UnsupportedOperationException("Empty iterable can't be reduced.")
|
||||
if (index < 0) throw UnsupportedOperationException("Empty char sequence can't be reduced.")
|
||||
var accumulator = get(index--)
|
||||
while (index >= 0) {
|
||||
accumulator = operation(get(index--), accumulator)
|
||||
|
||||
@@ -26,7 +26,7 @@ internal object EmptyList : List<Nothing>, Serializable {
|
||||
override fun contains(element: Nothing): Boolean = false
|
||||
override fun containsAll(elements: Collection<Nothing>): Boolean = elements.isEmpty()
|
||||
|
||||
override fun get(index: Int): Nothing = throw IndexOutOfBoundsException("Index $index is out of bound of empty list.")
|
||||
override fun get(index: Int): Nothing = throw IndexOutOfBoundsException("Empty list doesn't contain element at index $index.")
|
||||
override fun indexOf(element: Nothing): Int = -1
|
||||
override fun lastIndexOf(element: Nothing): Int = -1
|
||||
|
||||
@@ -274,7 +274,7 @@ public fun <T> List<T>.binarySearch(fromIndex: Int = 0, toIndex: Int = size, com
|
||||
*/
|
||||
private fun rangeCheck(size: Int, fromIndex: Int, toIndex: Int) {
|
||||
when {
|
||||
fromIndex > toIndex -> throw IllegalArgumentException("fromIndex ($fromIndex) is greater than toIndex ($toIndex)")
|
||||
fromIndex > toIndex -> throw IllegalArgumentException("fromIndex ($fromIndex) is greater than toIndex ($toIndex).")
|
||||
fromIndex < 0 -> throw IndexOutOfBoundsException("fromIndex ($fromIndex) is less than zero.")
|
||||
toIndex > size -> throw IndexOutOfBoundsException("toIndex ($toIndex) is greater than size ($size).")
|
||||
}
|
||||
|
||||
@@ -24,8 +24,8 @@ private open class ReversedListReadOnly<T>(protected open val delegate: List<T>)
|
||||
override val size: Int get() = delegate.size
|
||||
override fun get(index: Int): T = delegate[index.flipIndex()]
|
||||
|
||||
protected fun Int.flipIndex(): Int = if (this in 0..size - 1) size - this - 1 else throw IndexOutOfBoundsException("index $this should be in range [${0..size - 1}]")
|
||||
protected fun Int.flipIndexForward(): Int = if (this in 0..size) size - this else throw IndexOutOfBoundsException("index $this should be in range [${0..size}]")
|
||||
protected fun Int.flipIndex(): Int = if (this in 0..size - 1) size - this - 1 else throw IndexOutOfBoundsException("index $this should be in range [${0..size - 1}].")
|
||||
protected fun Int.flipIndexForward(): Int = if (this in 0..size) size - this else throw IndexOutOfBoundsException("index $this should be in range [${0..size}].")
|
||||
}
|
||||
|
||||
private class ReversedList<T>(protected override val delegate: MutableList<T>) : ReversedListReadOnly<T>(delegate) {
|
||||
|
||||
@@ -316,7 +316,7 @@ internal class TakeSequence<T> (
|
||||
) : Sequence<T>, DropTakeSequence<T> {
|
||||
|
||||
init {
|
||||
require (count >= 0) { throw IllegalArgumentException("count should be non-negative, but is $count") }
|
||||
require (count >= 0) { throw IllegalArgumentException("count must be non-negative, but was $count.") }
|
||||
}
|
||||
|
||||
override fun drop(n: Int): Sequence<T> = if (n >= count) emptySequence() else SubSequence(sequence, n, count)
|
||||
@@ -394,7 +394,7 @@ internal class DropSequence<T> (
|
||||
private val count: Int
|
||||
) : Sequence<T>, DropTakeSequence<T> {
|
||||
init {
|
||||
require (count >= 0) { throw IllegalArgumentException("count should be non-negative, but is $count") }
|
||||
require (count >= 0) { throw IllegalArgumentException("count must be non-negative, but was $count.") }
|
||||
}
|
||||
|
||||
override fun drop(n: Int): Sequence<T> = DropSequence(sequence, count + n)
|
||||
|
||||
@@ -32,7 +32,7 @@ public operator fun BufferedInputStream.iterator(): ByteIterator =
|
||||
public override fun nextByte(): Byte {
|
||||
prepareNext()
|
||||
if (finished)
|
||||
throw NoSuchElementException("Input stream is over")
|
||||
throw NoSuchElementException("Input stream is over.")
|
||||
val res = nextByte.toByte()
|
||||
nextPrepared = false
|
||||
return res
|
||||
|
||||
@@ -252,7 +252,7 @@ public class FileTreeWalk private constructor(
|
||||
*/
|
||||
public fun maxDepth(depth: Int): FileTreeWalk {
|
||||
if (depth <= 0)
|
||||
throw IllegalArgumentException("Use positive depth value")
|
||||
throw IllegalArgumentException("depth must be positive, but was $depth.")
|
||||
return FileTreeWalk(start, direction, onEnter, onLeave, onFail, depth)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ public fun createTempDir(prefix: String = "tmp", suffix: String? = null, directo
|
||||
if (dir.mkdir()) {
|
||||
return dir
|
||||
} else {
|
||||
throw IOException("Unable to create temporary directory $dir")
|
||||
throw IOException("Unable to create temporary directory $dir.")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ public val File.nameWithoutExtension: String
|
||||
* @throws IllegalArgumentException if this and base paths have different roots.
|
||||
*/
|
||||
public fun File.toRelativeString(base: File): String
|
||||
= toRelativeStringOrNull(base) ?: throw IllegalArgumentException("this and base files have different roots: $this and $base")
|
||||
= toRelativeStringOrNull(base) ?: throw IllegalArgumentException("this and base files have different roots: $this and $base.")
|
||||
|
||||
/**
|
||||
* Calculates the relative path for this file from [base] file.
|
||||
@@ -173,7 +173,7 @@ private fun File.toRelativeStringOrNull(base: File): String? {
|
||||
*/
|
||||
public fun File.copyTo(target: File, overwrite: Boolean = false, bufferSize: Int = DEFAULT_BUFFER_SIZE): File {
|
||||
if (!this.exists()) {
|
||||
throw NoSuchFileException(file = this, reason = "The source file doesn't exist")
|
||||
throw NoSuchFileException(file = this, reason = "The source file doesn't exist.")
|
||||
}
|
||||
|
||||
if (target.exists()) {
|
||||
@@ -182,13 +182,13 @@ public fun File.copyTo(target: File, overwrite: Boolean = false, bufferSize: Int
|
||||
if (stillExists) {
|
||||
throw FileAlreadyExistsException(file = this,
|
||||
other = target,
|
||||
reason = "The destination file already exists")
|
||||
reason = "The destination file already exists.")
|
||||
}
|
||||
}
|
||||
|
||||
if (this.isDirectory) {
|
||||
if (!target.mkdirs())
|
||||
throw FileSystemException(file = this, other = target, reason = "Failed to create target directory")
|
||||
throw FileSystemException(file = this, other = target, reason = "Failed to create target directory.")
|
||||
} else {
|
||||
target.parentFile?.mkdirs()
|
||||
|
||||
@@ -242,14 +242,14 @@ public fun File.copyRecursively(target: File,
|
||||
{ file, exception -> throw exception }
|
||||
): Boolean {
|
||||
if (!exists()) {
|
||||
return onError(this, NoSuchFileException(file = this, reason = "The source file doesn't exist")) !=
|
||||
return onError(this, NoSuchFileException(file = this, reason = "The source file doesn't exist.")) !=
|
||||
OnErrorAction.TERMINATE
|
||||
}
|
||||
try {
|
||||
// We cannot break for loop from inside a lambda, so we have to use an exception here
|
||||
for (src in walkTopDown().onFail { f, e -> if (onError(f, e) == OnErrorAction.TERMINATE) throw TerminateException(f) }) {
|
||||
if (!src.exists()) {
|
||||
if (onError(src, NoSuchFileException(file = src, reason = "The source file doesn't exist")) ==
|
||||
if (onError(src, NoSuchFileException(file = src, reason = "The source file doesn't exist.")) ==
|
||||
OnErrorAction.TERMINATE)
|
||||
return false
|
||||
} else {
|
||||
@@ -266,7 +266,7 @@ public fun File.copyRecursively(target: File,
|
||||
if (stillExists) {
|
||||
if (onError(dstFile, FileAlreadyExistsException(file = src,
|
||||
other = dstFile,
|
||||
reason = "The destination file already exists")) == OnErrorAction.TERMINATE)
|
||||
reason = "The destination file already exists.")) == OnErrorAction.TERMINATE)
|
||||
return false
|
||||
|
||||
continue
|
||||
@@ -277,7 +277,7 @@ public fun File.copyRecursively(target: File,
|
||||
dstFile.mkdirs()
|
||||
} else {
|
||||
if (src.copyTo(dstFile, overwrite).length() != src.length()) {
|
||||
if (onError(src, IOException("src.length() != dst.length()")) == OnErrorAction.TERMINATE)
|
||||
if (onError(src, IOException("Source file wasn't copied completely, length of destination file differs.")) == OnErrorAction.TERMINATE)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,5 +30,5 @@ public operator fun <T: Comparable<T>> T.rangeTo(that: T): ClosedRange<T> = Comp
|
||||
|
||||
|
||||
internal fun checkStepIsPositive(isPositive: Boolean, step: Number) {
|
||||
if (!isPositive) throw IllegalArgumentException("Step must be positive, was: $step")
|
||||
if (!isPositive) throw IllegalArgumentException("Step must be positive, was: $step.")
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ public fun String.trimMargin(marginPrefix: String = "|"): String =
|
||||
* Detects indent by [marginPrefix] as it does [trimMargin] and replace it with [newIndent].
|
||||
*/
|
||||
public fun String.replaceIndentByMargin(newIndent: String = "", marginPrefix: String = "|"): String {
|
||||
require(marginPrefix.isNotBlank()) { "marginPrefix must be non blank string." }
|
||||
require(marginPrefix.isNotBlank()) { "marginPrefix must be non-blank string." }
|
||||
val lines = lines()
|
||||
|
||||
return lines.reindent(length + newIndent.length * lines.size, getIndentFunction(newIndent), { line ->
|
||||
|
||||
@@ -380,7 +380,7 @@ public fun String.substringAfterLast(delimiter: String, missingDelimiterValue: S
|
||||
*/
|
||||
public fun CharSequence.replaceRange(startIndex: Int, endIndex: Int, replacement: CharSequence): CharSequence {
|
||||
if (endIndex < startIndex)
|
||||
throw IndexOutOfBoundsException("End index ($endIndex) is less than start index ($startIndex)")
|
||||
throw IndexOutOfBoundsException("End index ($endIndex) is less than start index ($startIndex).")
|
||||
val sb = StringBuilder()
|
||||
sb.append(this, 0, startIndex)
|
||||
sb.append(replacement)
|
||||
@@ -425,7 +425,7 @@ public inline fun String.replaceRange(range: IntRange, replacement: CharSequence
|
||||
*/
|
||||
public fun CharSequence.removeRange(startIndex: Int, endIndex: Int): CharSequence {
|
||||
if (endIndex < startIndex)
|
||||
throw IndexOutOfBoundsException("End index ($endIndex) is less than start index ($startIndex)")
|
||||
throw IndexOutOfBoundsException("End index ($endIndex) is less than start index ($startIndex).")
|
||||
|
||||
if (endIndex == startIndex)
|
||||
return this.subSequence(0, length)
|
||||
@@ -1068,7 +1068,7 @@ private class DelimitedRangesSequence(private val input: CharSequence, private v
|
||||
* @param limit The maximum number of substrings to return. Zero by default means no limit is set.
|
||||
*/
|
||||
private fun CharSequence.rangesDelimitedBy(delimiters: CharArray, startIndex: Int = 0, ignoreCase: Boolean = false, limit: Int = 0): Sequence<IntRange> {
|
||||
require(limit >= 0, { "Limit must be non-negative, but was $limit" })
|
||||
require(limit >= 0, { "Limit must be non-negative, but was $limit." })
|
||||
|
||||
return DelimitedRangesSequence(this, startIndex, limit, { startIndex -> findAnyOf(delimiters, startIndex, ignoreCase = ignoreCase, last = false)?.let { it.first to 1 } })
|
||||
}
|
||||
@@ -1089,7 +1089,7 @@ private fun CharSequence.rangesDelimitedBy(delimiters: CharArray, startIndex: In
|
||||
* that matches this string at that position.
|
||||
*/
|
||||
private fun CharSequence.rangesDelimitedBy(delimiters: Array<out String>, startIndex: Int = 0, ignoreCase: Boolean = false, limit: Int = 0): Sequence<IntRange> {
|
||||
require(limit >= 0, { "Limit must be non-negative, but was $limit" } )
|
||||
require(limit >= 0, { "Limit must be non-negative, but was $limit." } )
|
||||
val delimitersList = delimiters.asList()
|
||||
|
||||
return DelimitedRangesSequence(this, startIndex, limit, { startIndex -> findAnyOf(delimitersList, startIndex, ignoreCase = ignoreCase, last = false)?.let { it.first to it.second.length } })
|
||||
|
||||
@@ -151,7 +151,7 @@ public inline fun String.Companion.format(locale: Locale, format: String, vararg
|
||||
*/
|
||||
public fun CharSequence.split(regex: Pattern, limit: Int = 0): List<String>
|
||||
{
|
||||
require(limit >= 0, { "Limit must be non-negative, but was $limit" } )
|
||||
require(limit >= 0, { "Limit must be non-negative, but was $limit." } )
|
||||
return regex.split(this, if (limit == 0) -1 else limit).asList()
|
||||
}
|
||||
|
||||
|
||||
@@ -187,7 +187,7 @@ internal constructor(private val nativePattern: Pattern) {
|
||||
* Zero by default means no limit is set.
|
||||
*/
|
||||
public fun split(input: CharSequence, limit: Int = 0): List<String> {
|
||||
require(limit >= 0, { "Limit must be non-negative, but was $limit" } )
|
||||
require(limit >= 0, { "Limit must be non-negative, but was $limit." } )
|
||||
return nativePattern.split(input, if (limit == 0) -1 else limit).asList()
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import java.lang.IllegalStateException
|
||||
* Throws an [IllegalArgumentException] if the [value] is false.
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun require(value: Boolean): Unit = require(value) { "Failed requirement" }
|
||||
public inline fun require(value: Boolean): Unit = require(value) { "Failed requirement." }
|
||||
|
||||
/**
|
||||
* Throws an [IllegalArgumentException] with the result of calling [lazyMessage] if the [value] is false.
|
||||
@@ -28,7 +28,7 @@ public inline fun require(value: Boolean, lazyMessage: () -> Any): Unit {
|
||||
* Throws an [IllegalArgumentException] if the [value] is null. Otherwise returns the not null value.
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun <T:Any> requireNotNull(value: T?): T = requireNotNull(value) { "Required value was null" }
|
||||
public inline fun <T:Any> requireNotNull(value: T?): T = requireNotNull(value) { "Required value was null." }
|
||||
|
||||
/**
|
||||
* Throws an [IllegalArgumentException] with the result of calling [lazyMessage] if the [value] is null. Otherwise
|
||||
@@ -50,7 +50,7 @@ public inline fun <T:Any> requireNotNull(value: T?, lazyMessage: () -> Any): T {
|
||||
* Throws an [IllegalStateException] if the [value] is false.
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun check(value: Boolean): Unit = check(value) { "Check failed" }
|
||||
public inline fun check(value: Boolean): Unit = check(value) { "Check failed." }
|
||||
|
||||
/**
|
||||
* Throws an [IllegalStateException] with the result of calling [lazyMessage] if the [value] is false.
|
||||
@@ -70,7 +70,7 @@ public inline fun check(value: Boolean, lazyMessage: () -> Any): Unit {
|
||||
* returns the not null value.
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun <T:Any> checkNotNull(value: T?): T = checkNotNull(value) { "Required value was null" }
|
||||
public inline fun <T:Any> checkNotNull(value: T?): T = checkNotNull(value) { "Required value was null." }
|
||||
|
||||
/**
|
||||
* Throws an [IllegalStateException] with the result of calling [lazyMessage] if the [value] is null. Otherwise
|
||||
|
||||
Reference in New Issue
Block a user