Class ContainerUtil
java.lang.Object
cloud.opencode.base.core.container.ContainerUtil
Container Utility - Generic size/empty operations for Collection, Map, Array, CharSequence, Optional
容器工具 - 对 Collection、Map、Array、CharSequence、Optional 的通用 size/empty 操作
Features | 主要功能:
- Generic size() for Collection, Map, Array, CharSequence, Optional - 通用size()方法
- Generic isEmpty()/isNotEmpty() checks - 通用isEmpty()/isNotEmpty()检查
- Pattern matching for type dispatch - 使用模式匹配进行类型分派
Usage Examples | 使用示例:
int size = ContainerUtil.size(List.of(1, 2, 3)); // 3
boolean empty = ContainerUtil.isEmpty(Map.of()); // true
boolean notEmpty = ContainerUtil.isNotEmpty("abc"); // true
Security | 安全性:
- Thread-safe: Yes (stateless utility) - 线程安全: 是(无状态工具类)
- Null-safe: Yes, null returns 0/true for size/isEmpty - 空值安全: 是,null对size返回0,对isEmpty返回true
Performance | 性能特性:
- Time complexity: O(1) per check - 每次检查 O(1)
- Space complexity: O(1) - O(1)
- Since:
- JDK 25, opencode-base-core V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
-
Method Details
-
size
Returns the size of the container object. 返回容器对象的大小。Supported types: Collection, Map, CharSequence, Array, Optional.
- Parameters:
obj- the container object | 容器对象- Returns:
- the size, or -1 if the type is not supported | 大小,不支持的类型返回 -1
-
isEmpty
Checks if the container object is empty. 检查容器对象是否为空。- Parameters:
obj- the container object | 容器对象- Returns:
- true if null, empty, or unsupported type | 如果为 null、空或不支持的类型返回 true
-
isNotEmpty
Checks if the container object is not empty. 检查容器对象是否非空。- Parameters:
obj- the container object | 容器对象- Returns:
- true if not null and not empty | 如果非 null 且非空返回 true
-