Package io.deephaven.base.string.cache
Class ConcurrentUnboundedStringCache<STRING_LIKE_TYPE extends CharSequence>
java.lang.Object
io.deephaven.base.string.cache.ConcurrentUnboundedStringCache<STRING_LIKE_TYPE>
- All Implemented Interfaces:
StringCache<STRING_LIKE_TYPE>
public class ConcurrentUnboundedStringCache<STRING_LIKE_TYPE extends CharSequence>
extends Object
implements StringCache<STRING_LIKE_TYPE>
A very limited interface is specified, in order to decouple typeAdapter pooling and related concerns from the cache
itself.
StringCompatibles or Strings used as keys (or values) when probing/populating the cache are allowed to use their own
hashCode() implementation. This is dangerous, because we rely on our key implementation to hash CharSequences
identically to a String of the same characters. An assertion in the value factory should catch any cases where the
built-in assumption breaks down, but we've deemed that unnecessary at this time. Specify "debug" in the constructor
if you need this check. String.hashCode()'s implementation has been stable since JDK 1.2, and is specified in the
JavaDocs.
This implementation is thread-safe, and lock-free except for the insertion of new cached Strings on a cache miss.
StringCompatible implementation thread-safety is a separate concern.
-
Field Summary
Fields inherited from interface io.deephaven.base.string.cache.StringCache
CAPACITY_UNBOUNDED
-
Constructor Summary
ConstructorDescriptionConcurrentUnboundedStringCache
(@NotNull StringCacheTypeAdapter<STRING_LIKE_TYPE> typeAdapter, int initialCapacity, boolean debug) -
Method Summary
Modifier and TypeMethodDescriptionfinal int
capacity()
Get a hint about this cache's capacity and behavior.final STRING_LIKE_TYPE
getCachedString
(@NotNull StringCompatible protoString) final STRING_LIKE_TYPE
getCachedString
(@NotNull String string) final STRING_LIKE_TYPE
final @NotNull Class<STRING_LIKE_TYPE>
getType()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.deephaven.base.string.cache.StringCache
getCachedString
-
Constructor Details
-
ConcurrentUnboundedStringCache
public ConcurrentUnboundedStringCache(@NotNull @NotNull StringCacheTypeAdapter<STRING_LIKE_TYPE> typeAdapter, int initialCapacity, boolean debug) - Parameters:
typeAdapter
- The type adapter for this cacheinitialCapacity
- Initial capacity of the map backing this cachedebug
- Whether constructed Strings should be checked for consistency against the StringCompatible used
-
-
Method Details
-
capacity
public final int capacity()Description copied from interface:StringCache
Get a hint about this cache's capacity and behavior.- Specified by:
capacity
in interfaceStringCache<STRING_LIKE_TYPE extends CharSequence>
- Returns:
- -1 : This is an unbounded cache. 0 : This "cache" doesn't actually perform any caching. >0 : Actual capacity bound.
-
getType
- Specified by:
getType
in interfaceStringCache<STRING_LIKE_TYPE extends CharSequence>
- Returns:
- The type of the elements in this cache.
-
getEmptyString
- Specified by:
getEmptyString
in interfaceStringCache<STRING_LIKE_TYPE extends CharSequence>
- Returns:
- A cached STRING_LIKE_TYPE that represents the empty string.
-
getCachedString
@NotNull public final STRING_LIKE_TYPE getCachedString(@NotNull @NotNull StringCompatible protoString) - Specified by:
getCachedString
in interfaceStringCache<STRING_LIKE_TYPE extends CharSequence>
- Parameters:
protoString
- The string-like CharSequence to look up- Returns:
- A cached STRING_LIKE_TYPE that corresponds to the current value of the CharSequence expressed by protoString
-
getCachedString
- Specified by:
getCachedString
in interfaceStringCache<STRING_LIKE_TYPE extends CharSequence>
- Parameters:
string
- The String to look up- Returns:
- A cached STRING_LIKE_TYPE that corresponds to the CharSequence expressed by string
-