Class BitSetEncoding

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

public class BitSetEncoding extends AbstractEncoding<BitSet>
Non-null BitSet type.

Null values are not supported by this class and there is no default value.

Instances are ordered as if they were giant unsigned integers, i.e., whichever instance has the highest bit set to one where the other instance has it set to zero is considered bigger. So the empty instance is the smallest possible.

See Also:
  • Constructor Details

    • BitSetEncoding

      public BitSetEncoding()
  • Method Details

    • supportsNull

      public boolean supportsNull()
      Description copied from interface: Encoding
      Determine whether this encoding supports null values.
      Returns:
      true if null is a valid value, otherwise false
    • 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
    • hasPrefix0x00

      public boolean hasPrefix0x00()
      Description copied from interface: Encoding
      Determine whether any of this encoding's encoded values start with a 0x00 byte. Certain optimizations are possible when this is not the case. It is safe for this method to always return true.

      Note: changing the result of this method may result in an incompatible encoding if this encoding is wrapped in another class.

      Returns:
      true if an encoded value starting with 0x00 exists
    • hasPrefix0xff

      public boolean hasPrefix0xff()
      Description copied from interface: Encoding
      Determine whether any of this encoding's encoded values start with a 0xff byte. Certain optimizations are possible when this is not the case. It is safe for this method to always return true.

      Note: changing the result of this method may result in an incompatible encoding if this encoding is wrapped in another class.

      Returns:
      true if an encoded value starting with 0xff exists
    • read

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

      public void write(ByteWriter writer, BitSet bitSet)
      Description copied from interface: Encoding
      Write a value to the given output.
      Parameters:
      writer - byte output
      bitSet - 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.

      If the value skipped over is invalid, this method may, but is not required to, throw IllegalArgumentException.

      If the value skipped over is truncated, this method must throw IndexOutOfBoundsException.

      Parameters:
      reader - byte input
    • toString

      public String toString(BitSet bitSet)
      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, when decoded as 32-bit Unicode codepoints, must contain only valid XML characters (see XMLUtil.isValidChar(int)).

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

      public BitSet 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
    • compare

      public int compare(BitSet bitSet1, BitSet bitSet2)
      Description copied from interface: Encoding
      Order two 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 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.

    • getFixedWidth

      public OptionalInt getFixedWidth()
      Description copied from interface: Encoding
      Get the fixed width of this encoding, if any.

      Some encodings encode every value into the same number of bytes. For such encodings, this method returns that number. For variable width encodings, this method must return empty.

      Returns:
      the number of bytes of every encoded value, or empty if the encoding length varies