no message
This commit is contained in:
@@ -16,16 +16,14 @@
|
||||
* ProjectName mingli-utils
|
||||
* ModuleName mingli-utils.main
|
||||
* CurrentFile UUID.kt
|
||||
* LastUpdate 2026-01-08 13:21:00
|
||||
* LastUpdate 2026-02-05 11:20:59
|
||||
* UpdateUser MingLiPro
|
||||
*/
|
||||
|
||||
package com.mingliqiye.utils.uuid
|
||||
|
||||
import com.mingliqiye.utils.base.BASE256
|
||||
import com.mingliqiye.utils.base.BASE64
|
||||
import com.mingliqiye.utils.base.BASE91
|
||||
import com.mingliqiye.utils.random.randomByteSecure
|
||||
import com.mingliqiye.utils.base.*
|
||||
import com.mingliqiye.utils.random.randomByte
|
||||
import com.mingliqiye.utils.random.secureRandom
|
||||
import com.mingliqiye.utils.system.macAddressBytes
|
||||
import com.mingliqiye.utils.time.DateTime
|
||||
@@ -109,7 +107,7 @@ class UUID : Serializable {
|
||||
*/
|
||||
@JvmStatic
|
||||
fun getV4(): UUID {
|
||||
val randomBytes = randomByteSecure(16)
|
||||
val randomBytes = randomByte(16)
|
||||
randomBytes[6] = (randomBytes[6].toInt() and 0x0F).toByte()
|
||||
randomBytes[6] = (randomBytes[6].toInt() or 0x40).toByte()
|
||||
randomBytes[8] = (randomBytes[8].toInt() and 0x3F).toByte()
|
||||
@@ -192,7 +190,7 @@ class UUID : Serializable {
|
||||
val buffer = ByteBuffer.allocate(16)
|
||||
buffer.putInt((instant shr 16).toInt())
|
||||
buffer.putShort((instant).toShort())
|
||||
buffer.put(randomByteSecure(2))
|
||||
buffer.put(randomByte(2))
|
||||
buffer.putLong(secureRandom.nextLong())
|
||||
val bytes = buffer.array()
|
||||
bytes[6] = (bytes[6].toInt() and 0x0F or 0x70).toByte()
|
||||
@@ -363,6 +361,10 @@ class UUID : Serializable {
|
||||
return result
|
||||
}
|
||||
|
||||
fun of(str: String, base: BaseType): UUID {
|
||||
return UUID(base.baseCodec.decode(str))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -485,6 +487,18 @@ class UUID : Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
fun getString(uuidFormatType: UUIDFormatType): String {
|
||||
return getString(isUpper = uuidFormatType.isUpper, isnotSpace = uuidFormatType.isnotSpace)
|
||||
}
|
||||
|
||||
fun getString(baseType: BaseType): String {
|
||||
return getString(baseType.baseCodec)
|
||||
}
|
||||
|
||||
fun getString(baseCodec: BaseCodec): String {
|
||||
return baseCodec.encode(data)
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回标准格式的 UUID 字符串(带连字符)。
|
||||
*
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2026 mingliqiye
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ProjectName mingli-utils
|
||||
* ModuleName mingli-utils.main
|
||||
* CurrentFile UUIDFormatType.kt
|
||||
* LastUpdate 2026-02-04 21:54:04
|
||||
* UpdateUser MingLiPro
|
||||
*/
|
||||
|
||||
package com.mingliqiye.utils.uuid
|
||||
|
||||
enum class UUIDFormatType(val isUpper: Boolean, val isnotSpace: Boolean) {
|
||||
UPPER_SPACE(true, false),
|
||||
NO_UPPER_SPACE(false, false),
|
||||
NO_UPPER_NO_SPACE(false, true),
|
||||
UPPER_NO_SPACE(true, true),
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2026 mingliqiye
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ProjectName mingli-utils
|
||||
* ModuleName mingli-utils.main
|
||||
* CurrentFile UUIDJsonFormat.kt
|
||||
* LastUpdate 2026-02-04 22:14:47
|
||||
* UpdateUser MingLiPro
|
||||
*/
|
||||
|
||||
package com.mingliqiye.utils.uuid
|
||||
|
||||
import com.mingliqiye.utils.base.BaseType
|
||||
|
||||
@Target(AnnotationTarget.FIELD)
|
||||
annotation class UUIDJsonFormat(
|
||||
val value: UUIDFormatType = UUIDFormatType.NO_UPPER_SPACE,
|
||||
val base: BaseType = BaseType.BASE16
|
||||
)
|
||||
Reference in New Issue
Block a user