org.apache.jackrabbit.spi.commons.util
Class StringCache

java.lang.Object
  extended by org.apache.jackrabbit.spi.commons.util.StringCache

public class StringCache
extends Object

A few String utility functions.


Field Summary
static boolean OBJECT_CACHE
           
static int OBJECT_CACHE_SIZE
           
 
Method Summary
static String cache(String s)
          Get the string from the cache if possible.
static void clearCache()
          Clear the cache.
static String fromCacheOrNew(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
 

Field Detail

OBJECT_CACHE

public static final boolean OBJECT_CACHE

OBJECT_CACHE_SIZE

public static final int OBJECT_CACHE_SIZE
Method Detail

cache

public static String cache(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

fromCacheOrNew

public static String fromCacheOrNew(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.



Copyright © 2004-2010 The Apache Software Foundation. All Rights Reserved.