Class ObjectId

    • Constructor Detail

      • ObjectId

        public ObjectId​(byte[] b)
        Constructs an ObjectId given its 12-byte binary representation.
        Parameters:
        b - a byte array of length 12
      • ObjectId

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

      • get

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

        public static boolean isValid​(String s)
        Checks if a string could be an ObjectId.
        Parameters:
        s - a potential ObjectId as a String.
        Returns:
        whether the string could be an object id
        Throws:
        IllegalArgumentException - if hexString is null
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • toHexString

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

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

        public int getTimestamp()
        Gets the timestamp (number of seconds since the Unix epoch).
        Returns:
        the timestamp
      • getDate

        public Date getDate()
        Gets the timestamp as a Date instance.
        Returns:
        the Date
      • getCurrentCounter

        public static int getCurrentCounter()
        Gets the current value of the auto-incrementing counter.
        Returns:
        the current counter value.