public static class FunctionUtils.UnmodifiableMap<K,V> extends Object implements UnmodMap<K,V>, Serializable
FunctionUtils.unmodMap(Map)
.UnmodMap.AbstractUnmodMap<K,V>, UnmodMap.UnEntry<K,V>
UnmodIterable.AbstractUnmodIterable<T>
Modifier and Type | Method and Description |
---|---|
boolean |
containsKey(Object key) |
boolean |
containsValue(Object value)
Most maps are not designed for this - the default implementation has O(n) performance.
|
UnmodSet<Map.Entry<K,V>> |
entrySet()
Returns a view of the mappings contained in this map.
|
boolean |
equals(Object o) |
V |
get(Object key) |
int |
hashCode() |
boolean |
isEmpty() |
UnmodIterator<UnmodMap.UnEntry<K,V>> |
iterator()
A one-time use, mutable, not-thread-safe way to get each value of the underling collection in
turn.
|
UnmodSet<K> |
keySet()
Returns a view of the keys contained in this map.
|
int |
size()
Returns the number of items in this iterable.
|
String |
toString() |
UnmodCollection<V> |
values()
Deprecated.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
clear, compute, computeIfAbsent, computeIfPresent, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll
forEach, getOrDefault
concat, drop, filter, flatMap, foldLeft, foldLeft, hash, hashCode, head, map, precat, take, takeWhile, toString
forEach, spliterator
toImList, toImMap, toImSet, toImSortedMap, toImSortedSet, toMutableList, toMutableMap, toMutableSet, toMutableSortedMap, toMutableSortedSet
public UnmodIterator<UnmodMap.UnEntry<K,V>> iterator()
iterator
in interface Iterable<UnmodMap.UnEntry<K,V>>
iterator
in interface UnmodIterable<UnmodMap.UnEntry<K,V>>
public UnmodSet<Map.Entry<K,V>> entrySet()
UnmodMap
public int size()
Sized
public boolean isEmpty()
UnmodMap
public boolean containsKey(Object key)
containsKey
in interface Map<K,V>
public boolean containsValue(Object value)
UnmodMap
containsValue
in interface Map<K,V>
containsValue
in interface UnmodMap<K,V>
public UnmodSet<K> keySet()
UnmodMap
@Deprecated public UnmodCollection<V> values()
UnmodMap
myMap.map((UnEntry<K,V> entry) -> entry.getValue())
.toImSet();
If you want to keep a count of duplicates, try something like this, but it has a different
signature:
ImMap<V,Integer> valueCounts = myMap.foldLeft(PersistentHashMap.empty(),
(ImMap<V,Integer> accum, UnEntry<K,V> origEntry) -> {
V inVal = origEntry.getValue();
return accum.assoc(inVal,
accum.getOrElse(inVal, 0) + 1);
});
You really shouldn't turn values() into a List, because a List has order and an unsorted Map
is unordered by key, and especially unordered by value. On a SortedMap, List is the proper
return type.
java.util.HashMap.values() returns an instance of java.util.HashMap.Values which does *not*
have equals() or hashCode() defined. This is because List.equals() and Set.equals() return
not-equal when compared to a Collection. There is no good way to implement a reflexive
equals with both of those because they are just too different. Ultimately, Collection just
isn't specific enough to instantiate, but we do it anyway here for backward compatibility.
We don't implement equals() or hashCode() either because the result could have duplicates.
If the Map isn't sorted, the result could have random ordering.
public int hashCode()
public boolean equals(Object o)
Copyright © 2017. All rights reserved.