T
- the type of entry to be stored in the cachepublic abstract class StringCache<T>
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private static int |
DEFAULT_MAX_STRING_LENGTH |
private static int |
DEFAULT_SIZE_LIMIT |
private int |
maxStringLength |
private int |
sizeLimit |
private java.util.Map<java.lang.String,java.lang.ref.SoftReference<T>> |
stringCache |
Constructor and Description |
---|
StringCache() |
Modifier and Type | Method and Description |
---|---|
void |
clear()
Removes all entries stored in this cache.
|
boolean |
containsKey(java.lang.String input)
Tests whether the cache contains the given key
|
T |
get(java.lang.String input)
Returns the value associated with the given string.
|
int |
getMaxStringLength()
Returns the maximum length a
String key can have to be used as a key in this cache. |
int |
getSizeLimit()
Returns the size limit of this string cache.
|
protected abstract T |
process(java.lang.String input)
Converts a given string to a value
|
void |
put(java.lang.String input,
T value)
Associates a value to a string
|
void |
setMaxStringLength(int maxStringLength)
Returns the maximum length a
String key can have to be used as a key in this cache. |
void |
setSizeLimit(int sizeLimit)
Defines the size limit of this string cache (16,384 by default).
|
private static final int DEFAULT_SIZE_LIMIT
private static final int DEFAULT_MAX_STRING_LENGTH
private final java.util.Map<java.lang.String,java.lang.ref.SoftReference<T>> stringCache
private int sizeLimit
private int maxStringLength
protected abstract T process(java.lang.String input)
input
- the input to be converted and stored in the cachepublic boolean containsKey(java.lang.String input)
input
- a string that might have a value associated to it.true
if the cache contains (or contained) a value associated with the given key.public int getSizeLimit()
public void setSizeLimit(int sizeLimit)
sizeLimit
- the maximum number of entries that can be stored in this string cache.public void put(java.lang.String input, T value)
input
- the string to be associated with a given valuevalue
- the value associated with the given stringpublic T get(java.lang.String input)
process(String)
input
- the string whose associated value will be returnedpublic void clear()
public int getMaxStringLength()
String
key can have to be used as a key in this cache.
If the String
length exceeds this limit, the value associated with it won't be cached.
Defaults to 1024String
key can havepublic void setMaxStringLength(int maxStringLength)
String
key can have to be used as a key in this cache.
If the String
length exceeds this limit, the value associated with it won't be cached.
Defaults to 1024maxStringLength
- the maximum length a String
key can have