Class CaseInsensitiveMap<K,V>

java.lang.Object
com.cedarsoftware.util.CaseInsensitiveMap<K,V>
All Implemented Interfaces:
Map<K,V>

public class CaseInsensitiveMap<K,V> extends Object implements Map<K,V>
Useful Map that does not care about the case-sensitivity of keys when the key value is a String. Other key types can be used. String keys will be treated case insensitively, yet key case will be retained. Non-string keys will work as they normally would.

The internal CaseInsensitiveString is never exposed externally from this class. When requesting the keys or entries of this map, or calling containsKey() or get() for example, use a String as you normally would. The returned Set of keys for the keySet() and entrySet() APIs return the original Strings, not the internally wrapped CaseInsensitiveString. As an added benefit, .keySet() returns a case-insenstive Set, however, again, the contents of the entries are actual Strings. Similarly, .entrySet() returns a case-insensitive entry set, such that .getKey() on the entry is case insensitive when compared, but the returned key is a String.

Author:
John DeRegnaucourt ([email protected])
Copyright (c) Cedar Software LLC

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
  • Constructor Details

    • CaseInsensitiveMap

      public CaseInsensitiveMap()
    • CaseInsensitiveMap

      public CaseInsensitiveMap(int initialCapacity)
      Use the constructor that takes two (2) Maps. The first Map may/may not contain any items to add, and the second Map is an empty Map configured the way you want it to be (load factor, capacity) and the type of Map you want. This Map is used by CaseInsenstiveMap internally to store entries.
    • CaseInsensitiveMap

      public CaseInsensitiveMap(int initialCapacity, float loadFactor)
      Use the constructor that takes two (2) Maps. The first Map may/may not contain any items to add, and the second Map is an empty Map configured the way you want it to be (load factor, capacity) and the type of Map you want. This Map is used by CaseInsenstiveMap internally to store entries.
    • CaseInsensitiveMap

      public CaseInsensitiveMap(Map<K,V> source, Map<K,V> mapInstance)
      Wrap the passed in Map with a CaseInsensitiveMap, allowing other Map types like TreeMap, ConcurrentHashMap, etc. to be case insensitive. The caller supplies the actual Map instance that will back the CaseInsensitiveMap.;
      Parameters:
      source - existing Map to supply the entries.
      mapInstance - empty new Map to use. This lets you decide what Map to use to back the CaseInsensitiveMap.
    • CaseInsensitiveMap

      public CaseInsensitiveMap(Map<K,V> m)
      Wrap the passed in Map with a CaseInsensitiveMap, allowing other Map types like TreeMap, ConcurrentHashMap, etc. to be case insensitive.
      Parameters:
      m - Map to wrap.
  • Method Details

    • copy

      protected Map<K,V> copy(Map<K,V> source, Map<K,V> dest)
    • get

      public V get(Object key)
      Specified by:
      get in interface Map<K,V>
    • containsKey

      public boolean containsKey(Object key)
      Specified by:
      containsKey in interface Map<K,V>
    • put

      public V put(K key, V value)
      Specified by:
      put in interface Map<K,V>
    • putObject

      public Object putObject(Object key, Object value)
    • putAll

      public void putAll(Map<? extends K,? extends V> m)
      Specified by:
      putAll in interface Map<K,V>
    • remove

      public V remove(Object key)
      Specified by:
      remove in interface Map<K,V>
    • size

      public int size()
      Specified by:
      size in interface Map<K,V>
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Map<K,V>
    • equals

      public boolean equals(Object other)
      Specified by:
      equals in interface Map<K,V>
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in interface Map<K,V>
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • clear

      public void clear()
      Specified by:
      clear in interface Map<K,V>
    • containsValue

      public boolean containsValue(Object value)
      Specified by:
      containsValue in interface Map<K,V>
    • values

      public Collection<V> values()
      Specified by:
      values in interface Map<K,V>
    • minus

      public Map minus(Object removeMe)
    • plus

      public Map plus(Object right)
    • getWrappedMap

      public Map<K,V> getWrappedMap()
    • keySet

      public Set<K> keySet()
      Returns a Set view of the keys contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's own remove operation), the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll, and clear operations. It does not support the add or addAll operations.
      Specified by:
      keySet in interface Map<K,V>
    • entrySet

      public Set<Map.Entry<K,V>> entrySet()
      Specified by:
      entrySet in interface Map<K,V>