public interface UnmodMap<K,V> extends Map<K,V>, UnmodIterable<UnmodMap.UnEntry<K,V>>, Sized
Modifier and Type | Interface and Description |
---|---|
static interface |
UnmodMap.UnEntry<K,V>
A map entry (key-value pair).
|
Modifier and Type | Method and Description |
---|---|
default void |
clear()
Deprecated.
|
default V |
compute(K key,
BiFunction<? super K,? super V,? extends V> remappingFunction)
Deprecated.
|
default V |
computeIfAbsent(K key,
Function<? super K,? extends V> mappingFunction)
Deprecated.
|
default V |
computeIfPresent(K key,
BiFunction<? super K,? super V,? extends V> remappingFunction)
Deprecated.
|
default boolean |
containsValue(Object value)
Most maps are not designed for this - the default implementation has O(n) performance.
|
default UnmodSet<Map.Entry<K,V>> |
entrySet()
Returns a view of the mappings contained in this map.
|
default boolean |
isEmpty() |
default UnmodSet<K> |
keySet()
Returns a view of the keys contained in this map.
|
default V |
merge(K key,
V value,
BiFunction<? super V,? super V,? extends V> remappingFunction)
Deprecated.
|
default V |
put(K key,
V value)
Deprecated.
|
default void |
putAll(Map<? extends K,? extends V> m)
Deprecated.
|
default V |
putIfAbsent(K key,
V value)
Deprecated.
|
default V |
remove(Object key)
Deprecated.
|
default boolean |
remove(Object key,
Object value)
Deprecated.
|
default V |
replace(K key,
V value)
Deprecated.
|
default boolean |
replace(K key,
V oldValue,
V newValue)
Deprecated.
|
default void |
replaceAll(BiFunction<? super K,? super V,? extends V> function)
Deprecated.
|
default UnmodCollection<V> |
values()
Deprecated.
|
containsKey, equals, forEach, get, getOrDefault, hashCode, size
concat, drop, dropWhile, filter, flatMap, fold, foldUntil, hash, head, iterator, map, precat, take, takeWhile, toString
forEach, spliterator
toImList, toImMap, toImSet, toImSortedMap, toImSortedSet, toMutableList, toMutableMap, toMutableSet, toMutableSortedMap, toMutableSortedSet
@Deprecated default void clear()
@Deprecated default V compute(K key, BiFunction<? super K,? super V,? extends V> remappingFunction)
@Deprecated default V computeIfAbsent(K key, Function<? super K,? extends V> mappingFunction)
computeIfAbsent
in interface Map<K,V>
@Deprecated default V computeIfPresent(K key, BiFunction<? super K,? super V,? extends V> remappingFunction)
computeIfPresent
in interface Map<K,V>
default boolean containsValue(Object value)
containsValue
in interface Map<K,V>
default UnmodSet<Map.Entry<K,V>> entrySet()
default UnmodSet<K> keySet()
@Deprecated default V merge(K key, V value, BiFunction<? super V,? super V,? extends V> remappingFunction)
@Deprecated default V put(K key, V value)
ImMap.assoc(Object, Object)
instead because it returns a new map.@Deprecated default void putAll(Map<? extends K,? extends V> m)
@Deprecated default V putIfAbsent(K key, V value)
putIfAbsent
in interface Map<K,V>
@Deprecated default V remove(Object key)
@Deprecated default boolean remove(Object key, Object value)
@Deprecated default boolean replace(K key, V oldValue, V newValue)
@Deprecated default V replace(K key, V value)
@Deprecated default void replaceAll(BiFunction<? super K,? super V,? extends V> function)
replaceAll
in interface Map<K,V>
@Deprecated default UnmodCollection<V> values()
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.fold(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.
Copyright © 2017. All rights reserved.