org.h2.util
Class StringCache

java.lang.Object
  extended by org.h2.util.StringCache

public class StringCache
extends java.lang.Object

The string cache helps re-use string objects and therefore save memory. It uses a soft reference cache to keep frequently used strings in memory. The effect is similar to calling String.intern(), but faster.


Method Summary
static void clearCache()
          Clear the cache.
static java.lang.String get(java.lang.String s)
          Get the string from the cache if possible.
static java.lang.String getNew(java.lang.String s)
          Get a string from the cache, and if no such string has been found, create a new one with only this content.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

get

public static java.lang.String get(java.lang.String s)
Get the string from the cache if possible. If the string has not been found, it is added to the cache. If there is such a string in the cache, that one is returned.

Parameters:
s - the original string
Returns:
a string with the same content, if possible from the cache

getNew

public static java.lang.String getNew(java.lang.String s)
Get a string from the cache, and if no such string has been found, create a new one with only this content. This solves out of memory problems if the string is a substring of another, large string. In Java, strings are shared, which could lead to memory problems. This avoid such problems.

Parameters:
s - the string
Returns:
a string that is guaranteed not be a substring of a large string

clearCache

public static void clearCache()
Clear the cache. This method is used for testing.