Class ObjectId

java.lang.Object
com.walkfares.odsl.util.ObjectId

public class ObjectId
extends Object
  • Constructor Summary

    Constructors 
    Constructor Description
    ObjectId()
    Create a new object id.
    ObjectId​(byte[] bytes)
    Constructs a new instance from the given byte array
    ObjectId​(int timestamp, int counter)
    Creates an ObjectId using the given time, machine identifier, process identifier, and counter.
    ObjectId​(String hexString)
    Constructs a new instance from a 24-byte hexadecimal string representation.
    ObjectId​(ByteBuffer buffer)
    Constructs a new instance from the given ByteBuffer
    ObjectId​(Date date)
    Constructs a new instance using the given date.
    ObjectId​(Date date, int counter)
    Constructs a new instances using the given date and counter.
  • Method Summary

    Modifier and Type Method Description
    boolean equals​(Object o)  
    static ObjectId get()
    Gets a new object id.
    Date getDate()
    Gets the timestamp as a Date instance.
    static ObjectId getSmallestWithDate​(Date date)
    Gets a new object id with the given date value and all other bits zeroed.
    int getTimestamp()
    Gets the timestamp (number of seconds since the Unix epoch).
    int hashCode()  
    static void isTrue​(String name, boolean condition)
    Throw IllegalStateException if the condition if false.
    static void isTrueArgument​(String name, boolean condition)  
    static <T> T isTrueArgument​(String name, T value, boolean condition)  
    static boolean isValid​(String hexString)
    Checks if a string could be an ObjectId.
    static <T> T notNull​(String name, T value)  
    void putToByteBuffer​(ByteBuffer buffer)
    Convert to bytes and put those bytes to the provided ByteBuffer.
    byte[] toByteArray()
    Convert to a byte array.
    String toHexString()
    Converts this instance into a 24-byte hexadecimal string representation.
    String toString()  

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • ObjectId

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

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

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

      public ObjectId​(int timestamp, int counter)
      Creates an ObjectId using the given time, machine identifier, process identifier, and counter.
      Parameters:
      timestamp - the time in seconds
      counter - the counter
      Throws:
      IllegalArgumentException - if the high order byte of counter is not zero
    • ObjectId

      public ObjectId​(String hexString)
      Constructs a new instance from a 24-byte hexadecimal string representation.
      Parameters:
      hexString - the string to convert
      Throws:
      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
      Parameters:
      bytes - the byte array
      Throws:
      IllegalArgumentException - if array is null or not of length 12
    • ObjectId

      public ObjectId​(ByteBuffer buffer)
      Constructs a new instance from the given ByteBuffer
      Parameters:
      buffer - the ByteBuffer
      Throws:
      IllegalArgumentException - if the buffer is null or does not have at least 12 bytes remaining
      Since:
      3.4
  • Method Details

    • get

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

      public static ObjectId getSmallestWithDate​(Date date)
      Gets a new object id with the given date value and all other bits zeroed.

      The returned object id will compare as less than or equal to any other object id within the same second as the given date, and less than any later date.

      Parameters:
      date - the date
      Returns:
      the ObjectId
      Since:
      4.1
    • isValid

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

      public static <T> T notNull​(String name, T value)
    • isTrue

      public static void isTrue​(String name, boolean condition)
      Throw IllegalStateException if the condition if false.
      Parameters:
      name - the name of the state that is being checked
      condition - the condition about the parameter to check
      Throws:
      IllegalStateException - if the condition is false
    • isTrueArgument

      public static void isTrueArgument​(String name, boolean condition)
    • isTrueArgument

      public static <T> T isTrueArgument​(String name, T value, boolean condition)
    • toByteArray

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

      public void putToByteBuffer​(ByteBuffer buffer)
      Convert to bytes and put those bytes to the provided ByteBuffer. Note that the numbers are stored in big-endian order.
      Parameters:
      buffer - the ByteBuffer
      Throws:
      IllegalArgumentException - if the buffer is null or does not have at least 12 bytes remaining
      Since:
      3.4
    • 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
    • toHexString

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

      public boolean equals​(Object o)
      Overrides:
      equals in class Object
    • hashCode

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

      public String toString()
      Overrides:
      toString in class Object