NumericalID

通过一个数字作为ID值的 ID 实现。主要有2个子抽象类型:

并由此扩展为4个具体的 ID 类型,按照最大可表示的数值按顺序为:

如果想要作为ID的数字已经超过64位无符号 (ULongID) 锁能表示的最大数字, 那么建议使用其他类型来表示,例如字符串ID StringID 或 UUID (UUID,也可以算是一个128位数字的ID)

序列化

自 4.14.1 开始,NumericalID 支持序列化。 它默认使用可表示有符号数字ID的最大容量类型为序列化和反序列化目标,也就是 Long。 因此它反序列化的类型始终为 LongID。

See also

Inheritors

Constructors

Link copied to clipboard
protected constructor()

Types

Link copied to clipboard
object Companion

Inherited properties

Link copied to clipboard

同 ID.toString, 得到 ID 的字面值。

Functions

Link copied to clipboard
protected abstract fun compareNumber(target: NumericalID): Int
Link copied to clipboard
operator override fun compareTo(other: ID): Int
Link copied to clipboard
abstract fun toByte(): Byte

将数字值转化为 Byte。类似于 Number.toByte

Link copied to clipboard
abstract fun toDouble(): Double

将数字值转化为 Double。类似于 Number.toDouble

Link copied to clipboard
abstract fun toFloat(): Float

将数字值转化为 Float。类似于 Number.toFloat

Link copied to clipboard
abstract fun toInt(): Int

将数字值转化为 Int。类似于 Number.toInt

Link copied to clipboard
abstract fun toLong(): Long

将数字值转化为 Long。类似于 Number.toLong

Link copied to clipboard
abstract fun toShort(): Short

将数字值转化为 Short。类似于 Number.toShort

Link copied to clipboard
open fun toUInt(): UInt

将数字值转化为 UInt。

Link copied to clipboard
open fun toULong(): ULong

将数字值转化为 ULong。

Inherited functions

Link copied to clipboard
abstract fun copy(): ID

复制一个当前ID。

Link copied to clipboard
abstract operator override fun equals(other: Any?): Boolean

判断另外一个 ID 是否与当前 ID 字面值相同。

Link copied to clipboard
abstract fun equalsExact(other: Any?): Boolean

判断另外一个 ID 是否与当前 ID 字面值与类型均相同。

Link copied to clipboard
abstract override fun hashCode(): Int

ID 的源值 hashcode,等于对应的源值的 hashcode。

Link copied to clipboard
@JvmName(name = "toInt")
inline fun ID.toInt(notNumerical: ID.() -> Int = { literal.toInt() }): Int

尝试将 this 转化为 Int。 如果为 NumericalID 则直接使用 NumericalID.toInt, 否则使用 notNumerical 转化。默认会尝试使用 literal.toInt()。

Link copied to clipboard
@JvmName(name = "toIntID")
inline fun ID.toIntID(notNumerical: ID.() -> IntID = { literal.toInt().ID }): IntID

尝试将 this 转为 IntID 类型。 如果不是数字ID,则会使用 notNumerical 获取结果。默认使用 String.toInt。

Link copied to clipboard
@JvmName(name = "toIntOrNull")
inline fun ID.toIntOrNull(notNumerical: ID.() -> Int? = { literal.toIntOrNull() }): Int?

尝试将 this 转化为 Int。 如果为 NumericalID 则直接使用 NumericalID.toInt, 否则使用 notNumerical 转化。默认会尝试使用 literal.toIntOrNull()。

Link copied to clipboard
@JvmName(name = "toLong")
inline fun ID.toLong(notNumerical: ID.() -> Long = { literal.toLong() }): Long

尝试将 this 转化为 Long。 如果为 NumericalID 则直接使用 NumericalID.toLong, 否则使用 notNumerical 转化。默认会尝试使用 literal.toLong()。

Link copied to clipboard
@JvmName(name = "toLongID")
inline fun ID.toLongID(notNumerical: ID.() -> LongID = { literal.toLong().ID }): LongID

尝试将 this 转为 LongID 类型。 如果不是数字ID,则会使用 notNumerical 获取结果。默认使用 String.toLong。

Link copied to clipboard
@JvmName(name = "toLongOrNull")
inline fun ID.toLongOrNull(notNumerical: ID.() -> Long? = { literal.toLongOrNull() }): Long?

尝试将 this 转化为 Long。 如果为 NumericalID 则直接使用 NumericalID.toLong, 否则使用 notNumerical 转化。默认会尝试使用 literal.toLongOrNull()。

Link copied to clipboard
abstract override fun toString(): String

ID 的 字面值 字符串。

Link copied to clipboard
@JvmName(name = "toUInt")
inline fun ID.toUInt(notNumerical: ID.() -> UInt = { literal.toUInt() }): UInt

尝试将 this 转化为 UInt。 如果为 NumericalID 则直接使用 NumericalID.toInt.toUInt, 否则使用 notNumerical 转化。默认会尝试使用 literal.toUInt()。

Link copied to clipboard
@JvmName(name = "toUIntID")
inline fun ID.toUIntID(notNumerical: ID.() -> UIntID = { literal.toUInt().ID }): UIntID

尝试将 this 转为 UIntID 类型。 如果不是数字ID,则会使用 notNumerical 获取结果。默认使用 String.toUInt。

Link copied to clipboard
@JvmName(name = "toUIntOrNull")
inline fun ID.toUIntOrNull(notNumerical: ID.() -> UInt? = { literal.toUIntOrNull() }): UInt?

尝试将 this 转化为 UInt。 如果为 NumericalID 则直接使用 NumericalID.toInt.toUInt, 否则使用 notNumerical 转化。默认会尝试使用 literal.toUIntOrNull()。

Link copied to clipboard
@JvmName(name = "toULong")
inline fun ID.toULong(notNumerical: ID.() -> ULong = { literal.toULong() }): ULong

尝试将 this 转化为 ULong。 如果为 NumericalID 则直接使用 NumericalID.toLong.toULong, 否则使用 notNumerical 转化。默认会尝试使用 literal.toULong()。

Link copied to clipboard
@JvmName(name = "toULongID")
inline fun ID.toULongID(notNumerical: ID.() -> ULongID = { literal.toULong().ID }): ULongID

尝试将 this 转为 ULongID 类型。 如果不是数字ID,则会使用 notNumerical 获取结果。默认使用 String.toULong。

Link copied to clipboard
@JvmName(name = "toULongOrNull")
inline fun ID.toULongOrNull(notNumerical: ID.() -> ULong? = { literal.toULongOrNull() }): ULong?

尝试将 this 转化为 ULong。 如果为 NumericalID 则直接使用 NumericalID.toLong.toULong, 否则使用 notNumerical 转化。默认会尝试使用 literal.toULongOrNull()。