Package com.cedarsoftware.util
Class CaseInsensitiveMap<K,V>
java.lang.Object
com.cedarsoftware.util.CaseInsensitiveMap<K,V>
- All Implemented Interfaces:
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
License
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 ClassesModifier and TypeClassDescriptionclass
Entry implementation that will give back a String instead of a CaseInsensitiveString when .getKey() is called.static final class
Class used to wrap String keys. -
Constructor Summary
ConstructorsConstructorDescriptionCaseInsensitiveMap
(int initialCapacity) Use the constructor that takes two (2) Maps.CaseInsensitiveMap
(int initialCapacity, float loadFactor) Use the constructor that takes two (2) Maps.CaseInsensitiveMap
(Map<K, V> m) Wrap the passed in Map with a CaseInsensitiveMap, allowing other Map types like TreeMap, ConcurrentHashMap, etc.Wrap the passed in Map with a CaseInsensitiveMap, allowing other Map types like TreeMap, ConcurrentHashMap, etc. -
Method Summary
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 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
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
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
-
get
-
containsKey
- Specified by:
containsKey
in interfaceMap<K,
V>
-
put
-
putObject
-
putAll
-
remove
-
size
public int size() -
isEmpty
public boolean isEmpty() -
equals
-
hashCode
public int hashCode() -
toString
-
clear
public void clear() -
containsValue
- Specified by:
containsValue
in interfaceMap<K,
V>
-
values
-
minus
-
plus
-
getWrappedMap
-
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. -
entrySet
-