Class Shorts
java.lang.Object
cloud.opencode.base.core.primitives.Shorts
Short Array Utility Class - Guava-style operations for short primitive arrays
short 数组工具类 - Guava 风格的 short 原始类型数组操作
Provides comprehensive short array operations inspired by Guava Shorts.
提供 short 原始类型数组的操作方法。
Features | 主要功能:
- Byte conversion (toByteArray, fromByteArray) - 字节转换
- Array operations (concat, contains, indexOf, lastIndexOf) - 数组操作
- Min/Max (min, max, constrainToRange) - 最值和范围
- Collection conversion (asList, toArray) - 集合转换
- Array manipulation (reverse) - 数组操作
- String operations (join, tryParse) - 字符串操作
Usage Examples | 使用示例:
// Array operations - 数组操作
short[] merged = Shorts.concat(arr1, arr2);
short min = Shorts.min(arr);
int idx = Shorts.indexOf(arr, (short) 100);
Security | 安全性:
- Thread-safe: Yes (stateless) - 线程安全: 是 (无状态)
- Null-safe: Partially (throws on null array) - 空值安全: 部分 (null 数组抛异常)
- Since:
- JDK 25, opencode-base-core V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionasList(short... array) static shortcheckedCast(long value) static intcompare(short a, short b) static short[]concat(short[]... arrays) static shortconstrainToRange(short value, short min, short max) static booleancontains(short[] array, short target) static short[]ensureNonNull(short[] array) static shortfromByteArray(byte[] bytes) static intindexOf(short[] array, short target) static Stringstatic intlastIndexOf(short[] array, short target) static shortmax(short... array) static shortmin(short... array) static voidreverse(short[] array) static shortsaturatedCast(long value) static short[]toArray(Collection<? extends Number> collection) static byte[]toByteArray(short value)
-
Field Details
-
BYTES
public static final int BYTES- See Also:
-
EMPTY_ARRAY
public static final short[] EMPTY_ARRAY
-
-
Method Details
-
toByteArray
public static byte[] toByteArray(short value) -
fromByteArray
public static short fromByteArray(byte[] bytes) -
concat
public static short[] concat(short[]... arrays) -
contains
public static boolean contains(short[] array, short target) -
indexOf
public static int indexOf(short[] array, short target) -
lastIndexOf
public static int lastIndexOf(short[] array, short target) -
min
public static short min(short... array) -
max
public static short max(short... array) -
constrainToRange
public static short constrainToRange(short value, short min, short max) -
compare
public static int compare(short a, short b) -
asList
-
toArray
-
reverse
public static void reverse(short[] array) -
saturatedCast
public static short saturatedCast(long value) -
checkedCast
public static short checkedCast(long value) -
join
-
ensureNonNull
public static short[] ensureNonNull(short[] array)
-