Class StringCache

  extended by java.util.AbstractMap<K,V>
      extended by java.util.WeakHashMap<String,WeakReference<String>>
          extended by rabbit.util.StringCache
All Implemented Interfaces:

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.

Robert Olofsson

Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
Constructor Summary
Method Summary
 String getCachedString(String s)
          Get a cached string with the same contents as the given string.
static StringCache getSharedInstance()
          Get the shared instance of the string caches.
Methods inherited from class java.util.WeakHashMap
clear, containsKey, containsValue, entrySet, get, isEmpty, keySet, put, putAll, remove, size, values
Methods inherited from class java.util.AbstractMap
clone, equals, hashCode, toString
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Map
equals, hashCode

Constructor Detail


public StringCache()
Method Detail


public static StringCache getSharedInstance()
Get the shared instance of the string caches.


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.

s - the string to get a shared string for.