replace IllegalArgumentException with require
This commit is contained in:
@@ -5,8 +5,7 @@ import com.infendro.bytearray.ByteOrder.BIG_ENDIAN
|
||||
fun ByteArray.toInt(
|
||||
order: ByteOrder = BIG_ENDIAN,
|
||||
): Int {
|
||||
if (size != 4)
|
||||
throw IllegalArgumentException()
|
||||
require(size == 4)
|
||||
|
||||
return normalize(order)
|
||||
.fold(0) { acc, byte -> (acc shl 8) or (byte.toInt() and 0xFF) }
|
||||
@@ -27,8 +26,7 @@ fun UByteArray.toUInt(
|
||||
fun ByteArray.toIntArray(
|
||||
order: ByteOrder = BIG_ENDIAN,
|
||||
): IntArray {
|
||||
if (size % 4 != 0)
|
||||
throw IllegalArgumentException()
|
||||
require(size % 4 == 0)
|
||||
|
||||
return asList()
|
||||
.chunked(4) { it.toByteArray().toInt(order) }
|
||||
@@ -94,8 +92,7 @@ fun UIntArray.toUByteArray(
|
||||
fun ByteArray.toLong(
|
||||
order: ByteOrder = BIG_ENDIAN,
|
||||
): Long {
|
||||
if (size != 8)
|
||||
throw IllegalArgumentException()
|
||||
require(size == 8)
|
||||
|
||||
return normalize(order)
|
||||
.fold(0L) { acc, byte -> (acc shl 8) or (byte.toLong() and 0xFFL) }
|
||||
@@ -116,8 +113,7 @@ fun UByteArray.toULong(
|
||||
fun ByteArray.toLongArray(
|
||||
order: ByteOrder = BIG_ENDIAN,
|
||||
): LongArray {
|
||||
if (size % 8 != 0)
|
||||
throw IllegalArgumentException()
|
||||
require(size % 8 == 0)
|
||||
|
||||
return asList()
|
||||
.chunked(8) { it.toByteArray().toLong(order) }
|
||||
|
||||
Reference in New Issue
Block a user