Class Booleans
java.lang.Object
cloud.opencode.base.core.primitives.Booleans
Boolean Array Utility Class - Guava-style operations for boolean primitive arrays
boolean 数组工具类 - Guava 风格的 boolean 原始类型数组操作
Provides comprehensive boolean array operations inspired by Guava Booleans.
提供 boolean 原始类型数组的操作方法。
Features | 主要功能:
- Array operations (concat, contains, indexOf, lastIndexOf) - 数组操作
- Collection conversion (asList, toArray) - 集合转换
- Array manipulation (reverse) - 数组操作
- Comparison (compare) - 比较
- Counting (countTrue) - 统计
- String operations (join) - 字符串操作
Usage Examples | 使用示例:
// Array operations - 数组操作
boolean[] merged = Booleans.concat(arr1, arr2);
boolean found = Booleans.contains(arr, true);
int count = Booleans.countTrue(arr);
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
FieldsModifier and TypeFieldDescriptionstatic final boolean[]Empty boolean array constant | 空 boolean 数组常量 -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanand(boolean... array) Returns true if all values are true (logical AND) | 所有值为 true 时返回 true(逻辑与)asList(boolean... array) Converts a boolean array to a List | 将 boolean 数组转换为 Liststatic intcompare(boolean a, boolean b) Compares two boolean values | 比较两个 boolean 值static boolean[]concat(boolean[]... arrays) Concatenates multiple boolean arrays | 合并多个 boolean 数组static booleancontains(boolean[] array, boolean target) Checks if the array contains the target | 检查数组是否包含目标值static intcountFalse(boolean... array) Counts the number of false values | 统计 false 值的数量static intcountTrue(boolean... array) Counts the number of true values | 统计 true 值的数量static boolean[]ensureNonNull(boolean[] array) Returns the array itself or an empty array if null | 返回数组本身,若为 null 则返回空数组static intindexOf(boolean[] array, boolean target) Returns the first index of the target | 返回目标值的首个索引static StringJoins boolean values with a separator | 用分隔符连接 boolean 值static intlastIndexOf(boolean[] array, boolean target) Returns the last index of the target | 返回目标值的最后索引static booleanor(boolean... array) Returns true if any value is true (logical OR) | 任一值为 true 时返回 true(逻辑或)static voidreverse(boolean[] array) Reverses the array in-place | 原地反转数组static boolean[]toArray(Collection<Boolean> collection) Converts a Collection to a boolean array | 将 Collection 转换为 boolean 数组static booleanxor(boolean... array) Returns true if an odd number of values are true (logical XOR) | 奇数个 true 时返回 true(逻辑异或)
-
Field Details
-
EMPTY_ARRAY
public static final boolean[] EMPTY_ARRAYEmpty boolean array constant | 空 boolean 数组常量
-
-
Method Details
-
concat
public static boolean[] concat(boolean[]... arrays) Concatenates multiple boolean arrays | 合并多个 boolean 数组 -
contains
public static boolean contains(boolean[] array, boolean target) Checks if the array contains the target | 检查数组是否包含目标值 -
indexOf
public static int indexOf(boolean[] array, boolean target) Returns the first index of the target | 返回目标值的首个索引 -
lastIndexOf
public static int lastIndexOf(boolean[] array, boolean target) Returns the last index of the target | 返回目标值的最后索引 -
compare
public static int compare(boolean a, boolean b) Compares two boolean values | 比较两个 boolean 值 -
asList
-
toArray
Converts a Collection to a boolean array | 将 Collection 转换为 boolean 数组 -
reverse
public static void reverse(boolean[] array) Reverses the array in-place | 原地反转数组 -
countTrue
public static int countTrue(boolean... array) Counts the number of true values | 统计 true 值的数量 -
countFalse
public static int countFalse(boolean... array) Counts the number of false values | 统计 false 值的数量 -
and
public static boolean and(boolean... array) Returns true if all values are true (logical AND) | 所有值为 true 时返回 true(逻辑与) -
or
public static boolean or(boolean... array) Returns true if any value is true (logical OR) | 任一值为 true 时返回 true(逻辑或) -
xor
public static boolean xor(boolean... array) Returns true if an odd number of values are true (logical XOR) | 奇数个 true 时返回 true(逻辑异或) -
join
-
ensureNonNull
public static boolean[] ensureNonNull(boolean[] array) Returns the array itself or an empty array if null | 返回数组本身,若为 null 则返回空数组
-