类 ObjectId

java.lang.Object
net.apexes.commons.lang.ObjectId
所有已实现的接口:
Serializable, Comparable<ObjectId>

public final class ObjectId extends Object implements Comparable<ObjectId>, Serializable

A globally unique identifier for objects.

Consists of 12 bytes, divided as follows:

ObjectID layout
01234567891011
timemachine pidinc

Instances of this class are immutable.

另请参阅:
  • 构造器详细资料

    • ObjectId

      public ObjectId()
      Create a new object id.
    • ObjectId

      public ObjectId(Date date)
      Constructs a new instance using the given date.
      参数:
      date - the date
    • ObjectId

      public ObjectId(Date date, int counter)
      Constructs a new instances using the given date and counter.
      参数:
      date - the date
      counter - the counter
      抛出:
      IllegalArgumentException - if the high order byte of counter is not zero
    • ObjectId

      public ObjectId(Date date, int machineIdentifier, int counter)
      Constructs a new instances using the given date, machine identifier, and counter.
      参数:
      date - the date
      machineIdentifier - the machine identifier
      counter - the counter
      抛出:
      IllegalArgumentException - if the high order byte of machineIdentifier or counter is not zero
    • ObjectId

      public ObjectId(int timestamp, int machineIdentifier, int counter)
      Creates an ObjectId using the given time, machine identifier, and counter.
      参数:
      timestamp - the time in seconds
      machineIdentifier - the machine identifier
      counter - the counter
      抛出:
      IllegalArgumentException - if the high order byte of machineIdentifier or counter is not zero
    • ObjectId

      public ObjectId(String hexString)
      Constructs a new instance from a 24-byte hexadecimal string representation.
      参数:
      hexString - the string to convert
      抛出:
      IllegalArgumentException - if the string is not a valid hex string representation of an ObjectId
    • ObjectId

      public ObjectId(byte[] bytes)
      Constructs a new instance from the given byte array
      参数:
      bytes - the byte array
      抛出:
      IllegalArgumentException - if array is null or not of length 12
  • 方法详细资料

    • get

      public static ObjectId get()
      Gets a new object id.
      返回:
      the new id
    • isValid

      public static boolean isValid(String hexString)
      Checks if a string could be an ObjectId.
      参数:
      hexString - a potential ObjectId as a String.
      返回:
      whether the string could be an object id
      抛出:
      IllegalArgumentException - if hexString is null
    • getGeneratedMachineIdentifier

      public static int getGeneratedMachineIdentifier()
      Gets the generated machine identifier.
      返回:
      an int representing the machine identifier
    • getCurrentCounter

      public static int getCurrentCounter()
      Gets the current value of the auto-incrementing counter.
      返回:
      the current counter value.
    • createFromLegacyFormat

      public static ObjectId createFromLegacyFormat(int time, int machine, int inc)

      Creates an ObjectId using time, machine and inc values. The Java driver used to create all ObjectIds this way, but it does not match the ObjectId specification, which requires four values, not three. This major release of the Java driver conforms to the specification, but still supports clients that are relying on the behavior of the previous major release by providing this explicit factory method that takes three parameters instead of four.

      Ordinary users of the driver will not need this method. It's only for those that have written there own BSON decoders.

      NOTE: This will not break any application that use ObjectIds. The 12-byte representation will be round-trippable from old to new driver releases.

      参数:
      time - time in seconds
      machine - machine ID
      inc - incremental value
      返回:
      a new ObjectId created from the given values
      从以下版本开始:
      2.12.0
    • toByteArray

      public byte[] toByteArray()
      Convert to a byte array. Note that the numbers are stored in big-endian order.
      返回:
      the byte array
    • getTimestamp

      public int getTimestamp()
      Gets the timestamp (number of seconds since the Unix epoch).
      返回:
      the timestamp
    • getMachineIdentifier

      public int getMachineIdentifier()
      Gets the machine identifier.
      返回:
      the machine identifier
    • getProcessIdentifier

      public short getProcessIdentifier()
      Gets the process identifier.
      返回:
      the process identifier
    • getCounter

      public int getCounter()
      Gets the counter.
      返回:
      the counter
    • getDate

      public Date getDate()
      Gets the timestamp as a Date instance.
      返回:
      the Date
    • toHexString

      public String toHexString()
      Converts this instance into a 24-byte hexadecimal string representation.
      返回:
      a string representation of the ObjectId in hexadecimal format
    • equals

      public boolean equals(Object o)
      覆盖:
      equals 在类中 Object
    • hashCode

      public int hashCode()
      覆盖:
      hashCode 在类中 Object
    • compareTo

      public int compareTo(ObjectId other)
      指定者:
      compareTo 在接口中 Comparable<ObjectId>
    • toString

      public String toString()
      覆盖:
      toString 在类中 Object
    • getTimeSecond

      @Deprecated public int getTimeSecond()
      已过时。
      Use #getTimestamp instead
      Gets the time of this ID, in seconds.
      返回:
      the time component of this ID in seconds
    • getTime

      @Deprecated public long getTime()
      已过时。
      Use #getDate instead
      Gets the time of this instance, in milliseconds.
      返回:
      the time component of this ID in milliseconds
    • toStringMongod

      @Deprecated public String toStringMongod()
      已过时。
      返回:
      a string representation of the ObjectId in hexadecimal format
      另请参阅: