Package io.deephaven.base.string.cache
Class CharSequenceAdapter
java.lang.Object
io.deephaven.base.string.cache.CharSequenceAdapter
- All Implemented Interfaces:
StringCompatible
,CharSequence
,Comparable<CharSequence>
- Direct Known Subclasses:
ByteOrientedCharSequenceAdapter
,CharSequenceAdapterBuilder
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 Summary
-
Method Summary
Modifier and TypeMethodDescriptionabstract CharSequenceAdapter
clear()
Prepare this adapter for re-use, and eliminate references to external resources.final int
compareTo
(@NotNull CharSequence that) Implementations MUST compare StringCompatibles and Strings char-by-char.final boolean
final int
hashCode()
Implementations MUST match the current implementation of String.hashCode().protected abstract String
subSequence
(int start, int end) final @NotNull String
toString()
Convert this StringCompatible into a String.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.CharSequence
charAt, chars, codePoints, isEmpty, length
Methods inherited from interface io.deephaven.base.string.cache.StringCompatible
toCompressedString, toMappedCompressedString
-
Constructor Details
-
CharSequenceAdapter
public CharSequenceAdapter()
-
-
Method Details
-
clear
Prepare this adapter for re-use, and eliminate references to external resources. -
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 interfaceCharSequence
- Specified by:
toString
in interfaceStringCompatible
- Overrides:
toString
in classObject
- Returns:
- A newly constructed String representing the same sequence of characters as this StringCompatible.
-
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 interfaceStringCompatible
- Overrides:
hashCode
in classObject
- Returns:
- A hashcode value for this StringCompatible that matches the value a String of the same chars.
-
equals
- Specified by:
equals
in interfaceStringCompatible
- Overrides:
equals
in classObject
- Returns:
- true iff that is a StringCompatible of the same class with identical members.
-
subSequence
- Specified by:
subSequence
in interfaceCharSequence
-
compareTo
Description copied from interface:StringCompatible
Implementations MUST compare StringCompatibles and Strings char-by-char.- Specified by:
compareTo
in interfaceComparable<CharSequence>
- Specified by:
compareTo
in interfaceStringCompatible
- Returns:
- 0, <0, or >0 if that compares equal-to, less-than, or greater-than this.
-