public interface UnmodSortedMap<K,V> extends UnmodMap<K,V>, SortedMap<K,V>, UnmodSortedIterable<UnmodMap.UnEntry<K,V>>
UnmodMap.UnEntry<K,V>
Modifier and Type | Method and Description |
---|---|
default UnmodSortedSet<Map.Entry<K,V>> |
entrySet()
Returns a view of the mappings contained in this map.
|
default UnmodSortedMap<K,V> |
headMap(K toKey) |
default UnmodSortedSet<K> |
keySet()
Returns a view of the keys contained in this map.
|
UnmodSortedMap<K,V> |
subMap(K fromKey,
K toKey) |
UnmodSortedMap<K,V> |
tailMap(K fromKey) |
default UnmodSortedCollection<V> |
values()
This method is deprecated on UnmodMap because equals() and hashCode() cannot be implemented
on the resulting collection, but the guaranteed order of the result in a SortedMap makes this
able to return a List.
|
clear, compute, computeIfAbsent, computeIfPresent, containsValue, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll
comparator, firstKey, lastKey
containsKey, equals, forEach, get, getOrDefault, hashCode, size
castFromList, castFromSortedMap, castFromSortedSet, equal, iterator
concat, drop, dropWhile, filter, flatMap, fold, foldUntil, hash, head, map, precat, take, takeWhile, toString
forEach, spliterator
toImList, toImMap, toImSet, toImSortedMap, toImSortedSet, toMutableList, toMutableMap, toMutableSet, toMutableSortedMap, toMutableSortedSet
default UnmodSortedSet<Map.Entry<K,V>> entrySet()
default UnmodSortedMap<K,V> headMap(K toKey)
default UnmodSortedSet<K> keySet()
UnmodSortedMap<K,V> subMap(K fromKey, K toKey)
default UnmodSortedCollection<V> values()
mySortedMap.map((UnEntry<K,V> entry) -> entry.getValue())
.toImList();
This method has been deprecated because it is impossible to implement equals() or hashCode()
on the resulting collection, and calling this method is probably at least a missed opportunity,
if not an outright error. Use an UnmodMap as an UnmodIterable<UnmodMap.UnEntry> instead.
If you don't care about eliminating duplicate values, and want a compatible return type call:
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.