rabbit.util
Class StringCache
java.lang.Object
java.util.AbstractMap<K,V>
java.util.WeakHashMap<String,WeakReference<String>>
rabbit.util.StringCache
- All Implemented Interfaces:
- Map<String,WeakReference<String>>
public class StringCache
- extends WeakHashMap<String,WeakReference<String>>
A cache for strings. The cache is weak so GC can happen quickly.
String.intern may seem similar, but String.intern is a hard cache,
that is no GC will remove interned strings.
- Author:
- Robert Olofsson
Methods inherited from class java.util.WeakHashMap |
clear, containsKey, containsValue, entrySet, get, isEmpty, keySet, put, putAll, remove, size, values |
StringCache
public StringCache()
getSharedInstance
public static StringCache getSharedInstance()
- Get the shared instance of the string caches.
getCachedString
public String getCachedString(String s)
- Get a cached string with the same contents as the given string.
If the string given is not null then the cache will hold one
entry with the same value as the given string after this method has completed.
- Parameters:
s
- the string to get a shared string for.