Package org.organicdesign.fp.collections
Interface UnmodSortedMap<K,V>
-
- All Superinterfaces:
Iterable<UnmodMap.UnEntry<K,V>>
,Map<K,V>
,Sized
,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>, SortedMap<K,V>, UnmodSortedIterable<UnmodMap.UnEntry<K,V>>
An unmodifiable SortedMap.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K extends Object,V extends Object>
-
Nested classes/interfaces inherited from interface org.organicdesign.fp.collections.UnmodIterable
UnmodIterable.UnIterable
-
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 @NotNull UnmodSortedSet<Map.Entry<K,V>>
entrySet()
Returns a view of the mappings contained in this map.default @NotNull UnmodSortedMap<K,V>
headMap(K toKey)
default @NotNull UnmodSortedIterator<K>
keyIterator()
default @NotNull UnmodSortedSet<K>
keySet()
Returns a view of the keys contained in this map.@NotNull UnmodSortedMap<K,V>
subMap(K fromKey, K toKey)
@NotNull UnmodSortedMap<K,V>
tailMap(K fromKey)
default @NotNull UnmodSortedIterator<V>
valIterator()
default @NotNull 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.lang.Iterable
forEach, spliterator
-
Methods inherited from interface java.util.Map
containsKey, equals, forEach, get, getOrDefault, hashCode, size
-
Methods inherited from interface java.util.SortedMap
comparator, firstKey, lastKey
-
Methods inherited from interface org.organicdesign.fp.xform.Transformable
any, toImList, toImMap, toImRrbt, toImSet, toImSortedMap, toImSortedSet, toMutList, toMutMap, toMutRrbt, toMutSet, toMutSortedMap, toMutSortedSet
-
Methods inherited from interface org.organicdesign.fp.collections.UnmodIterable
concat, drop, dropWhile, filter, flatMap, fold, foldUntil, head, map, precat, take, takeWhile, whereNonNull
-
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
@NotNull default @NotNull UnmodSortedSet<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
@NotNull default @NotNull UnmodSortedMap<K,V> headMap(K toKey)
-
keyIterator
@NotNull default @NotNull UnmodSortedIterator<K> keyIterator()
- Specified by:
keyIterator
in interfaceUnmodMap<K,V>
-
valIterator
@NotNull default @NotNull UnmodSortedIterator<V> valIterator()
- Specified by:
valIterator
in interfaceUnmodMap<K,V>
-
keySet
@NotNull default @NotNull UnmodSortedSet<K> keySet()
Returns a view of the keys contained in this map.
-
subMap
@NotNull @NotNull UnmodSortedMap<K,V> subMap(K fromKey, K toKey)
-
tailMap
@NotNull @NotNull UnmodSortedMap<K,V> tailMap(K fromKey)
-
values
@NotNull default @NotNull 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); });
-
-