org.springframework.util

Class LinkedCaseInsensitiveMap<V>

  • java.lang.Object
    • org.springframework.util.LinkedCaseInsensitiveMap<V>
  • Type Parameters:
    V - the value type
    All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.util.Map<java.lang.String,V>


    public class LinkedCaseInsensitiveMap<V>
    extends java.lang.Object
    implements java.util.Map<java.lang.String,V>, java.io.Serializable, java.lang.Cloneable
    LinkedHashMap variant that stores String keys in a case-insensitive manner, for example for key-based access in a results table.

    Preserves the original order as well as the original casing of keys, while allowing for contains, get and remove calls with any case of key.

    Does not support null keys.

    Since:
    3.0
    Author:
    Juergen Hoeller
    See Also:
    Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface java.util.Map

        java.util.Map.Entry<K,V>
    • Constructor Summary

      Constructors 
      Constructor and Description
      LinkedCaseInsensitiveMap()
      Create a new LinkedCaseInsensitiveMap that stores case-insensitive keys according to the default Locale (by default in lower case).
      LinkedCaseInsensitiveMap(int initialCapacity)
      Create a new LinkedCaseInsensitiveMap that wraps a LinkedHashMap with the given initial capacity and stores case-insensitive keys according to the default Locale (by default in lower case).
      LinkedCaseInsensitiveMap(int initialCapacity, java.util.Locale locale)
      Create a new LinkedCaseInsensitiveMap that wraps a LinkedHashMap with the given initial capacity and stores case-insensitive keys according to the given Locale (by default in lower case).
      LinkedCaseInsensitiveMap(java.util.Locale locale)
      Create a new LinkedCaseInsensitiveMap that stores case-insensitive keys according to the given Locale (by default in lower case).
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      void clear() 
      LinkedCaseInsensitiveMap<V> clone() 
      V computeIfAbsent(java.lang.String key, java.util.function.Function<? super java.lang.String,? extends V> mappingFunction) 
      boolean containsKey(java.lang.Object key) 
      boolean containsValue(java.lang.Object value) 
      protected java.lang.String convertKey(java.lang.String key)
      Convert the given key to a case-insensitive key.
      java.util.Set<java.util.Map.Entry<java.lang.String,V>> entrySet() 
      boolean equals(java.lang.Object obj) 
      V get(java.lang.Object key) 
      java.util.Locale getLocale()
      Return the locale used by this LinkedCaseInsensitiveMap.
      V getOrDefault(java.lang.Object key, V defaultValue) 
      int hashCode() 
      boolean isEmpty() 
      java.util.Set<java.lang.String> keySet() 
      V put(java.lang.String key, V value) 
      void putAll(java.util.Map<? extends java.lang.String,? extends V> map) 
      V putIfAbsent(java.lang.String key, V value) 
      V remove(java.lang.Object key) 
      protected boolean removeEldestEntry(java.util.Map.Entry<java.lang.String,V> eldest)
      Determine whether this map should remove the given eldest entry.
      int size() 
      java.lang.String toString() 
      java.util.Collection<V> values() 
      • Methods inherited from class java.lang.Object

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

        compute, computeIfPresent, forEach, merge, remove, replace, replace, replaceAll
    • Constructor Detail

      • LinkedCaseInsensitiveMap

        public LinkedCaseInsensitiveMap()
        Create a new LinkedCaseInsensitiveMap that stores case-insensitive keys according to the default Locale (by default in lower case).
        See Also:
        convertKey(String)
      • LinkedCaseInsensitiveMap

        public LinkedCaseInsensitiveMap(@Nullable
                                        java.util.Locale locale)
        Create a new LinkedCaseInsensitiveMap that stores case-insensitive keys according to the given Locale (by default in lower case).
        Parameters:
        locale - the Locale to use for case-insensitive key conversion
        See Also:
        convertKey(String)
      • LinkedCaseInsensitiveMap

        public LinkedCaseInsensitiveMap(int initialCapacity)
        Create a new LinkedCaseInsensitiveMap that wraps a LinkedHashMap with the given initial capacity and stores case-insensitive keys according to the default Locale (by default in lower case).
        Parameters:
        initialCapacity - the initial capacity
        See Also:
        convertKey(String)
      • LinkedCaseInsensitiveMap

        public LinkedCaseInsensitiveMap(int initialCapacity,
                                        @Nullable
                                        java.util.Locale locale)
        Create a new LinkedCaseInsensitiveMap that wraps a LinkedHashMap with the given initial capacity and stores case-insensitive keys according to the given Locale (by default in lower case).
        Parameters:
        initialCapacity - the initial capacity
        locale - the Locale to use for case-insensitive key conversion
        See Also:
        convertKey(String)
    • Method Detail

      • size

        public int size()
        Specified by:
        size in interface java.util.Map<java.lang.String,V>
      • isEmpty

        public boolean isEmpty()
        Specified by:
        isEmpty in interface java.util.Map<java.lang.String,V>
      • containsKey

        public boolean containsKey(java.lang.Object key)
        Specified by:
        containsKey in interface java.util.Map<java.lang.String,V>
      • containsValue

        public boolean containsValue(java.lang.Object value)
        Specified by:
        containsValue in interface java.util.Map<java.lang.String,V>
      • get

        @Nullable
        public V get(java.lang.Object key)
        Specified by:
        get in interface java.util.Map<java.lang.String,V>
      • getOrDefault

        @Nullable
        public V getOrDefault(java.lang.Object key,
                                        V defaultValue)
        Specified by:
        getOrDefault in interface java.util.Map<java.lang.String,V>
      • put

        @Nullable
        public V put(java.lang.String key,
                               @Nullable
                               V value)
        Specified by:
        put in interface java.util.Map<java.lang.String,V>
      • putAll

        public void putAll(java.util.Map<? extends java.lang.String,? extends V> map)
        Specified by:
        putAll in interface java.util.Map<java.lang.String,V>
      • putIfAbsent

        @Nullable
        public V putIfAbsent(java.lang.String key,
                                       @Nullable
                                       V value)
        Specified by:
        putIfAbsent in interface java.util.Map<java.lang.String,V>
      • computeIfAbsent

        @Nullable
        public V computeIfAbsent(java.lang.String key,
                                           java.util.function.Function<? super java.lang.String,? extends V> mappingFunction)
        Specified by:
        computeIfAbsent in interface java.util.Map<java.lang.String,V>
      • remove

        @Nullable
        public V remove(java.lang.Object key)
        Specified by:
        remove in interface java.util.Map<java.lang.String,V>
      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Map<java.lang.String,V>
      • keySet

        public java.util.Set<java.lang.String> keySet()
        Specified by:
        keySet in interface java.util.Map<java.lang.String,V>
      • values

        public java.util.Collection<V> values()
        Specified by:
        values in interface java.util.Map<java.lang.String,V>
      • entrySet

        public java.util.Set<java.util.Map.Entry<java.lang.String,V>> entrySet()
        Specified by:
        entrySet in interface java.util.Map<java.lang.String,V>
      • equals

        public boolean equals(java.lang.Object obj)
        Specified by:
        equals in interface java.util.Map<java.lang.String,V>
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Specified by:
        hashCode in interface java.util.Map<java.lang.String,V>
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • convertKey

        protected java.lang.String convertKey(java.lang.String key)
        Convert the given key to a case-insensitive key.

        The default implementation converts the key to lower-case according to this Map's Locale.

        Parameters:
        key - the user-specified key
        Returns:
        the key to use for storing
        See Also:
        String.toLowerCase(Locale)
      • removeEldestEntry

        protected boolean removeEldestEntry(java.util.Map.Entry<java.lang.String,V> eldest)
        Determine whether this map should remove the given eldest entry.
        Parameters:
        eldest - the candidate entry
        Returns:
        true for removing it, false for keeping it
        See Also:
        LinkedHashMap.removeEldestEntry(java.util.Map.Entry<K, V>)