Package org.organicdesign.fp.collections
Interface UnmodMap<K,V>
-
- All Superinterfaces:
Iterable<UnmodMap.UnEntry<K,V>>,Map<K,V>,Sized,Transformable<UnmodMap.UnEntry<K,V>>,UnmodIterable<UnmodMap.UnEntry<K,V>>
- All Known Subinterfaces:
BaseMap<K,V>,BaseUnsortedMap<K,V>,ImMap<K,V>,ImSortedMap<K,V>,MutMap<K,V>,UnmodSortedMap<K,V>
- All Known Implementing Classes:
AbstractUnmodMap,PersistentHashMap,PersistentHashMap.MutHashMap,PersistentTreeMap
public interface UnmodMap<K,V> extends Map<K,V>, UnmodIterable<UnmodMap.UnEntry<K,V>>, Sized
An unmodifiable map. This cannot extend Collection because the remove() method would then be inherited from both Collection and Map and Collection.remove() returns a boolean while Map.remove() returns a V (the type of the value in the key/value pair). Maybe an UnmodSizedIterable is called for?
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceUnmodMap.UnEntry<K,V>A map entry (key-value pair).-
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
-
-
Method Summary
All Methods Instance Methods Default Methods Deprecated Methods Modifier and Type Method Description default voidclear()Deprecated.default Vcompute(K key, @NotNull BiFunction<? super K,? super V,? extends V> remappingFunction)Deprecated.default VcomputeIfAbsent(K key, @NotNull Function<? super K,? extends V> mappingFunction)Deprecated.default VcomputeIfPresent(K key, @NotNull BiFunction<? super K,? super V,? extends V> remappingFunction)Deprecated.default booleancontainsValue(Object value)Most maps are not designed for this - the default implementation has O(n) performance.default @NotNull UnmodSet<Map.Entry<K,V>>entrySet()Returns a view of the mappings contained in this map.default booleanisEmpty()default @NotNull UnmodIterator<K>keyIterator()default @NotNull UnmodSet<K>keySet()Returns a view of the keys contained in this map.default Vmerge(K key, V value, @NotNull BiFunction<? super V,? super V,? extends V> remappingFunction)Deprecated.default Vput(K key, V value)Deprecated.default voidputAll(@NotNull Map<? extends K,? extends V> m)Deprecated.default VputIfAbsent(K key, V value)Deprecated.default Vremove(Object key)Deprecated.default booleanremove(Object key, Object value)Deprecated.default Vreplace(K key, V value)Deprecated.default booleanreplace(K key, V oldValue, V newValue)Deprecated.default voidreplaceAll(BiFunction<? super K,? super V,? extends V> function)Deprecated.default @NotNull UnmodIterator<V>valIterator()default @NotNull UnmodCollection<V>values()Deprecated.-
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 org.organicdesign.fp.xform.Transformable
any, toImList, toImMap, toImRrbt, toImSet, toImSortedMap, toImSortedSet, toMutList, toMutMap, toMutRrbt, toMutSet, toMutSortedMap, toMutSortedSet
-
-
-
-
Method Detail
-
clear
@Deprecated default void clear()
Deprecated.Not allowed - this is supposed to be unmodifiable
-
compute
@Deprecated default V compute(K key, @NotNull @NotNull BiFunction<? super K,? super V,? extends V> remappingFunction)
Deprecated.Not allowed - this is supposed to be unmodifiable
-
computeIfAbsent
@Deprecated default V computeIfAbsent(K key, @NotNull @NotNull Function<? super K,? extends V> mappingFunction)
Deprecated.Not allowed - this is supposed to be unmodifiable- Specified by:
computeIfAbsentin interfaceMap<K,V>
-
computeIfPresent
@Deprecated default V computeIfPresent(K key, @NotNull @NotNull BiFunction<? super K,? super V,? extends V> remappingFunction)
Deprecated.Not allowed - this is supposed to be unmodifiable- Specified by:
computeIfPresentin interfaceMap<K,V>
-
containsValue
default boolean containsValue(Object value)
Most maps are not designed for this - the default implementation has O(n) performance.- Specified by:
containsValuein interfaceMap<K,V>
-
entrySet
@NotNull default @NotNull UnmodSet<Map.Entry<K,V>> entrySet()
Returns a view of the mappings contained in this map. The set will contain UnmodMap.UnEntry items, but that return signature is illegal in Java, so you'll just have to remember. An UnmodMap is iterable, so this method is probably not nearly as useful as it once was.
-
keySet
@NotNull default @NotNull UnmodSet<K> keySet()
Returns a view of the keys contained in this map. An UnmodMap is iterable, so this method is probably not nearly as useful as it once was.
-
keyIterator
@NotNull default @NotNull UnmodIterator<K> keyIterator()
-
valIterator
@NotNull default @NotNull UnmodIterator<V> valIterator()
-
merge
@Deprecated default V merge(K key, @NotNull V value, @NotNull @NotNull BiFunction<? super V,? super V,? extends V> remappingFunction)
Deprecated.Not allowed - this is supposed to be unmodifiable
-
put
@Deprecated default V put(K key, V value)
Deprecated.Not compatible with immutability - useImMap.assoc(Object, Object)instead because it returns a new map.
-
putAll
@Deprecated default void putAll(@NotNull @NotNull Map<? extends K,? extends V> m)
Deprecated.Not allowed - this is supposed to be unmodifiable
-
putIfAbsent
@Deprecated default V putIfAbsent(K key, V value)
Deprecated.Not allowed - this is supposed to be unmodifiable- Specified by:
putIfAbsentin interfaceMap<K,V>
-
remove
@Deprecated default V remove(Object key)
Deprecated.Not allowed - this is supposed to be unmodifiable
-
remove
@Deprecated default boolean remove(Object key, Object value)
Deprecated.Not allowed - this is supposed to be unmodifiable
-
replace
@Deprecated default boolean replace(K key, V oldValue, V newValue)
Deprecated.Not allowed - this is supposed to be unmodifiable
-
replace
@Deprecated default V replace(K key, V value)
Deprecated.Not allowed - this is supposed to be unmodifiable
-
replaceAll
@Deprecated default void replaceAll(BiFunction<? super K,? super V,? extends V> function)
Deprecated.Not allowed - this is supposed to be unmodifiable- Specified by:
replaceAllin interfaceMap<K,V>
-
values
@Deprecated @NotNull default @NotNull UnmodCollection<V> values()
Deprecated.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:
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); });
-
-