Skip to content

refactor: convert RandomStringUtils from Java to Kotlin with enhanced KDoc#86

Open
cto-new[bot] wants to merge 3 commits intomasterfrom
cto/randomstringutils-kotlinkdoc-e01
Open

refactor: convert RandomStringUtils from Java to Kotlin with enhanced KDoc#86
cto-new[bot] wants to merge 3 commits intomasterfrom
cto/randomstringutils-kotlinkdoc-e01

Conversation

@cto-new
Copy link
Contributor

@cto-new cto-new bot commented Feb 25, 2026

Summary

RandomStringUtils 从 Java 转换为 Kotlin,并完善了 KDoc 文档。

Changes

1. 转换为 Kotlin

  • 删除了 RandomStringUtils.java
  • 新建了 RandomStringUtils.kt
  • 使用 @file:JvmName("RandomStringUtils") 保持 Java 兼容性
  • 移除了不必要的 @JvmStatic 注解(顶层函数自动编译为静态方法)

2. 完善 KDoc 文档

  • 添加了文件级别的 KDoc,说明工具类的功能和线程安全性
  • 为每个公共方法添加了详细的 KDoc,包括:
    • 方法功能描述
    • 参数说明
    • 返回值说明
    • 使用示例(@sample 标签)
  • 私有常量使用自解释命名,无需额外注释

3. Kotlin 惯用法优化

  • 使用 buildString() 替代 StringBuilder
  • 使用 repeat() 替代 for 循环
  • 使用 List(size) { ... } 构建列表
  • 使用 emptyList() 替代 Collections.emptyList()
  • 使用 filterNotNull() 处理可空列表转换

4. 命名改进

私有常量重命名为自解释形式:

  • SRC_NUMBERNUMERIC_CHARS
  • SRC_LOWER / SRC_UPPERLOWERCASE_LETTERS / UPPERCASE_LETTERS
  • SRC_HEX_LOWER / SRC_HEX_UPPERHEX_LOWERCASE_CHARS / HEX_UPPERCASE_CHARS
  • ESC_CHARPLACEHOLDER_CHAR
  • lockerLOCK

5. Bug Fixes

  • 修复了 subStringByLength 返回类型不匹配的问题,添加了 .filterNotNull()

Backward Compatibility

  • 完全向后兼容,Java 测试代码无需修改
  • 类名和方法签名保持不变

Powered by CTO.new

@github-actions
Copy link

github-actions bot commented Feb 25, 2026

Test Results

185 tests  ±0   184 ✅ ±0   21s ⏱️ ±0s
 53 suites ±0     1 💤 ±0 
 53 files   ±0     0 ❌ ±0 

Results for commit ffae552. ± Comparison against base commit 9c7e4b7.

♻️ This comment has been updated with latest results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants