Document fromIndex and toIndex parameters #KT-38388

This commit is contained in:
Abduqodiri Qurbonzoda
2020-04-21 05:59:10 +03:00
parent 3c1b41c020
commit 0c7b04a495
9 changed files with 893 additions and 209 deletions
+117 -36
View File
@@ -1268,8 +1268,11 @@ public actual fun <T> Array<out T>.copyOf(newSize: Int): Array<T?> {
/**
* Returns a new array which is a copy of the specified range of the original array.
*
* @param fromIndex the start of the range (inclusive), must be in `0..array.size`
* @param toIndex the end of the range (exclusive), must be in `fromIndex..array.size`
* @param fromIndex the start of the range (inclusive) to copy.
* @param toIndex the end of the range (exclusive) to copy.
*
* @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array.
* @throws IllegalArgumentException if [fromIndex] is greater than [toIndex].
*/
@Suppress("ACTUAL_WITHOUT_EXPECT")
public actual fun <T> Array<out T>.copyOfRange(fromIndex: Int, toIndex: Int): Array<T> {
@@ -1280,8 +1283,11 @@ public actual fun <T> Array<out T>.copyOfRange(fromIndex: Int, toIndex: Int): Ar
/**
* Returns a new array which is a copy of the specified range of the original array.
*
* @param fromIndex the start of the range (inclusive), must be in `0..array.size`
* @param toIndex the end of the range (exclusive), must be in `fromIndex..array.size`
* @param fromIndex the start of the range (inclusive) to copy.
* @param toIndex the end of the range (exclusive) to copy.
*
* @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array.
* @throws IllegalArgumentException if [fromIndex] is greater than [toIndex].
*/
public actual fun ByteArray.copyOfRange(fromIndex: Int, toIndex: Int): ByteArray {
AbstractList.checkRangeIndexes(fromIndex, toIndex, size)
@@ -1291,8 +1297,11 @@ public actual fun ByteArray.copyOfRange(fromIndex: Int, toIndex: Int): ByteArray
/**
* Returns a new array which is a copy of the specified range of the original array.
*
* @param fromIndex the start of the range (inclusive), must be in `0..array.size`
* @param toIndex the end of the range (exclusive), must be in `fromIndex..array.size`
* @param fromIndex the start of the range (inclusive) to copy.
* @param toIndex the end of the range (exclusive) to copy.
*
* @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array.
* @throws IllegalArgumentException if [fromIndex] is greater than [toIndex].
*/
public actual fun ShortArray.copyOfRange(fromIndex: Int, toIndex: Int): ShortArray {
AbstractList.checkRangeIndexes(fromIndex, toIndex, size)
@@ -1302,8 +1311,11 @@ public actual fun ShortArray.copyOfRange(fromIndex: Int, toIndex: Int): ShortArr
/**
* Returns a new array which is a copy of the specified range of the original array.
*
* @param fromIndex the start of the range (inclusive), must be in `0..array.size`
* @param toIndex the end of the range (exclusive), must be in `fromIndex..array.size`
* @param fromIndex the start of the range (inclusive) to copy.
* @param toIndex the end of the range (exclusive) to copy.
*
* @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array.
* @throws IllegalArgumentException if [fromIndex] is greater than [toIndex].
*/
public actual fun IntArray.copyOfRange(fromIndex: Int, toIndex: Int): IntArray {
AbstractList.checkRangeIndexes(fromIndex, toIndex, size)
@@ -1313,8 +1325,11 @@ public actual fun IntArray.copyOfRange(fromIndex: Int, toIndex: Int): IntArray {
/**
* Returns a new array which is a copy of the specified range of the original array.
*
* @param fromIndex the start of the range (inclusive), must be in `0..array.size`
* @param toIndex the end of the range (exclusive), must be in `fromIndex..array.size`
* @param fromIndex the start of the range (inclusive) to copy.
* @param toIndex the end of the range (exclusive) to copy.
*
* @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array.
* @throws IllegalArgumentException if [fromIndex] is greater than [toIndex].
*/
public actual fun LongArray.copyOfRange(fromIndex: Int, toIndex: Int): LongArray {
AbstractList.checkRangeIndexes(fromIndex, toIndex, size)
@@ -1324,8 +1339,11 @@ public actual fun LongArray.copyOfRange(fromIndex: Int, toIndex: Int): LongArray
/**
* Returns a new array which is a copy of the specified range of the original array.
*
* @param fromIndex the start of the range (inclusive), must be in `0..array.size`
* @param toIndex the end of the range (exclusive), must be in `fromIndex..array.size`
* @param fromIndex the start of the range (inclusive) to copy.
* @param toIndex the end of the range (exclusive) to copy.
*
* @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array.
* @throws IllegalArgumentException if [fromIndex] is greater than [toIndex].
*/
public actual fun FloatArray.copyOfRange(fromIndex: Int, toIndex: Int): FloatArray {
AbstractList.checkRangeIndexes(fromIndex, toIndex, size)
@@ -1335,8 +1353,11 @@ public actual fun FloatArray.copyOfRange(fromIndex: Int, toIndex: Int): FloatArr
/**
* Returns a new array which is a copy of the specified range of the original array.
*
* @param fromIndex the start of the range (inclusive), must be in `0..array.size`
* @param toIndex the end of the range (exclusive), must be in `fromIndex..array.size`
* @param fromIndex the start of the range (inclusive) to copy.
* @param toIndex the end of the range (exclusive) to copy.
*
* @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array.
* @throws IllegalArgumentException if [fromIndex] is greater than [toIndex].
*/
public actual fun DoubleArray.copyOfRange(fromIndex: Int, toIndex: Int): DoubleArray {
AbstractList.checkRangeIndexes(fromIndex, toIndex, size)
@@ -1346,8 +1367,11 @@ public actual fun DoubleArray.copyOfRange(fromIndex: Int, toIndex: Int): DoubleA
/**
* Returns a new array which is a copy of the specified range of the original array.
*
* @param fromIndex the start of the range (inclusive), must be in `0..array.size`
* @param toIndex the end of the range (exclusive), must be in `fromIndex..array.size`
* @param fromIndex the start of the range (inclusive) to copy.
* @param toIndex the end of the range (exclusive) to copy.
*
* @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array.
* @throws IllegalArgumentException if [fromIndex] is greater than [toIndex].
*/
public actual fun BooleanArray.copyOfRange(fromIndex: Int, toIndex: Int): BooleanArray {
AbstractList.checkRangeIndexes(fromIndex, toIndex, size)
@@ -1357,8 +1381,11 @@ public actual fun BooleanArray.copyOfRange(fromIndex: Int, toIndex: Int): Boolea
/**
* Returns a new array which is a copy of the specified range of the original array.
*
* @param fromIndex the start of the range (inclusive), must be in `0..array.size`
* @param toIndex the end of the range (exclusive), must be in `fromIndex..array.size`
* @param fromIndex the start of the range (inclusive) to copy.
* @param toIndex the end of the range (exclusive) to copy.
*
* @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array.
* @throws IllegalArgumentException if [fromIndex] is greater than [toIndex].
*/
public actual fun CharArray.copyOfRange(fromIndex: Int, toIndex: Int): CharArray {
AbstractList.checkRangeIndexes(fromIndex, toIndex, size)
@@ -1368,8 +1395,8 @@ public actual fun CharArray.copyOfRange(fromIndex: Int, toIndex: Int): CharArray
/**
* Fills this array or its subrange with the specified [element] value.
*
* @param fromIndex the start of the range (inclusive), 0 by default.
* @param toIndex the end of the range (exclusive), size of this array by default.
* @param fromIndex the start of the range (inclusive) to fill, 0 by default.
* @param toIndex the end of the range (exclusive) to fill, size of this array by default.
*
* @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array.
* @throws IllegalArgumentException if [fromIndex] is greater than [toIndex].
@@ -1384,8 +1411,8 @@ public actual fun <T> Array<T>.fill(element: T, fromIndex: Int = 0, toIndex: Int
/**
* Fills this array or its subrange with the specified [element] value.
*
* @param fromIndex the start of the range (inclusive), 0 by default.
* @param toIndex the end of the range (exclusive), size of this array by default.
* @param fromIndex the start of the range (inclusive) to fill, 0 by default.
* @param toIndex the end of the range (exclusive) to fill, size of this array by default.
*
* @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array.
* @throws IllegalArgumentException if [fromIndex] is greater than [toIndex].
@@ -1400,8 +1427,8 @@ public actual fun ByteArray.fill(element: Byte, fromIndex: Int = 0, toIndex: Int
/**
* Fills this array or its subrange with the specified [element] value.
*
* @param fromIndex the start of the range (inclusive), 0 by default.
* @param toIndex the end of the range (exclusive), size of this array by default.
* @param fromIndex the start of the range (inclusive) to fill, 0 by default.
* @param toIndex the end of the range (exclusive) to fill, size of this array by default.
*
* @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array.
* @throws IllegalArgumentException if [fromIndex] is greater than [toIndex].
@@ -1416,8 +1443,8 @@ public actual fun ShortArray.fill(element: Short, fromIndex: Int = 0, toIndex: I
/**
* Fills this array or its subrange with the specified [element] value.
*
* @param fromIndex the start of the range (inclusive), 0 by default.
* @param toIndex the end of the range (exclusive), size of this array by default.
* @param fromIndex the start of the range (inclusive) to fill, 0 by default.
* @param toIndex the end of the range (exclusive) to fill, size of this array by default.
*
* @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array.
* @throws IllegalArgumentException if [fromIndex] is greater than [toIndex].
@@ -1432,8 +1459,8 @@ public actual fun IntArray.fill(element: Int, fromIndex: Int = 0, toIndex: Int =
/**
* Fills this array or its subrange with the specified [element] value.
*
* @param fromIndex the start of the range (inclusive), 0 by default.
* @param toIndex the end of the range (exclusive), size of this array by default.
* @param fromIndex the start of the range (inclusive) to fill, 0 by default.
* @param toIndex the end of the range (exclusive) to fill, size of this array by default.
*
* @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array.
* @throws IllegalArgumentException if [fromIndex] is greater than [toIndex].
@@ -1448,8 +1475,8 @@ public actual fun LongArray.fill(element: Long, fromIndex: Int = 0, toIndex: Int
/**
* Fills this array or its subrange with the specified [element] value.
*
* @param fromIndex the start of the range (inclusive), 0 by default.
* @param toIndex the end of the range (exclusive), size of this array by default.
* @param fromIndex the start of the range (inclusive) to fill, 0 by default.
* @param toIndex the end of the range (exclusive) to fill, size of this array by default.
*
* @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array.
* @throws IllegalArgumentException if [fromIndex] is greater than [toIndex].
@@ -1464,8 +1491,8 @@ public actual fun FloatArray.fill(element: Float, fromIndex: Int = 0, toIndex: I
/**
* Fills this array or its subrange with the specified [element] value.
*
* @param fromIndex the start of the range (inclusive), 0 by default.
* @param toIndex the end of the range (exclusive), size of this array by default.
* @param fromIndex the start of the range (inclusive) to fill, 0 by default.
* @param toIndex the end of the range (exclusive) to fill, size of this array by default.
*
* @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array.
* @throws IllegalArgumentException if [fromIndex] is greater than [toIndex].
@@ -1480,8 +1507,8 @@ public actual fun DoubleArray.fill(element: Double, fromIndex: Int = 0, toIndex:
/**
* Fills this array or its subrange with the specified [element] value.
*
* @param fromIndex the start of the range (inclusive), 0 by default.
* @param toIndex the end of the range (exclusive), size of this array by default.
* @param fromIndex the start of the range (inclusive) to fill, 0 by default.
* @param toIndex the end of the range (exclusive) to fill, size of this array by default.
*
* @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array.
* @throws IllegalArgumentException if [fromIndex] is greater than [toIndex].
@@ -1496,8 +1523,8 @@ public actual fun BooleanArray.fill(element: Boolean, fromIndex: Int = 0, toInde
/**
* Fills this array or its subrange with the specified [element] value.
*
* @param fromIndex the start of the range (inclusive), 0 by default.
* @param toIndex the end of the range (exclusive), size of this array by default.
* @param fromIndex the start of the range (inclusive) to fill, 0 by default.
* @param toIndex the end of the range (exclusive) to fill, size of this array by default.
*
* @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array.
* @throws IllegalArgumentException if [fromIndex] is greater than [toIndex].
@@ -1831,6 +1858,12 @@ public fun <T> Array<out T>.sort(comparison: (a: T, b: T) -> Int): Unit {
*
* The sort is _stable_. It means that equal elements preserve their order relative to each other after sorting.
*
* @param fromIndex the start of the range (inclusive) to sort, 0 by default.
* @param toIndex the end of the range (exclusive) to sort, size of this array by default.
*
* @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array.
* @throws IllegalArgumentException if [fromIndex] is greater than [toIndex].
*
* @sample samples.collections.Arrays.Sorting.sortRangeOfArrayOfComparable
*/
@SinceKotlin("1.4")
@@ -1843,6 +1876,12 @@ public actual fun <T : Comparable<T>> Array<out T>.sort(fromIndex: Int = 0, toIn
/**
* Sorts a range in the array in-place.
*
* @param fromIndex the start of the range (inclusive) to sort, 0 by default.
* @param toIndex the end of the range (exclusive) to sort, size of this array by default.
*
* @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array.
* @throws IllegalArgumentException if [fromIndex] is greater than [toIndex].
*
* @sample samples.collections.Arrays.Sorting.sortRangeOfArray
*/
@SinceKotlin("1.4")
@@ -1856,6 +1895,12 @@ public actual fun ByteArray.sort(fromIndex: Int = 0, toIndex: Int = size): Unit
/**
* Sorts a range in the array in-place.
*
* @param fromIndex the start of the range (inclusive) to sort, 0 by default.
* @param toIndex the end of the range (exclusive) to sort, size of this array by default.
*
* @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array.
* @throws IllegalArgumentException if [fromIndex] is greater than [toIndex].
*
* @sample samples.collections.Arrays.Sorting.sortRangeOfArray
*/
@SinceKotlin("1.4")
@@ -1869,6 +1914,12 @@ public actual fun ShortArray.sort(fromIndex: Int = 0, toIndex: Int = size): Unit
/**
* Sorts a range in the array in-place.
*
* @param fromIndex the start of the range (inclusive) to sort, 0 by default.
* @param toIndex the end of the range (exclusive) to sort, size of this array by default.
*
* @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array.
* @throws IllegalArgumentException if [fromIndex] is greater than [toIndex].
*
* @sample samples.collections.Arrays.Sorting.sortRangeOfArray
*/
@SinceKotlin("1.4")
@@ -1882,6 +1933,12 @@ public actual fun IntArray.sort(fromIndex: Int = 0, toIndex: Int = size): Unit {
/**
* Sorts a range in the array in-place.
*
* @param fromIndex the start of the range (inclusive) to sort, 0 by default.
* @param toIndex the end of the range (exclusive) to sort, size of this array by default.
*
* @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array.
* @throws IllegalArgumentException if [fromIndex] is greater than [toIndex].
*
* @sample samples.collections.Arrays.Sorting.sortRangeOfArray
*/
@SinceKotlin("1.4")
@@ -1894,6 +1951,12 @@ public actual fun LongArray.sort(fromIndex: Int = 0, toIndex: Int = size): Unit
/**
* Sorts a range in the array in-place.
*
* @param fromIndex the start of the range (inclusive) to sort, 0 by default.
* @param toIndex the end of the range (exclusive) to sort, size of this array by default.
*
* @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array.
* @throws IllegalArgumentException if [fromIndex] is greater than [toIndex].
*
* @sample samples.collections.Arrays.Sorting.sortRangeOfArray
*/
@SinceKotlin("1.4")
@@ -1907,6 +1970,12 @@ public actual fun FloatArray.sort(fromIndex: Int = 0, toIndex: Int = size): Unit
/**
* Sorts a range in the array in-place.
*
* @param fromIndex the start of the range (inclusive) to sort, 0 by default.
* @param toIndex the end of the range (exclusive) to sort, size of this array by default.
*
* @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array.
* @throws IllegalArgumentException if [fromIndex] is greater than [toIndex].
*
* @sample samples.collections.Arrays.Sorting.sortRangeOfArray
*/
@SinceKotlin("1.4")
@@ -1920,6 +1989,12 @@ public actual fun DoubleArray.sort(fromIndex: Int = 0, toIndex: Int = size): Uni
/**
* Sorts a range in the array in-place.
*
* @param fromIndex the start of the range (inclusive) to sort, 0 by default.
* @param toIndex the end of the range (exclusive) to sort, size of this array by default.
*
* @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array.
* @throws IllegalArgumentException if [fromIndex] is greater than [toIndex].
*
* @sample samples.collections.Arrays.Sorting.sortRangeOfArray
*/
@SinceKotlin("1.4")
@@ -1998,6 +2073,12 @@ public actual fun <T> Array<out T>.sortWith(comparator: Comparator<in T>): Unit
* Sorts a range in the array in-place with the given [comparator].
*
* The sort is _stable_. It means that equal elements preserve their order relative to each other after sorting.
*
* @param fromIndex the start of the range (inclusive) to sort, 0 by default.
* @param toIndex the end of the range (exclusive) to sort, size of this array by default.
*
* @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array.
* @throws IllegalArgumentException if [fromIndex] is greater than [toIndex].
*/
@SinceKotlin("1.4")
@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")