Package org.organicdesign.fp.collections
Interface UnmodSortedMap<K,V>
-
- All Superinterfaces:
java.lang.Iterable<UnmodMap.UnEntry<K,V>>,java.util.Map<K,V>,Sized,java.util.SortedMap<K,V>,Transformable<UnmodMap.UnEntry<K,V>>,UnmodIterable<UnmodMap.UnEntry<K,V>>,UnmodMap<K,V>,UnmodSortedIterable<UnmodMap.UnEntry<K,V>>
- All Known Subinterfaces:
ImSortedMap<K,V>
- All Known Implementing Classes:
PersistentTreeMap
public interface UnmodSortedMap<K,V> extends UnmodMap<K,V>, java.util.SortedMap<K,V>, UnmodSortedIterable<UnmodMap.UnEntry<K,V>>
An unmodifiable SortedMap.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K extends java.lang.Object,V extends java.lang.Object>
-
Nested classes/interfaces inherited from interface org.organicdesign.fp.collections.UnmodMap
UnmodMap.UnEntry<K,V>
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default UnmodSortedSet<java.util.Map.Entry<K,V>>entrySet()Returns a view of the mappings contained in this map.default UnmodSortedMap<K,V>headMap(K toKey)default UnmodSortedIterator<K>keyIterator()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 UnmodSortedIterator<V>valIterator()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.-
Methods inherited from interface java.util.Map
containsKey, equals, forEach, get, getOrDefault, hashCode, size
-
Methods inherited from interface org.organicdesign.fp.xform.Transformable
toImList, toImMap, toImRrbt, toImSet, toImSortedMap, toImSortedSet, toMutableList, toMutableMap, toMutableRrbt, toMutableSet, toMutableSortedMap, toMutableSortedSet
-
Methods inherited from interface org.organicdesign.fp.collections.UnmodIterable
concat, drop, dropWhile, filter, flatMap, fold, foldUntil, head, map, precat, take, takeWhile
-
Methods inherited from interface org.organicdesign.fp.collections.UnmodMap
clear, compute, computeIfAbsent, computeIfPresent, containsValue, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll
-
Methods inherited from interface org.organicdesign.fp.collections.UnmodSortedIterable
iterator
-
-
-
-
Method Detail
-
entrySet
default UnmodSortedSet<java.util.Map.Entry<K,V>> entrySet()
Returns a view of the mappings contained in this map. The set should actually contain UnmodMap.Entry items, but that return signature is illegal in Java, so you'll just have to remember.
-
headMap
default UnmodSortedMap<K,V> headMap(K toKey)
-
keyIterator
default UnmodSortedIterator<K> keyIterator()
- Specified by:
keyIteratorin interfaceUnmodMap<K,V>
-
valIterator
default UnmodSortedIterator<V> valIterator()
- Specified by:
valIteratorin interfaceUnmodMap<K,V>
-
keySet
default UnmodSortedSet<K> keySet()
Returns a view of the keys contained in this map.
-
subMap
UnmodSortedMap<K,V> subMap(K fromKey, K toKey)
-
tailMap
UnmodSortedMap<K,V> tailMap(K fromKey)
-
values
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. It's still an unnecessary convenience method and you should use this map as an Iterable instead for consistency in dealing with all maps.
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:mySortedMap.map((UnEntry<K,V> entry) -> entry.getValue()) .toImList();
If you want to keep a count of duplicates, try something like this, but it has a different signature:myMap.map((UnEntry<K,V> entry) -> entry.getValue()) .toImSet();
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.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); });
-
-