Class CaseUtil

java.lang.Object
cloud.opencode.base.string.naming.CaseUtil

public final class CaseUtil extends Object
Naming Case Conversion Utility 命名风格转换工具类

Converts between different naming conventions (camelCase, snake_case, kebab-case, etc.).

在不同命名约定之间转换(驼峰、蛇形、短横线等)。

Features | 主要功能:

  • Convert between 9 naming styles - 9种命名风格互转
  • Auto-detect source naming style - 自动检测源命名风格
  • Preserve acronyms where possible - 尽可能保留缩写
  • Database/Java naming conversion - 数据库/Java命名转换

Usage Examples | 使用示例:

// Convert to camelCase
String camel = CaseUtil.toCamelCase("get_user_name"); // "getUserName"

// Convert to snake_case
String snake = CaseUtil.toSnakeCase("getUserName"); // "get_user_name"

// Convert to kebab-case
String kebab = CaseUtil.toKebabCase("getUserName"); // "get-user-name"

// Auto-detect and convert
String result = CaseUtil.convert("get_user_name", NamingCase.CAMEL_CASE);
// -> "getUserName"

// Detect naming style
NamingCase style = CaseUtil.detect("getUserName"); // CAMEL_CASE

Performance | 性能:

  • Time complexity: O(n) - 时间复杂度: O(n)
  • Space complexity: O(n) - 空间复杂度: O(n)

Security | 安全性:

  • Thread-safe: Yes (stateless utility) - 线程安全: 是(无状态工具类)
  • Null-safe: Yes - 空值安全: 是
Since:
JDK 25, opencode-base-string V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • toCamelCase

      public static String toCamelCase(String name)
      Convert to camelCase. 转换为小驼峰命名。
      Parameters:
      name - the name to convert | 要转换的名称
      Returns:
      camelCase string | 小驼峰字符串
    • toPascalCase

      public static String toPascalCase(String name)
      Convert to PascalCase. 转换为大驼峰命名。
      Parameters:
      name - the name to convert | 要转换的名称
      Returns:
      PascalCase string | 大驼峰字符串
    • toSnakeCase

      public static String toSnakeCase(String name)
      Convert to snake_case. 转换为蛇形命名。
      Parameters:
      name - the name to convert | 要转换的名称
      Returns:
      snake_case string | 蛇形字符串
    • toUpperSnakeCase

      public static String toUpperSnakeCase(String name)
      Convert to UPPER_SNAKE_CASE. 转换为大写蛇形命名。
      Parameters:
      name - the name to convert | 要转换的名称
      Returns:
      UPPER_SNAKE_CASE string | 大写蛇形字符串
    • toKebabCase

      public static String toKebabCase(String name)
      Convert to kebab-case. 转换为短横线命名。
      Parameters:
      name - the name to convert | 要转换的名称
      Returns:
      kebab-case string | 短横线字符串
    • toDotCase

      public static String toDotCase(String name)
      Convert to dot.case. 转换为点分隔命名。
      Parameters:
      name - the name to convert | 要转换的名称
      Returns:
      dot.case string | 点分隔字符串
    • toPathCase

      public static String toPathCase(String name)
      Convert to path/case. 转换为路径命名。
      Parameters:
      name - the name to convert | 要转换的名称
      Returns:
      path/case string | 路径字符串
    • toTitleCase

      public static String toTitleCase(String name)
      Convert to Title Case. 转换为标题形式。
      Parameters:
      name - the name to convert | 要转换的名称
      Returns:
      Title Case string | 标题字符串
    • toSentenceCase

      public static String toSentenceCase(String name)
      Convert to Sentence case. 转换为句子形式。
      Parameters:
      name - the name to convert | 要转换的名称
      Returns:
      Sentence case string | 句子字符串
    • convert

      public static String convert(String name, NamingCase targetCase)
      Convert to specified naming case. 转换为指定的命名风格。
      Parameters:
      name - the name to convert | 要转换的名称
      targetCase - the target naming case | 目标命名风格
      Returns:
      converted string | 转换后的字符串
    • convert

      public static String convert(String name, NamingCase sourceCase, NamingCase targetCase)
      Convert from one naming case to another. 从一种命名风格转换为另一种。
      Parameters:
      name - the name to convert | 要转换的名称
      sourceCase - the source naming case | 源命名风格
      targetCase - the target naming case | 目标命名风格
      Returns:
      converted string | 转换后的字符串
    • detect

      public static NamingCase detect(String name)
      Detect the naming case of a string. 检测字符串的命名风格。
      Parameters:
      name - the name to detect | 要检测的名称
      Returns:
      detected naming case | 检测到的命名风格