Interface BigId

All Superinterfaces:
Comparable<BigId>
All Known Implementing Classes:
BigIdBytes, BigIdLong, BigIdZero

public interface BigId extends Comparable<BigId>

Class used to store arbitrary long IDs (i.e. as many bytes as necessary can be encoded, much like BigInteger), along with a scope.

The local ID part is typically used as the database local ID while the combination of scope and ID is used as a public ID (for example by the federated database). The scope must be unique for Id provider in order to be able to form a globally unique ID across providers (e.g. different databases).

Since:
Apr 14, 2022
  • Field Details

    • NONE

      static final BigId NONE
    • NO_LONG_REPRESENTATION

      static final String NO_LONG_REPRESENTATION
      See Also:
    • BYTES_COMPARATOR

      static final Comparator<byte[]> BYTES_COMPARATOR
    • BASE32_ENCODING

      static final com.google.common.io.BaseEncoding BASE32_ENCODING
  • Method Details

    • getScope

      int getScope()
      Returns:
      The scope within which the ID is valid
    • getIdAsBytes

      byte[] getIdAsBytes()
      Returns:
      The value of the ID part as a byte array
    • getIdAsLong

      default long getIdAsLong()
      Returns:
      The value of the ID part as a long
      Throws:
      IllegalArgumentException - if this type of BigId cannot be represented by a single long value
    • size

      default int size()
      Returns:
      Size of the ID part in bytes
    • compareTo

      default int compareTo(BigId other)
      Specified by:
      compareTo in interface Comparable<BigId>
    • equals

      boolean equals(Object other)
      Overrides:
      equals in class Object
    • hashCode

      int hashCode()
      Overrides:
      hashCode in class Object
    • fromBytes

      static BigId fromBytes(int scope, byte[] id)
      Creates a BigId from a scope and an ID part coded as a byte array
      Parameters:
      scope - Integer ID scope (e.g. database number)
      id - Local ID part
      Returns:
      The new immutable BigId instance
    • fromBytes

      static BigId fromBytes(int scope, byte[] buf, int offset, int len)
      Creates a BigId with the given scope and reading the ID part from a portion of a byte array
      Parameters:
      scope - Integer ID scope (e.g. database number)
      buf - Byte array containing the local ID part
      offset - Offset where to start reading the ID in the byte array
      len - Number of bytes to read from the byte array
      Returns:
      The new immutable BigId instance
    • fromLong

      static BigId fromLong(int scope, long id)
      Creates a BigId from a scope and an ID part coded as a long
      Parameters:
      scope - Integer ID scope (e.g. database number)
      id - Local ID part
      Returns:
      The new immutable BigId instance
    • fromLongs

      static Collection<BigId> fromLongs(int scope, long... ids)
      Creates multiple BigIds from a scope and their ID parts coded as longs
      Parameters:
      scope - Integer ID scope (e.g. database number)
      ids - One or more local IDs
      Returns:
      A collection of immutable BigId instances
    • equals

      static boolean equals(BigId a, BigId b)
    • compare

      static int compare(BigId a, BigId b)
      Compare two BigIds using their byte representations. This function works with all BigId types since they are all required to provide a byte[] representation.
      Parameters:
      a - First id to compare (must not be null)
      b - Second id to compare (must not be null)
      Returns:
      A negative, zero, or positive integer as the first argument is less than, equal to, or greater than the second.
      Throws:
      NullPointerException - if one of the argument is null
    • compareLongs

      static int compareLongs(BigId a, BigId b)
      Compare two BigIds using their long representations. This will only work for BigId types with an ID part that can be represented as a long.
      Parameters:
      a - First id to compare (must not be null)
      b - Second id to compare (must not be null)
      Returns:
      A negative, zero, or positive integer as the first argument is less than, equal to, or greater than the second.
      Throws:
      NullPointerException - if one of the argument is null
    • fromString32

      static BigId fromString32(String s)
      Parse a BigId from a base32 encoded string
      Parameters:
      s -
      Returns:
      A BigId instance
      Throws:
      IllegalArgumentException - if the provided string is not a valid base32 string as per IETF RFC 4648 section 7
    • toString32

      static String toString32(BigId id)