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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract CharSequenceAdapterclear()Prepare this adapter for re-use, and eliminate references to external resources.final intcompareTo(@NotNull CharSequence that) Implementations MUST compare StringCompatibles and Strings char-by-char.final booleanfinal inthashCode()Implementations MUST match the current implementation of String.hashCode().protected abstract StringsubSequence(int start, int end) final @NotNull StringtoString()Convert this StringCompatible into a String.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.CharSequence
charAt, chars, codePoints, isEmpty, lengthMethods 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:StringCompatibleConvert 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:
toStringin interfaceCharSequence- Specified by:
toStringin interfaceStringCompatible- Overrides:
toStringin 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:StringCompatibleImplementations MUST match the current implementation of String.hashCode().- Specified by:
hashCodein interfaceStringCompatible- Overrides:
hashCodein classObject- Returns:
- A hashcode value for this StringCompatible that matches the value a String of the same chars.
-
equals
- Specified by:
equalsin interfaceStringCompatible- Overrides:
equalsin classObject- Returns:
- true iff that is a StringCompatible of the same class with identical members.
-
subSequence
- Specified by:
subSequencein interfaceCharSequence
-
compareTo
Description copied from interface:StringCompatibleImplementations MUST compare StringCompatibles and Strings char-by-char.- Specified by:
compareToin interfaceComparable<CharSequence>- Specified by:
compareToin interfaceStringCompatible- Returns:
- 0, <0, or >0 if that compares equal-to, less-than, or greater-than this.
-