feat(utils): 添加数组工具类和国际化支持
- 添加ByteArray.toHexString和String.toHexByteArray扩展函数 - 实现多种数组类型的copyTo和copyFrom扩展方法 - 在AutoConfiguration中集成I18N国际化功能 - 添加AutoService注解及处理器用于自动服务注册 - 新增BadGatewayException HTTP状态异常类 - 更新启动横幅格式并添加国际化文本支持
This commit is contained in:
@@ -16,373 +16,327 @@
|
||||
* ProjectName mingli-utils
|
||||
* ModuleName mingli-utils.main
|
||||
* CurrentFile ArrayUtils.kt
|
||||
* LastUpdate 2026-01-28 08:03:28
|
||||
* LastUpdate 2026-02-06 14:01:56
|
||||
* UpdateUser MingLiPro
|
||||
*/
|
||||
|
||||
|
||||
@file:JvmName("ArrayUtils")
|
||||
|
||||
package com.mingliqiye.utils.array
|
||||
|
||||
import com.mingliqiye.utils.base.BASE16
|
||||
|
||||
|
||||
/**
|
||||
* 复制数组元素到目标数组
|
||||
* @param from 源数组
|
||||
* @param to 目标数组
|
||||
* @param fromPos 源数组起始位置,默认为0
|
||||
* @param toPos 目标数组起始位置,默认为0
|
||||
* @param length 要复制的元素数量,默认为源数组从起始位置到末尾的长度
|
||||
* @throws IndexOutOfBoundsException 当索引超出数组边界时抛出
|
||||
* @throws ArrayStoreException 当类型不匹配时抛出
|
||||
* 将字节数组转换为十六进制字符串
|
||||
*
|
||||
* @return 大写的十六进制字符串,每两个字符表示一个字节
|
||||
* @since 4.6.0
|
||||
* @see toHexByteArray
|
||||
*/
|
||||
@Throws(IndexOutOfBoundsException::class, ArrayStoreException::class)
|
||||
fun <T> arrayCopy(from: Array<T>, to: Array<T>, fromPos: Int = 0, toPos: Int = 0, length: Int = from.size - fromPos) {
|
||||
System.arraycopy(from, fromPos, to, toPos, length)
|
||||
fun ByteArray.toHexString(): String = BASE16.encode(this).uppercase()
|
||||
|
||||
/**
|
||||
* 将十六进制字符串转换为字节数组
|
||||
*
|
||||
* @return 对应的字节数组
|
||||
* @throws IllegalArgumentException 如果字符串包含非十六进制字符
|
||||
* @since 4.6.0
|
||||
* @see toHexString
|
||||
*/
|
||||
fun String.toHexByteArray(): ByteArray = BASE16.decode(this.lowercase())
|
||||
|
||||
/* ==================== 数组复制扩展函数 ==================== */
|
||||
|
||||
/**
|
||||
* 将当前数组的指定范围复制到目标数组
|
||||
*
|
||||
* @param dest 目标数组
|
||||
* @param srcPos 源数组起始位置(包含)
|
||||
* @param distPos 目标数组起始位置(包含)
|
||||
* @param len 要复制的元素数量
|
||||
* @return 源数组自身(支持链式调用)
|
||||
* @throws IndexOutOfBoundsException 如果索引超出范围
|
||||
* @throws IllegalArgumentException 如果参数无效
|
||||
* @since 4.6.0
|
||||
*/
|
||||
@JvmName("arrayCopy")
|
||||
fun <T> Array<T>.copyTo(dest: Array<T>, srcPos: Int, distPos: Int, len: Int): Array<T> = this.also {
|
||||
System.arraycopy(this, srcPos, dest, distPos, len)
|
||||
}
|
||||
|
||||
/**
|
||||
* 扩展函数:将当前数组元素复制到目标数组
|
||||
* @param to 目标数组
|
||||
* @param fromPos 源数组起始位置,默认为0
|
||||
* @param toPos 目标数组起始位置,默认为0
|
||||
* @param length 要复制的元素数量,默认为源数组从起始位置到末尾的长度
|
||||
* @throws IndexOutOfBoundsException 当索引超出数组边界时抛出
|
||||
* @throws ArrayStoreException 当类型不匹配时抛出
|
||||
* 创建新数组并复制当前数组的指定范围
|
||||
*
|
||||
* @param srcPos 源数组起始位置(包含)
|
||||
* @param distPos 目标数组起始位置(包含)
|
||||
* @param len 要复制的元素数量,也作为新数组的长度
|
||||
* @return 新创建的数组
|
||||
* @throws IndexOutOfBoundsException 如果索引超出范围
|
||||
* @since 4.6.2
|
||||
*/
|
||||
@JvmSynthetic
|
||||
@Throws(IndexOutOfBoundsException::class, ArrayStoreException::class)
|
||||
fun <T> Array<T>.copyTo(to: Array<T>, fromPos: Int = 0, toPos: Int = 0, length: Int = this.size - fromPos) {
|
||||
System.arraycopy(this, fromPos, to, toPos, length)
|
||||
@JvmName("arrayCopy")
|
||||
fun <T> Array<T>.copyTo(srcPos: Int, distPos: Int, len: Int): Array<T> =
|
||||
java.lang.reflect.Array.newInstance(this.javaClass.componentType, len).also {
|
||||
System.arraycopy(this, srcPos, it, distPos, len)
|
||||
}.let {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
it as Array<T>
|
||||
}
|
||||
|
||||
/**
|
||||
* 将源数组的指定范围复制到当前数组
|
||||
*
|
||||
* @param src 源数组
|
||||
* @param srcPos 源数组起始位置(包含)
|
||||
* @param distPos 当前数组起始位置(包含)
|
||||
* @param len 要复制的元素数量
|
||||
* @return 当前数组自身(支持链式调用)
|
||||
* @throws IndexOutOfBoundsException 如果索引超出范围
|
||||
* @since 4.6.1
|
||||
*/
|
||||
@JvmName("arrayCopyFrom")
|
||||
fun <T> Array<T>.copyFrom(src: Array<T>, srcPos: Int, distPos: Int, len: Int): Array<T> = this.also {
|
||||
System.arraycopy(src, srcPos, this, distPos, len)
|
||||
}
|
||||
|
||||
/* ==================== BooleanArray 扩展 ==================== */
|
||||
|
||||
/**
|
||||
* @see Array.copyTo
|
||||
* @since 4.6.0
|
||||
*/
|
||||
@JvmName("arrayCopy")
|
||||
fun BooleanArray.copyTo(dest: BooleanArray, srcPos: Int, distPos: Int, len: Int): BooleanArray = this.also {
|
||||
System.arraycopy(this, srcPos, dest, distPos, len)
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制整个数组到目标数组(重载版本)
|
||||
* @param from 源数组
|
||||
* @param to 目标数组
|
||||
* @throws IndexOutOfBoundsException 当索引超出数组边界时抛出
|
||||
* @throws ArrayStoreException 当类型不匹配时抛出
|
||||
* @see Array.copyTo
|
||||
* @since 4.6.2
|
||||
*/
|
||||
@Throws(IndexOutOfBoundsException::class, ArrayStoreException::class)
|
||||
fun <T> arrayCopy(from: Array<T>, to: Array<T>) {
|
||||
return arrayCopy(from, to, 0, 0, from.size)
|
||||
@JvmName("arrayCopy")
|
||||
fun BooleanArray.copyTo(srcPos: Int, distPos: Int, len: Int): BooleanArray =
|
||||
BooleanArray(len).also { newArray ->
|
||||
System.arraycopy(this, srcPos, newArray, distPos, len)
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Array.copyFrom
|
||||
* @since 4.6.1
|
||||
*/
|
||||
@JvmName("arrayCopyFrom")
|
||||
fun BooleanArray.copyFrom(src: BooleanArray, srcPos: Int, distPos: Int, len: Int): BooleanArray = this.also {
|
||||
System.arraycopy(src, srcPos, this, distPos, len)
|
||||
}
|
||||
|
||||
/* ==================== ByteArray 扩展 ==================== */
|
||||
|
||||
/**
|
||||
* @see Array.copyTo
|
||||
* @since 4.6.0
|
||||
*/
|
||||
@JvmName("arrayCopy")
|
||||
fun ByteArray.copyTo(dest: ByteArray, srcPos: Int, distPos: Int, len: Int): ByteArray = this.also {
|
||||
System.arraycopy(this, srcPos, dest, distPos, len)
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制字节数组元素到目标数组
|
||||
* @param from 源字节数组
|
||||
* @param to 目标字节数组
|
||||
* @param fromPos 源数组起始位置,默认为0
|
||||
* @param toPos 目标数组起始位置,默认为0
|
||||
* @param length 要复制的元素数量,默认为源数组从起始位置到末尾的长度
|
||||
* @throws IndexOutOfBoundsException 当索引超出数组边界时抛出
|
||||
* @see Array.copyTo
|
||||
* @since 4.6.2
|
||||
*/
|
||||
@Throws(IndexOutOfBoundsException::class)
|
||||
fun arrayCopy(from: ByteArray, to: ByteArray, fromPos: Int = 0, toPos: Int = 0, length: Int = from.size - fromPos) {
|
||||
System.arraycopy(from, fromPos, to, toPos, length)
|
||||
@JvmName("arrayCopy")
|
||||
fun ByteArray.copyTo(srcPos: Int, distPos: Int, len: Int): ByteArray =
|
||||
ByteArray(len).also { newArray ->
|
||||
System.arraycopy(this, srcPos, newArray, distPos, len)
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Array.copyFrom
|
||||
* @since 4.6.1
|
||||
*/
|
||||
@JvmName("arrayCopyFrom")
|
||||
fun ByteArray.copyFrom(src: ByteArray, srcPos: Int, distPos: Int, len: Int): ByteArray = this.also {
|
||||
System.arraycopy(src, srcPos, this, distPos, len)
|
||||
}
|
||||
|
||||
/* ==================== CharArray 扩展 ==================== */
|
||||
|
||||
/**
|
||||
* @see Array.copyTo
|
||||
* @since 4.6.0
|
||||
*/
|
||||
@JvmName("arrayCopy")
|
||||
fun CharArray.copyTo(dest: CharArray, srcPos: Int, distPos: Int, len: Int): CharArray = this.also {
|
||||
System.arraycopy(this, srcPos, dest, distPos, len)
|
||||
}
|
||||
|
||||
/**
|
||||
* 扩展函数:将当前字节数组元素复制到目标数组
|
||||
* @param to 目标字节数组
|
||||
* @param fromPos 源数组起始位置,默认为0
|
||||
* @param toPos 目标数组起始位置,默认为0
|
||||
* @param length 要复制的元素数量,默认为源数组从起始位置到末尾的长度
|
||||
* @throws IndexOutOfBoundsException 当索引超出数组边界时抛出
|
||||
* @throws ArrayStoreException 当类型不匹配时抛出
|
||||
* @see Array.copyTo
|
||||
* @since 4.6.2
|
||||
*/
|
||||
@JvmSynthetic
|
||||
@Throws(IndexOutOfBoundsException::class, ArrayStoreException::class)
|
||||
fun ByteArray.copyTo(to: ByteArray, fromPos: Int = 0, toPos: Int = 0, length: Int = this.size - fromPos) {
|
||||
System.arraycopy(this, fromPos, to, toPos, length)
|
||||
@JvmName("arrayCopy")
|
||||
fun CharArray.copyTo(srcPos: Int, distPos: Int, len: Int): CharArray =
|
||||
CharArray(len).also { newArray ->
|
||||
System.arraycopy(this, srcPos, newArray, distPos, len)
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Array.copyFrom
|
||||
* @since 4.6.1
|
||||
*/
|
||||
@JvmName("arrayCopyFrom")
|
||||
fun CharArray.copyFrom(src: CharArray, srcPos: Int, distPos: Int, len: Int): CharArray = this.also {
|
||||
System.arraycopy(src, srcPos, this, distPos, len)
|
||||
}
|
||||
|
||||
/* ==================== DoubleArray 扩展 ==================== */
|
||||
|
||||
/**
|
||||
* @see Array.copyTo
|
||||
* @since 4.6.0
|
||||
*/
|
||||
@JvmName("arrayCopy")
|
||||
fun DoubleArray.copyTo(dest: DoubleArray, srcPos: Int, distPos: Int, len: Int): DoubleArray = this.also {
|
||||
System.arraycopy(this, srcPos, dest, distPos, len)
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制整个字节数组到目标数组(重载版本)
|
||||
* @param from 源字节数组
|
||||
* @param to 目标字节数组
|
||||
* @throws IndexOutOfBoundsException 当索引超出数组边界时抛出
|
||||
* @see Array.copyTo
|
||||
* @since 4.6.2
|
||||
*/
|
||||
@Throws(IndexOutOfBoundsException::class)
|
||||
fun arrayCopy(from: ByteArray, to: ByteArray) {
|
||||
arrayCopy(from, to, 0, 0, from.size)
|
||||
@JvmName("arrayCopy")
|
||||
fun DoubleArray.copyTo(srcPos: Int, distPos: Int, len: Int): DoubleArray =
|
||||
DoubleArray(len).also { newArray ->
|
||||
System.arraycopy(this, srcPos, newArray, distPos, len)
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Array.copyFrom
|
||||
* @since 4.6.1
|
||||
*/
|
||||
@JvmName("arrayCopyFrom")
|
||||
fun DoubleArray.copyFrom(src: DoubleArray, srcPos: Int, distPos: Int, len: Int): DoubleArray = this.also {
|
||||
System.arraycopy(src, srcPos, this, distPos, len)
|
||||
}
|
||||
|
||||
/* ==================== FloatArray 扩展 ==================== */
|
||||
|
||||
/**
|
||||
* @see Array.copyTo
|
||||
* @since 4.6.0
|
||||
*/
|
||||
@JvmName("arrayCopy")
|
||||
fun FloatArray.copyTo(dest: FloatArray, srcPos: Int, distPos: Int, len: Int): FloatArray = this.also {
|
||||
System.arraycopy(this, srcPos, dest, distPos, len)
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制短整型数组元素到目标数组
|
||||
* @param from 源短整型数组
|
||||
* @param to 目标短整型数组
|
||||
* @param fromPos 源数组起始位置,默认为0
|
||||
* @param toPos 目标数组起始位置,默认为0
|
||||
* @param length 要复制的元素数量,默认为源数组从起始位置到末尾的长度
|
||||
* @throws IndexOutOfBoundsException 当索引超出数组边界时抛出
|
||||
* @see Array.copyTo
|
||||
* @since 4.6.2
|
||||
*/
|
||||
@Throws(IndexOutOfBoundsException::class)
|
||||
fun arrayCopy(from: ShortArray, to: ShortArray, fromPos: Int = 0, toPos: Int = 0, length: Int = from.size - fromPos) {
|
||||
System.arraycopy(from, fromPos, to, toPos, length)
|
||||
@JvmName("arrayCopy")
|
||||
fun FloatArray.copyTo(srcPos: Int, distPos: Int, len: Int): FloatArray =
|
||||
FloatArray(len).also { newArray ->
|
||||
System.arraycopy(this, srcPos, newArray, distPos, len)
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Array.copyFrom
|
||||
* @since 4.6.1
|
||||
*/
|
||||
@JvmName("arrayCopyFrom")
|
||||
fun FloatArray.copyFrom(src: FloatArray, srcPos: Int, distPos: Int, len: Int): FloatArray = this.also {
|
||||
System.arraycopy(src, srcPos, this, distPos, len)
|
||||
}
|
||||
|
||||
/* ==================== IntArray 扩展 ==================== */
|
||||
|
||||
/**
|
||||
* @see Array.copyTo
|
||||
* @since 4.6.0
|
||||
*/
|
||||
@JvmName("arrayCopy")
|
||||
fun IntArray.copyTo(dest: IntArray, srcPos: Int, distPos: Int, len: Int): IntArray = this.also {
|
||||
System.arraycopy(this, srcPos, dest, distPos, len)
|
||||
}
|
||||
|
||||
/**
|
||||
* 扩展函数:将当前短整型数组元素复制到目标数组
|
||||
* @param to 目标短整型数组
|
||||
* @param fromPos 源数组起始位置,默认为0
|
||||
* @param toPos 目标数组起始位置,默认为0
|
||||
* @param length 要复制的元素数量,默认为源数组从起始位置到末尾的长度
|
||||
* @throws IndexOutOfBoundsException 当索引超出数组边界时抛出
|
||||
* @throws ArrayStoreException 当类型不匹配时抛出
|
||||
* @see Array.copyTo
|
||||
* @since 4.6.2
|
||||
*/
|
||||
@JvmSynthetic
|
||||
@Throws(IndexOutOfBoundsException::class, ArrayStoreException::class)
|
||||
fun ShortArray.copyTo(to: ShortArray, fromPos: Int = 0, toPos: Int = 0, length: Int = this.size - fromPos) {
|
||||
System.arraycopy(this, fromPos, to, toPos, length)
|
||||
@JvmName("arrayCopy")
|
||||
fun IntArray.copyTo(srcPos: Int, distPos: Int, len: Int): IntArray =
|
||||
IntArray(len).also { newArray ->
|
||||
System.arraycopy(this, srcPos, newArray, distPos, len)
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Array.copyFrom
|
||||
* @since 4.6.1
|
||||
*/
|
||||
@JvmName("arrayCopyFrom")
|
||||
fun IntArray.copyFrom(src: IntArray, srcPos: Int, distPos: Int, len: Int): IntArray = this.also {
|
||||
System.arraycopy(src, srcPos, this, distPos, len)
|
||||
}
|
||||
|
||||
/* ==================== LongArray 扩展 ==================== */
|
||||
|
||||
/**
|
||||
* @see Array.copyTo
|
||||
* @since 4.6.0
|
||||
*/
|
||||
@JvmName("arrayCopy")
|
||||
fun LongArray.copyTo(dest: LongArray, srcPos: Int, distPos: Int, len: Int): LongArray = this.also {
|
||||
System.arraycopy(this, srcPos, dest, distPos, len)
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制整个短整型数组到目标数组(重载版本)
|
||||
* @param from 源短整型数组
|
||||
* @param to 目标短整型数组
|
||||
* @throws IndexOutOfBoundsException 当索引超出数组边界时抛出
|
||||
* @see Array.copyTo
|
||||
* @since 4.6.2
|
||||
*/
|
||||
@Throws(IndexOutOfBoundsException::class)
|
||||
fun arrayCopy(from: ShortArray, to: ShortArray) {
|
||||
arrayCopy(from, to, 0, 0, from.size)
|
||||
@JvmName("arrayCopy")
|
||||
fun LongArray.copyTo(srcPos: Int, distPos: Int, len: Int): LongArray =
|
||||
LongArray(len).also { newArray ->
|
||||
System.arraycopy(this, srcPos, newArray, distPos, len)
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Array.copyFrom
|
||||
* @since 4.6.1
|
||||
*/
|
||||
@JvmName("arrayCopyFrom")
|
||||
fun LongArray.copyFrom(src: LongArray, srcPos: Int, distPos: Int, len: Int): LongArray = this.also {
|
||||
System.arraycopy(src, srcPos, this, distPos, len)
|
||||
}
|
||||
|
||||
/* ==================== ShortArray 扩展 ==================== */
|
||||
|
||||
/**
|
||||
* @see Array.copyTo
|
||||
* @since 4.6.0
|
||||
*/
|
||||
@JvmName("arrayCopy")
|
||||
fun ShortArray.copyTo(dest: ShortArray, srcPos: Int, distPos: Int, len: Int): ShortArray = this.also {
|
||||
System.arraycopy(this, srcPos, dest, distPos, len)
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制整型数组元素到目标数组
|
||||
* @param from 源整型数组
|
||||
* @param to 目标整型数组
|
||||
* @param fromPos 源数组起始位置,默认为0
|
||||
* @param toPos 目标数组起始位置,默认为0
|
||||
* @param length 要复制的元素数量,默认为源数组从起始位置到末尾的长度
|
||||
* @throws IndexOutOfBoundsException 当索引超出数组边界时抛出
|
||||
* @see Array.copyTo
|
||||
* @since 4.6.2
|
||||
*/
|
||||
@Throws(IndexOutOfBoundsException::class)
|
||||
fun arrayCopy(from: IntArray, to: IntArray, fromPos: Int = 0, toPos: Int = 0, length: Int = from.size - fromPos) {
|
||||
System.arraycopy(from, fromPos, to, toPos, length)
|
||||
}
|
||||
@JvmName("arrayCopy")
|
||||
fun ShortArray.copyTo(srcPos: Int, distPos: Int, len: Int): ShortArray =
|
||||
ShortArray(len).also { newArray ->
|
||||
System.arraycopy(this, srcPos, newArray, distPos, len)
|
||||
}
|
||||
|
||||
/**
|
||||
* 扩展函数:将当前整型数组元素复制到目标数组
|
||||
* @param to 目标整型数组
|
||||
* @param fromPos 源数组起始位置,默认为0
|
||||
* @param toPos 目标数组起始位置,默认为0
|
||||
* @param length 要复制的元素数量,默认为源数组从起始位置到末尾的长度
|
||||
* @throws IndexOutOfBoundsException 当索引超出数组边界时抛出
|
||||
* @throws ArrayStoreException 当类型不匹配时抛出
|
||||
* @see Array.copyFrom
|
||||
* @since 4.6.1
|
||||
*/
|
||||
@JvmSynthetic
|
||||
@Throws(IndexOutOfBoundsException::class, ArrayStoreException::class)
|
||||
fun IntArray.copyTo(to: IntArray, fromPos: Int = 0, toPos: Int = 0, length: Int = this.size - fromPos) {
|
||||
System.arraycopy(this, fromPos, to, toPos, length)
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制整个整型数组到目标数组(重载版本)
|
||||
* @param from 源整型数组
|
||||
* @param to 目标整型数组
|
||||
* @throws IndexOutOfBoundsException 当索引超出数组边界时抛出
|
||||
*/
|
||||
@Throws(IndexOutOfBoundsException::class)
|
||||
fun arrayCopy(from: IntArray, to: IntArray) {
|
||||
arrayCopy(from, to, 0, 0, from.size)
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制长整型数组元素到目标数组
|
||||
* @param from 源长整型数组
|
||||
* @param to 目标长整型数组
|
||||
* @param fromPos 源数组起始位置,默认为0
|
||||
* @param toPos 目标数组起始位置,默认为0
|
||||
* @param length 要复制的元素数量,默认为源数组从起始位置到末尾的长度
|
||||
* @throws IndexOutOfBoundsException 当索引超出数组边界时抛出
|
||||
*/
|
||||
@Throws(IndexOutOfBoundsException::class)
|
||||
fun arrayCopy(from: LongArray, to: LongArray, fromPos: Int = 0, toPos: Int = 0, length: Int = from.size - fromPos) {
|
||||
System.arraycopy(from, fromPos, to, toPos, length)
|
||||
}
|
||||
|
||||
/**
|
||||
* 扩展函数:将当前长整型数组元素复制到目标数组
|
||||
* @param to 目标长整型数组
|
||||
* @param fromPos 源数组起始位置,默认为0
|
||||
* @param toPos 目标数组起始位置,默认为0
|
||||
* @param length 要复制的元素数量,默认为源数组从起始位置到末尾的长度
|
||||
* @throws IndexOutOfBoundsException 当索引超出数组边界时抛出
|
||||
* @throws ArrayStoreException 当类型不匹配时抛出
|
||||
*/
|
||||
@JvmSynthetic
|
||||
@Throws(IndexOutOfBoundsException::class, ArrayStoreException::class)
|
||||
fun LongArray.copyTo(to: LongArray, fromPos: Int = 0, toPos: Int = 0, length: Int = this.size - fromPos) {
|
||||
System.arraycopy(this, fromPos, to, toPos, length)
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制整个长整型数组到目标数组(重载版本)
|
||||
* @param from 源长整型数组
|
||||
* @param to 目标长整型数组
|
||||
* @throws IndexOutOfBoundsException 当索引超出数组边界时抛出
|
||||
*/
|
||||
@Throws(IndexOutOfBoundsException::class)
|
||||
fun arrayCopy(from: LongArray, to: LongArray) {
|
||||
arrayCopy(from, to, 0, 0, from.size)
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制浮点型数组元素到目标数组
|
||||
* @param from 源浮点型数组
|
||||
* @param to 目标浮点型数组
|
||||
* @param fromPos 源数组起始位置,默认为0
|
||||
* @param toPos 目标数组起始位置,默认为0
|
||||
* @param length 要复制的元素数量,默认为源数组从起始位置到末尾的长度
|
||||
* @throws IndexOutOfBoundsException 当索引超出数组边界时抛出
|
||||
*/
|
||||
@Throws(IndexOutOfBoundsException::class)
|
||||
fun arrayCopy(from: FloatArray, to: FloatArray, fromPos: Int = 0, toPos: Int = 0, length: Int = from.size - fromPos) {
|
||||
System.arraycopy(from, fromPos, to, toPos, length)
|
||||
}
|
||||
|
||||
/**
|
||||
* 扩展函数:将当前浮点型数组元素复制到目标数组
|
||||
* @param to 目标浮点型数组
|
||||
* @param fromPos 源数组起始位置,默认为0
|
||||
* @param toPos 目标数组起始位置,默认为0
|
||||
* @param length 要复制的元素数量,默认为源数组从起始位置到末尾的长度
|
||||
* @throws IndexOutOfBoundsException 当索引超出数组边界时抛出
|
||||
* @throws ArrayStoreException 当类型不匹配时抛出
|
||||
*/
|
||||
@JvmSynthetic
|
||||
@Throws(IndexOutOfBoundsException::class, ArrayStoreException::class)
|
||||
fun FloatArray.copyTo(to: FloatArray, fromPos: Int = 0, toPos: Int = 0, length: Int = this.size - fromPos) {
|
||||
System.arraycopy(this, fromPos, to, toPos, length)
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制整个浮点型数组到目标数组(重载版本)
|
||||
* @param from 源浮点型数组
|
||||
* @param to 目标浮点型数组
|
||||
* @throws IndexOutOfBoundsException 当索引超出数组边界时抛出
|
||||
*/
|
||||
@Throws(IndexOutOfBoundsException::class)
|
||||
fun arrayCopy(from: FloatArray, to: FloatArray) {
|
||||
arrayCopy(from, to, 0, 0, from.size)
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制双精度浮点型数组元素到目标数组
|
||||
* @param from 源双精度浮点型数组
|
||||
* @param to 目标双精度浮点型数组
|
||||
* @param fromPos 源数组起始位置,默认为0
|
||||
* @param toPos 目标数组起始位置,默认为0
|
||||
* @param length 要复制的元素数量,默认为源数组从起始位置到末尾的长度
|
||||
* @throws IndexOutOfBoundsException 当索引超出数组边界时抛出
|
||||
*/
|
||||
@Throws(IndexOutOfBoundsException::class)
|
||||
fun arrayCopy(from: DoubleArray, to: DoubleArray, fromPos: Int = 0, toPos: Int = 0, length: Int = from.size - fromPos) {
|
||||
System.arraycopy(from, fromPos, to, toPos, length)
|
||||
}
|
||||
|
||||
/**
|
||||
* 扩展函数:将当前双精度浮点型数组元素复制到目标数组
|
||||
* @param to 目标双精度浮点型数组
|
||||
* @param fromPos 源数组起始位置,默认为0
|
||||
* @param toPos 目标数组起始位置,默认为0
|
||||
* @param length 要复制的元素数量,默认为源数组从起始位置到末尾的长度
|
||||
* @throws IndexOutOfBoundsException 当索引超出数组边界时抛出
|
||||
* @throws ArrayStoreException 当类型不匹配时抛出
|
||||
*/
|
||||
@JvmSynthetic
|
||||
@Throws(IndexOutOfBoundsException::class, ArrayStoreException::class)
|
||||
fun DoubleArray.copyTo(to: DoubleArray, fromPos: Int = 0, toPos: Int = 0, length: Int = this.size - fromPos) {
|
||||
System.arraycopy(this, fromPos, to, toPos, length)
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制整个双精度浮点型数组到目标数组(重载版本)
|
||||
* @param from 源双精度浮点型数组
|
||||
* @param to 目标双精度浮点型数组
|
||||
* @throws IndexOutOfBoundsException 当索引超出数组边界时抛出
|
||||
*/
|
||||
@Throws(IndexOutOfBoundsException::class)
|
||||
fun arrayCopy(from: DoubleArray, to: DoubleArray) {
|
||||
arrayCopy(from, to, 0, 0, from.size)
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制布尔型数组元素到目标数组
|
||||
* @param from 源布尔型数组
|
||||
* @param to 目标布尔型数组
|
||||
* @param fromPos 源数组起始位置,默认为0
|
||||
* @param toPos 目标数组起始位置,默认为0
|
||||
* @param length 要复制的元素数量,默认为源数组从起始位置到末尾的长度
|
||||
* @throws IndexOutOfBoundsException 当索引超出数组边界时抛出
|
||||
*/
|
||||
@Throws(IndexOutOfBoundsException::class)
|
||||
fun arrayCopy(
|
||||
from: BooleanArray, to: BooleanArray, fromPos: Int = 0, toPos: Int = 0, length: Int = from.size - fromPos
|
||||
) {
|
||||
System.arraycopy(from, fromPos, to, toPos, length)
|
||||
}
|
||||
|
||||
/**
|
||||
* 扩展函数:将当前布尔型数组元素复制到目标数组
|
||||
* @param to 目标布尔型数组
|
||||
* @param fromPos 源数组起始位置,默认为0
|
||||
* @param toPos 目标数组起始位置,默认为0
|
||||
* @param length 要复制的元素数量,默认为源数组从起始位置到末尾的长度
|
||||
* @throws IndexOutOfBoundsException 当索引超出数组边界时抛出
|
||||
* @throws ArrayStoreException 当类型不匹配时抛出
|
||||
*/
|
||||
@JvmSynthetic
|
||||
@Throws(IndexOutOfBoundsException::class, ArrayStoreException::class)
|
||||
fun BooleanArray.copyTo(to: BooleanArray, fromPos: Int = 0, toPos: Int = 0, length: Int = this.size - fromPos) {
|
||||
System.arraycopy(this, fromPos, to, toPos, length)
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制整个布尔型数组到目标数组(重载版本)
|
||||
* @param from 源布尔型数组
|
||||
* @param to 目标布尔型数组
|
||||
* @throws IndexOutOfBoundsException 当索引超出数组边界时抛出
|
||||
*/
|
||||
@Throws(IndexOutOfBoundsException::class)
|
||||
fun arrayCopy(from: BooleanArray, to: BooleanArray) {
|
||||
arrayCopy(from, to, 0, 0, from.size)
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制字符型数组元素到目标数组
|
||||
* @param from 源字符型数组
|
||||
* @param to 目标字符型数组
|
||||
* @param fromPos 源数组起始位置,默认为0
|
||||
* @param toPos 目标数组起始位置,默认为0
|
||||
* @param length 要复制的元素数量,默认为源数组从起始位置到末尾的长度
|
||||
* @throws IndexOutOfBoundsException 当索引超出数组边界时抛出
|
||||
*/
|
||||
@Throws(IndexOutOfBoundsException::class)
|
||||
fun arrayCopy(from: CharArray, to: CharArray, fromPos: Int = 0, toPos: Int = 0, length: Int = from.size - fromPos) {
|
||||
System.arraycopy(from, fromPos, to, toPos, length)
|
||||
}
|
||||
|
||||
/**
|
||||
* 扩展函数:将当前字符型数组元素复制到目标数组
|
||||
* @param to 目标字符型数组
|
||||
* @param fromPos 源数组起始位置,默认为0
|
||||
* @param toPos 目标数组起始位置,默认为0
|
||||
* @param length 要复制的元素数量,默认为源数组从起始位置到末尾的长度
|
||||
* @throws IndexOutOfBoundsException 当索引超出数组边界时抛出
|
||||
* @throws ArrayStoreException 当类型不匹配时抛出
|
||||
*/
|
||||
@JvmSynthetic
|
||||
@Throws(IndexOutOfBoundsException::class, ArrayStoreException::class)
|
||||
fun CharArray.copyTo(to: CharArray, fromPos: Int = 0, toPos: Int = 0, length: Int = this.size - fromPos) {
|
||||
System.arraycopy(this, fromPos, to, toPos, length)
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制整个字符型数组到目标数组(重载版本)
|
||||
* @param from 源字符型数组
|
||||
* @param to 目标字符型数组
|
||||
* @throws IndexOutOfBoundsException 当索引超出数组边界时抛出
|
||||
*/
|
||||
@Throws(IndexOutOfBoundsException::class)
|
||||
fun arrayCopy(from: CharArray, to: CharArray) {
|
||||
arrayCopy(from, to, 0, 0, from.size)
|
||||
@JvmName("arrayCopyFrom")
|
||||
fun ShortArray.copyFrom(src: ShortArray, srcPos: Int, distPos: Int, len: Int): ShortArray = this.also {
|
||||
System.arraycopy(src, srcPos, this, distPos, len)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user