Class UUIDEncoding

java.lang.Object
io.permazen.encoding.AbstractEncoding<UUID>
io.permazen.encoding.UUIDEncoding
All Implemented Interfaces:
Encoding<UUID>, NaturalSortAware, Serializable, Comparator<UUID>

public class UUIDEncoding extends AbstractEncoding<UUID>
Non-null UUID type. Null values are not supported by this class.

Binary encoding is 16 bytes, consisting of the eight high-order bytes followed by the eight low-order bytes.

See Also:
  • Constructor Details

    • UUIDEncoding

      public UUIDEncoding(EncodingId encodingId)
  • Method Details

    • withEncodingId

      public UUIDEncoding withEncodingId(EncodingId encodingId)
      Description copied from interface: Encoding
      Build an encoding that has the given EncodingId but is otherwise equivalent to this encoding.

      If this encoding already has encodingId, then this method may (but is not required to) return this same instance.

      Parameters:
      encodingId - new encoding's EncodingId, or null for an anonymized encoding
      Returns:
      a version of this encoding with the given EncodingId
    • read

      public UUID read(ByteReader reader)
      Description copied from interface: Encoding
      Read a value from the given input.
      Parameters:
      reader - byte input
      Returns:
      field value (possibly null)
    • write

      public void write(ByteWriter writer, UUID uuid)
      Description copied from interface: Encoding
      Write a value to the given output.
      Parameters:
      writer - byte output
      uuid - value to write (possibly null)
    • skip

      public void skip(ByteReader reader)
      Description copied from interface: Encoding
      Read and discard a byte[] encoded value from the given input.
      Parameters:
      reader - byte input
    • fromString

      public UUID fromString(String string)
      Description copied from interface: Encoding
      Parse a non-null value previously encoded by toString(T).
      Parameters:
      string - non-null value previously encoded as a String by toString(T)
      Returns:
      actual value
    • toString

      public String toString(UUID uuid)
      Description copied from interface: Encoding
      Encode a non-null value as a String for later decoding by fromString().

      Each of the characters in the returned String must be one of the valid XML characters (tab, newline, carriage return, \u0020 - \ud7ff, and \ue000 - \ufffd).

      Parameters:
      uuid - actual value, never null
      Returns:
      string encoding of value acceptable to fromString()
      See Also:
    • compare

      public int compare(UUID uuid1, UUID uuid2)
      Description copied from interface: Encoding
      Order two field values.

      This method must provide a total ordering of all supported Java values that is consistent with the database ordering, i.e., the unsigned lexicographical ordering of the corresponding byte[] encoded field values.

      If null is a supported Java value, then the this method must accept null parameters without throwing an exception (note, this is a stronger requirement than the Comparator interface normally requires).

      Note: by convention, null values usually sort last.

    • sortsNaturally

      public boolean sortsNaturally()
      Description copied from interface: NaturalSortAware
      Determine if this instance sorts Java instances naturally.

      This method should return true only if all of the following are true:

      • This class also implements Comparator for some Java type T.
      • Type T has a natural ordering (i.e., T itself implements Comparable).
      • The ordering implied by this class's compare() method is identical to T's natural ordering.
      Returns:
      true if this instance orders Java values in their natural order