Class InternCache

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.util.Map<java.lang.String,​java.lang.String>

    public final class InternCache
    extends java.util.LinkedHashMap<java.lang.String,​java.lang.String>
    Singleton class that implements "fast intern" functionality, essentially adding a layer that caches Strings that have been previously intern()ed, but that probably shouldn't be added to symbol tables. This is usually used by improving intern()ing of things like namespace URIs.

    Note: that this class extends LinkedHashMap is an implementation detail -- no code should ever directly call Map methods.

    See Also:
    Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.util.AbstractMap

        java.util.AbstractMap.SimpleEntry<K extends java.lang.Object,​V extends java.lang.Object>, java.util.AbstractMap.SimpleImmutableEntry<K extends java.lang.Object,​V extends java.lang.Object>
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static int DEFAULT_SIZE
      Let's create cache big enough to usually have enough space for all entries...
      private static int MAX_SIZE
      Let's limit to hash area size of 1024.
      private static InternCache sInstance  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private InternCache()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static InternCache getInstance()  
      java.lang.String intern​(java.lang.String input)  
      protected boolean removeEldestEntry​(java.util.Map.Entry<java.lang.String,​java.lang.String> eldest)  
      • Methods inherited from class java.util.LinkedHashMap

        clear, containsValue, entrySet, forEach, get, getOrDefault, keySet, replaceAll, values
      • Methods inherited from class java.util.HashMap

        clone, compute, computeIfAbsent, computeIfPresent, containsKey, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, size
      • Methods inherited from class java.util.AbstractMap

        equals, hashCode, toString
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Map

        compute, computeIfAbsent, computeIfPresent, containsKey, equals, hashCode, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, size
    • Field Detail

      • DEFAULT_SIZE

        private static final int DEFAULT_SIZE
        Let's create cache big enough to usually have enough space for all entries... (assuming NS URIs only)
        See Also:
        Constant Field Values
      • MAX_SIZE

        private static final int MAX_SIZE
        Let's limit to hash area size of 1024.
        See Also:
        Constant Field Values
      • sInstance

        private static final InternCache sInstance
    • Constructor Detail

      • InternCache

        private InternCache()
    • Method Detail

      • getInstance

        public static InternCache getInstance()
      • intern

        public java.lang.String intern​(java.lang.String input)
      • removeEldestEntry

        protected boolean removeEldestEntry​(java.util.Map.Entry<java.lang.String,​java.lang.String> eldest)
        Overrides:
        removeEldestEntry in class java.util.LinkedHashMap<java.lang.String,​java.lang.String>