Class OpenStringBase
java.lang.Object
cloud.opencode.base.core.OpenStringBase
Basic String Utility Class - Minimal string operations for core module
基础字符串工具类 - 核心模块的最小化字符串操作
Provides minimal string methods for core module. For full string functionality, use OpenString from String component.
提供最小化的基础字符串方法集。完整字符串功能请使用 String 组件的 OpenString。
Features | 主要功能:
- Empty/Blank checking (isEmpty, isBlank, hasLength, hasText) - 空值检查
- Default value handling (defaultIfEmpty, defaultIfBlank, nullToEmpty) - 默认值处理
- Trim operations (trim, trimToNull, trimToEmpty) - 裁剪操作
- Comparison (equals, equalsIgnoreCase) - 比较
- Case conversion (toLowerCase, toUpperCase) - 大小写转换
- Pattern matching (startsWith, endsWith, contains) - 模式匹配
Usage Examples | 使用示例:
// Empty checking - 空值检查
boolean empty = OpenStringBase.isEmpty(str);
boolean blank = OpenStringBase.isBlank(" "); // true
// Default value - 默认值
String value = OpenStringBase.defaultIfBlank(str, "default");
String trimmed = OpenStringBase.trimToEmpty(str);
// Comparison - 比较
boolean eq = OpenStringBase.equals(s1, s2);
Security | 安全性:
- Thread-safe: Yes (stateless) - 线程安全: 是 (无状态)
- Null-safe: Yes - 空值安全: 是
- Since:
- JDK 25, opencode-base-core V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic booleancontains(CharSequence str, CharSequence searchStr) Checks if the string contains the specified substring 检查是否包含指定子串static StringdefaultIfBlank(String str, String defaultValue) Returns default value when blank 空白时返回默认值static StringdefaultIfEmpty(String str, String defaultValue) Returns default value when empty 空时返回默认值static StringemptyToNull(String str) Converts empty string to null 空字符串转为 nullstatic booleanChecks if the string ends with the specified suffix 检查是否以指定后缀结束static booleanequals(CharSequence cs1, CharSequence cs2) Null-safe string comparison null 安全的字符串比较static booleanequalsIgnoreCase(String str1, String str2) Null-safe case-insensitive comparison null 安全的忽略大小写比较static booleanChecks if it has length (non-null and length > 0) 检查是否有长度(非 null 且长度 > 0)static booleanhasText(CharSequence cs) Checks if it has text (non-blank) 检查是否有文本(非空白)static booleanisBlank(CharSequence cs) Checks if blank (null, empty, or contains only whitespace) 检查是否为空白(null、空或只包含空白字符)static booleanisEmpty(CharSequence cs) Checks if empty (null or length is 0) 检查是否为空(null 或长度为 0)static booleanChecks if not blank 检查是否非空白static booleanChecks if not empty 检查是否非空static intlength(CharSequence cs) Gets length in a null-safe manner null 安全获取长度static StringnullToEmpty(String str) Converts null to empty string null 转为空字符串static booleanstartsWith(String str, String prefix) Checks if the string starts with the specified prefix 检查是否以指定前缀开始static StringtoLowerCase(String str) Safe lowercase conversion 安全转小写static StringtoUpperCase(String str) Safe uppercase conversion 安全转大写static StringSafe trim 安全 trimstatic StringtrimToEmpty(String str) Returns empty string if empty after trim trim 后为空则返回空字符串static StringtrimToNull(String str) Returns null if empty after trim trim 后为空则返回 null
-
Field Details
-
EMPTY
-
SPACE
-
-
Method Details
-
isEmpty
Checks if empty (null or length is 0) 检查是否为空(null 或长度为 0) -
isNotEmpty
Checks if not empty 检查是否非空 -
isBlank
Checks if blank (null, empty, or contains only whitespace) 检查是否为空白(null、空或只包含空白字符) -
isNotBlank
Checks if not blank 检查是否非空白 -
hasLength
Checks if it has length (non-null and length > 0) 检查是否有长度(非 null 且长度 > 0) -
hasText
Checks if it has text (non-blank) 检查是否有文本(非空白) -
length
Gets length in a null-safe manner null 安全获取长度 -
defaultIfEmpty
-
defaultIfBlank
-
nullToEmpty
-
emptyToNull
-
trimToNull
-
trimToEmpty
-
equals
Null-safe string comparison null 安全的字符串比较 -
equalsIgnoreCase
-
trim
-
toLowerCase
-
toUpperCase
-
startsWith
-
endsWith
-
contains
Checks if the string contains the specified substring 检查是否包含指定子串
-