Skip to content

Commit 8c1f96c

Browse files
committed
NumericalID 增加两个toUxx
1 parent 5d2e9bc commit 8c1f96c

File tree

1 file changed

+16
-2
lines changed
  • simbot-commons/simbot-common-core/src/commonMain/kotlin/love/forte/simbot/common/id

1 file changed

+16
-2
lines changed

simbot-commons/simbot-common-core/src/commonMain/kotlin/love/forte/simbot/common/id/ID.kt

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -645,11 +645,23 @@ public sealed class NumericalID : ID() {
645645
*/
646646
public abstract fun toLong(): Long
647647

648+
/**
649+
* 将数字值转化为 [ULong]。
650+
*/
651+
public open fun toULong(): ULong =
652+
toLong().toULong()
653+
648654
/**
649655
* 将数字值转化为 [Int]。类似于 [Number.toInt]
650656
*/
651657
public abstract fun toInt(): Int
652658

659+
/**
660+
* 将数字值转化为 [UInt]。
661+
*/
662+
public open fun toUInt(): UInt =
663+
toInt().toUInt()
664+
653665
/**
654666
* 将数字值转化为 [Short]。类似于 [Number.toShort]
655667
*/
@@ -683,7 +695,7 @@ public sealed class NumericalID : ID() {
683695
* - [IntID] 32位有符号整型
684696
* - [LongID] 64位有符号整型
685697
*
686-
* 如果想要作为ID的数字已经超过64位有符号 ([LongID]) 锁能表示的最大数字
698+
* 如果想要作为ID的数字已经超过64位有符号 ([LongID]) 所能表示的最大数字
687699
* 那么建议使用其他类型来表示,例如 [ULongID] 或 [StringID]
688700
*
689701
*
@@ -698,7 +710,7 @@ public sealed class SignedNumericID : NumericalID()
698710
* - [UIntID] 32位无符号整型
699711
* - [ULongID] 64位无符号整型
700712
*
701-
* 如果想要作为ID的数字已经超过64位无符号 ([ULongID]) 锁能表示的最大数字
713+
* 如果想要作为ID的数字已经超过64位无符号 ([ULongID]) 所能表示的最大数字
702714
* 那么建议使用其他类型来表示,例如 [StringID]
703715
*
704716
* 在 Java 中对无符号数字的操作需要有些注意的地方。
@@ -782,6 +794,7 @@ public class UIntID private constructor(@get:JvmName("getValue") public val valu
782794
override fun toFloat(): Float = value.toFloat()
783795
override fun toLong(): Long = value.toLong()
784796
override fun toInt(): Int = value.toInt()
797+
override fun toUInt(): UInt = value
785798
override fun toShort(): Short = value.toShort()
786799
override fun toByte(): Byte = value.toByte()
787800
override fun toString(): String = value.toString()
@@ -895,6 +908,7 @@ public class ULongID private constructor(@get:JvmName("getValue") public val val
895908
override fun toDouble(): Double = value.toDouble()
896909
override fun toFloat(): Float = value.toFloat()
897910
override fun toLong(): Long = value.toLong()
911+
override fun toULong(): ULong = value
898912
override fun toInt(): Int = value.toInt()
899913
override fun toShort(): Short = value.toShort()
900914
override fun toByte(): Byte = value.toByte()

0 commit comments

Comments
 (0)