Class StringCache


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