Package com.cedarsoftware.util
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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
CaseInsensitiveMap.CaseInsensitiveEntry<KK,VV>
Entry implementation that will give back a String instead of a CaseInsensitiveString when .getKey() is called.static class
CaseInsensitiveMap.CaseInsensitiveString
Class used to wrap String keys.
-
Constructor Summary
Constructors Constructor Description CaseInsensitiveMap()
CaseInsensitiveMap(int initialCapacity)
CaseInsensitiveMap(int initialCapacity, float loadFactor)
CaseInsensitiveMap(Map<K,V> m)
Wrap the passed in Map with a CaseInsensitiveMap, allowing other Map types like TreeMap, ConcurrentHashMap, etc.CaseInsensitiveMap(Map<K,V> m, Map<K,V> backingMap)
Wrap the passed in Map with a CaseInsensitiveMap, allowing other Map types like TreeMap, ConcurrentHashMap, etc.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
boolean
containsKey(Object key)
boolean
containsValue(Object value)
protected Map<K,V>
copy(Map<K,V> source, Map dest)
Set<Map.Entry<K,V>>
entrySet()
boolean
equals(Object other)
V
get(Object key)
Map<K,V>
getWrappedMap()
int
hashCode()
boolean
isEmpty()
Set<K>
keySet()
Returns a Set view of the keys contained in this map.Map
minus(Object removeMe)
Map
plus(Object right)
V
put(K key, V value)
void
putAll(Map<? extends K,? extends V> m)
Object
putObject(Object key, Object value)
V
remove(Object key)
int
size()
String
toString()
Collection<V>
values()
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
-
-
-
Constructor Detail
-
CaseInsensitiveMap
public CaseInsensitiveMap()
-
CaseInsensitiveMap
public CaseInsensitiveMap(int initialCapacity)
-
CaseInsensitiveMap
public CaseInsensitiveMap(Map<K,V> m, Map<K,V> backingMap)
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:
m
- Map to wrap.
-
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.
-
CaseInsensitiveMap
public CaseInsensitiveMap(int initialCapacity, float loadFactor)
-
-
Method Detail
-
containsKey
public boolean containsKey(Object key)
- Specified by:
containsKey
in interfaceMap<K,V>
-
equals
public boolean equals(Object other)
-
hashCode
public int hashCode()
-
containsValue
public boolean containsValue(Object value)
- Specified by:
containsValue
in interfaceMap<K,V>
-
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.
-
-