Class StringCache


  • public class StringCache
    extends java.lang.Object
    A few String utility functions.
    • 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.
      • Methods inherited from class java.lang.Object

        equals, 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 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.