Class StringCache
- java.lang.Object
-
- org.apache.jackrabbit.spi.commons.util.StringCache
-
public class StringCache extends java.lang.Object
A few String utility functions.
-
-
Field Summary
Fields Modifier and Type Field Description static boolean
OBJECT_CACHE
static int
OBJECT_CACHE_SIZE
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
cache(java.lang.String s)
Get the string from the cache if possible.static void
clearCache()
Clear the cache.static java.lang.String
fromCacheOrNew(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.
-
-
-
Method Detail
-
cache
public static java.lang.String cache(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
-
fromCacheOrNew
public static java.lang.String fromCacheOrNew(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.
-
-