Class ObjId

java.lang.Object
io.permazen.core.ObjId
All Implemented Interfaces:
Serializable, Comparable<ObjId>

@Immutable public final class ObjId extends Object implements Comparable<ObjId>, Serializable
Object IDs. Instances identify individual Database objects.
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The number of bytes in the binary encoding of an ObjId.
    static final Pattern
    Regular expression that matches the string encoding of an ObjId.
  • Constructor Summary

    Constructors
    Constructor
    Description
    ObjId(int storageId)
    Create a new, random instance with the given storage ID.
    ObjId(long value)
    Constructor using a long value previously returned by asLong().
    ObjId(ByteReader reader)
    Constructor that reads an encoded instance from the given ByteReader.
    ObjId(String string)
    Constructor that parses a string previously returned by toString().
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    Get this instance encoded as a long value.
    int
     
    boolean
     
    byte[]
    Get the binary encoding of this instance.
    static KeyRange
    getKeyRange(int storageId)
    Get the KeyRange containing all object IDs with the given storage ID.
    static ObjId
    getMax(int storageId)
    Get the largest (i.e., last) instance having the given storage ID.
    static ObjId
    getMin(int storageId)
    Get the smallest (i.e., first) instance having the given storage ID.
    int
    Get the storage ID associated with this instance.
    int
    Returns the hash code value for this instance.
    Encode this instance as a string.
    void
    Write the binary encoding of this instance to the given output.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • NUM_BYTES

      public static final int NUM_BYTES
      The number of bytes in the binary encoding of an ObjId.
      See Also:
    • PATTERN

      public static final Pattern PATTERN
      Regular expression that matches the string encoding of an ObjId.
  • Constructor Details

    • ObjId

      public ObjId(int storageId)
      Create a new, random instance with the given storage ID.
      Parameters:
      storageId - storage ID, must be greater than zero
      Throws:
      IllegalArgumentException - if storageId is zero or negative
    • ObjId

      public ObjId(String string)
      Constructor that parses a string previously returned by toString().
      Parameters:
      string - string encoding of an instance
      Throws:
      IllegalArgumentException - if string is invalid
    • ObjId

      public ObjId(ByteReader reader)
      Constructor that reads an encoded instance from the given ByteReader.
      Parameters:
      reader - input for binary encoding of an instance
      Throws:
      IllegalArgumentException - if reader contains invalid data
    • ObjId

      public ObjId(long value)
      Constructor using a long value previously returned by asLong().
      Parameters:
      value - long encoding of an instance
      Throws:
      IllegalArgumentException - if value is invalid
  • Method Details

    • getStorageId

      public int getStorageId()
      Get the storage ID associated with this instance. This is the storage ID of the associated object type.
      Returns:
      object type storage ID
    • getBytes

      public byte[] getBytes()
      Get the binary encoding of this instance.
      Returns:
      binary encoding
    • asLong

      public long asLong()
      Get this instance encoded as a long value.
      Returns:
      long encoding
    • writeTo

      public void writeTo(ByteWriter writer)
      Write the binary encoding of this instance to the given output.
      Parameters:
      writer - destination
    • getMin

      public static ObjId getMin(int storageId)
      Get the smallest (i.e., first) instance having the given storage ID.
      Parameters:
      storageId - storage ID, must be greater than zero
      Returns:
      smallest instance with storage ID storageId (inclusive)
      Throws:
      IllegalArgumentException - if storageId is zero or negative
    • getMax

      public static ObjId getMax(int storageId)
      Get the largest (i.e., last) instance having the given storage ID.
      Parameters:
      storageId - storage ID, must be greater than zero
      Returns:
      largest instance with storage ID storageId (inclusive)
      Throws:
      IllegalArgumentException - if storageId is zero or negative
    • getKeyRange

      public static KeyRange getKeyRange(int storageId)
      Get the KeyRange containing all object IDs with the given storage ID.
      Parameters:
      storageId - storage ID, must be greater than zero
      Returns:
      KeyRange containing all object IDs having the specified type
      Throws:
      IllegalArgumentException - if storageId is zero or negative
    • toString

      public String toString()
      Encode this instance as a string.
      Overrides:
      toString in class Object
    • equals

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

      public int hashCode()
      Returns the hash code value for this instance.

      The hash code of an ObjId is defined as the hash code of its asLong() value, which is defined as the exclusive-or of the upper and lower 32 bits.

      Overrides:
      hashCode in class Object
    • compareTo

      public int compareTo(ObjId that)
      Specified by:
      compareTo in interface Comparable<ObjId>