refactor(mingli-utils):重构集合工具类并添加新功能
- 重写 Collection 类,使用 Kotlin 语法和特性优化代码结构 - 添加新方法以支持数组和集合之间的转换 - 新增 CopyOnWriteArrayList、Stack 和 TreeSet 相关方法 -优化现有方法,提高代码可读性和性能 - 删除未使用的 ForEach 导入 -调整 build.gradle.kts 中的依赖项
This commit is contained in:
@@ -16,14 +16,13 @@
|
||||
* ProjectName mingli-utils
|
||||
* ModuleName mingli-utils.main
|
||||
* CurrentFile SystemUtil.kt
|
||||
* LastUpdate 2025-09-14 21:56:58
|
||||
* LastUpdate 2025-09-15 08:50:23
|
||||
* UpdateUser MingLiPro
|
||||
*/
|
||||
@file:JvmName("SystemUtils")
|
||||
|
||||
package com.mingliqiye.utils.system
|
||||
|
||||
import com.mingliqiye.utils.collection.Lists
|
||||
import java.net.Inet4Address
|
||||
import java.net.NetworkInterface
|
||||
import java.net.SocketException
|
||||
@@ -90,14 +89,14 @@ fun getJavaVersionAsInteger(): Int {
|
||||
"Invalid Java version format: $version"
|
||||
)
|
||||
}
|
||||
version.substring(2, 3)
|
||||
version[2] + ""
|
||||
} else {
|
||||
if (version.length < 2) {
|
||||
throw IllegalStateException(
|
||||
"Invalid Java version format: $version"
|
||||
)
|
||||
}
|
||||
version.substring(0, 2)
|
||||
version.take(2)
|
||||
}
|
||||
return uversion.toInt()
|
||||
}
|
||||
@@ -151,7 +150,7 @@ fun getLocalIps(): Array<String> {
|
||||
* @return 本地IP地址的字符串列表
|
||||
*/
|
||||
fun getLocalIpsByList(): List<String> {
|
||||
return Lists.newArrayList(*getLocalIps())
|
||||
return getLocalIps().toList()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -179,7 +178,6 @@ fun getLoopbackIps(): Array<String> {
|
||||
}
|
||||
strings.toTypedArray()
|
||||
} catch (e: SocketException) {
|
||||
// 可考虑添加日志记录
|
||||
arrayOf("127.0.0.1")
|
||||
}
|
||||
}
|
||||
@@ -191,5 +189,5 @@ fun getLoopbackIps(): Array<String> {
|
||||
*/
|
||||
fun getLoopbackIpsByList(): List<String> {
|
||||
// 将本地回环地址IP数组转换为列表并返回
|
||||
return Lists.newArrayList(*getLoopbackIps())
|
||||
return getLoopbackIps().toList()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user