Provide toTypedArray method for primitive arrays.

This commit is contained in:
Ilya Gorbunov
2015-07-16 17:33:53 +03:00
parent f57c207ed2
commit 12e3542bce
5 changed files with 177 additions and 0 deletions
@@ -903,3 +903,83 @@ public fun ShortArray.sort(fromIndex: Int = 0, toIndex: Int = size()): Unit {
Arrays.sort(this, fromIndex, toIndex)
}
/**
* Returns a *typed* object array containing all of the elements of this primitive array.
*/
public fun BooleanArray.toTypedArray(): Array<Boolean> {
val result = arrayOfNulls<Boolean>(size())
for (index in indices)
result[index] = this[index]
return result as Array<Boolean>
}
/**
* Returns a *typed* object array containing all of the elements of this primitive array.
*/
public fun ByteArray.toTypedArray(): Array<Byte> {
val result = arrayOfNulls<Byte>(size())
for (index in indices)
result[index] = this[index]
return result as Array<Byte>
}
/**
* Returns a *typed* object array containing all of the elements of this primitive array.
*/
public fun CharArray.toTypedArray(): Array<Char> {
val result = arrayOfNulls<Char>(size())
for (index in indices)
result[index] = this[index]
return result as Array<Char>
}
/**
* Returns a *typed* object array containing all of the elements of this primitive array.
*/
public fun DoubleArray.toTypedArray(): Array<Double> {
val result = arrayOfNulls<Double>(size())
for (index in indices)
result[index] = this[index]
return result as Array<Double>
}
/**
* Returns a *typed* object array containing all of the elements of this primitive array.
*/
public fun FloatArray.toTypedArray(): Array<Float> {
val result = arrayOfNulls<Float>(size())
for (index in indices)
result[index] = this[index]
return result as Array<Float>
}
/**
* Returns a *typed* object array containing all of the elements of this primitive array.
*/
public fun IntArray.toTypedArray(): Array<Int> {
val result = arrayOfNulls<Int>(size())
for (index in indices)
result[index] = this[index]
return result as Array<Int>
}
/**
* Returns a *typed* object array containing all of the elements of this primitive array.
*/
public fun LongArray.toTypedArray(): Array<Long> {
val result = arrayOfNulls<Long>(size())
for (index in indices)
result[index] = this[index]
return result as Array<Long>
}
/**
* Returns a *typed* object array containing all of the elements of this primitive array.
*/
public fun ShortArray.toTypedArray(): Array<Short> {
val result = arrayOfNulls<Short>(size())
for (index in indices)
result[index] = this[index]
return result as Array<Short>
}