Class CharSequenceAdapter

java.lang.Object
io.deephaven.base.string.cache.CharSequenceAdapter
All Implemented Interfaces:
StringCompatible, CharSequence, Comparable<CharSequence>
Direct Known Subclasses:
ByteOrientedCharSequenceAdapter, CharSequenceAdapterBuilder

public abstract class CharSequenceAdapter extends Object implements StringCompatible
This class provides base functionality for several implementations of CharSequenceAdapter. Currently, there's one for ByteBuffers, another for byte arrays, one for sequences of chars, and one for chains of Strings. If you have array-backed, writable ByteBuffers, it's probably best to use the byte array implementation with the backing array, e.g. for ByteBuffer b, ByteBufferCharSequenceAdapterImpl a, proto-String length l, use: a.set(b.array(), b.position() + b.arrayOffset(), l); Note: trim() support hasn't been needed/implemented so far. Note: Only Latin-1 (ISO-8859-1) characters are expected at this time. Bytes are converted to chars one-for-one with the result masked by 0xFF. Implementations are not thread-safe. Pool them, create ThreadLocal instances, or (better) instantiate them along natural concurrency boundaries. Implementations allow any proto-String (that is, anything that can be expressed as a sequence of chars) to be used as a cache key (in ConcurrentUnboundedStringCache instances) and a String creator. Note Subclasses *must* support length(), and charAt(int index). Note The makeString() implementation *must* be consistent with length() and charAt(int index) - that is, we require that makeString().contentEquals(this). Note subSequence(int start, int end) is unsupported by default - no StringCache implementations need it at this time.
  • Constructor Details

    • CharSequenceAdapter

      public CharSequenceAdapter()
  • Method Details

    • clear

      public abstract CharSequenceAdapter clear()
      Prepare this adapter for re-use, and eliminate references to external resources.
    • toString

      @NotNull public final @NotNull String toString()
      Description copied from interface: StringCompatible
      Convert this StringCompatible into a String. Implementations should not cache result Strings, in order to avoid inadvertently allowing promotion of short-lived objects under generational garbage collection.
      Specified by:
      toString in interface CharSequence
      Specified by:
      toString in interface StringCompatible
      Overrides:
      toString in class Object
      Returns:
      A newly constructed String representing the same sequence of characters as this StringCompatible.
    • makeString

      protected abstract String makeString()
      Returns:
      A new String consistent with this CharSequenceAdapter.
    • hashCode

      public final int hashCode()
      Description copied from interface: StringCompatible
      Implementations MUST match the current implementation of String.hashCode().
      Specified by:
      hashCode in interface StringCompatible
      Overrides:
      hashCode in class Object
      Returns:
      A hashcode value for this StringCompatible that matches the value a String of the same chars.
    • equals

      public final boolean equals(Object that)
      Specified by:
      equals in interface StringCompatible
      Overrides:
      equals in class Object
      Returns:
      true iff that is a StringCompatible of the same class with identical members.
    • subSequence

      public CharSequence subSequence(int start, int end)
      Specified by:
      subSequence in interface CharSequence
    • compareTo

      public final int compareTo(@NotNull @NotNull CharSequence that)
      Description copied from interface: StringCompatible
      Implementations MUST compare StringCompatibles and Strings char-by-char.
      Specified by:
      compareTo in interface Comparable<CharSequence>
      Specified by:
      compareTo in interface StringCompatible
      Returns:
      0, <0, or >0 if that compares equal-to, less-than, or greater-than this.