Class CompareUtil
java.lang.Object
cloud.opencode.base.core.compare.CompareUtil
Compare Utility - Generic comparison operations for Comparable types
比较工具 - 对 Comparable 类型的通用比较操作
Provides generic comparison operator dispatch (EQ/NE/LT/LE/GT/GE) for any Comparable types, with fallback to string comparison.
为任何 Comparable 类型提供通用比较运算符分派(EQ/NE/LT/LE/GT/GE), 回退到字符串比较。
Features | 主要功能:
- Generic comparison operator dispatch (EQ/NE/LT/LE/GT/GE) - 通用比较运算符分派
- Support for any Comparable types - 支持任何Comparable类型
- Fallback to string comparison - 回退到字符串比较
Usage Examples | 使用示例:
boolean result = CompareUtil.compare(5, 3, CompareUtil.Operator.GT); // true
boolean eq = CompareUtil.compare("a", "a", CompareUtil.Operator.EQ); // true
Security | 安全性:
- Thread-safe: Yes (stateless utility) - 线程安全: 是(无状态工具类)
- Null-safe: No, arguments must not be null - 空值安全: 否,参数不可为null
- Since:
- JDK 25, opencode-base-core V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested Classes -
Method Summary
-
Method Details
-
compare
Compares two Comparable values. Falls back to string comparison for non-Comparable types. 比较两个 Comparable 值。对非 Comparable 类型回退到字符串比较。- Parameters:
first- the first value | 第一个值second- the second value | 第二个值- Returns:
- negative, 0, or positive | 负数、0 或正数
-
equals
Checks if two objects are equal usingObjects.equals(Object, Object). 使用 Objects.equals 检查两个对象是否相等。- Parameters:
first- the first value | 第一个值second- the second value | 第二个值- Returns:
- true if equal | 相等返回 true
-