Class SmoothieMap<K,V>
- java.lang.Object
-
- io.timeandspace.smoothie.SmoothieMap<K,V>
-
- Type Parameters:
K- the type of keys maintained by this mapV- the type of mapped values
public class SmoothieMap<K,V> extends Object implements ObjObjMap<K,V>
UnorderedMapwith worstputlatencies more than 100 times smaller than in ordinary hash table implementations likeHashMapand very low footprint per entry. SmoothieMap may also operate in the "low-garbage" or the "footprint" modes.SmoothieMap is created using a builder:
SmoothieMap.newBuilder().build(). See possible configurations in the documentation forSmoothieMapBuilder.Unlike
HashMap, but likeConcurrentHashMap,Map.of()immutable Maps, and Guava's ImmutableMaps, SmoothieMap does not support null key and values. An attempt to put null key or value, or query null key or value (e. g. viaget(null)), leads to aNullPointerException.SmoothieMapsupports pluggable keys' and values' equivalences which could be configured in the builder, viaSmoothieMapBuilder.keyEquivalence(Equivalence)andSmoothieMapBuilder.valueEquivalence(Equivalence)methods.Functional additions to the
Mapinterface implemented by SmoothieMap are described in the documentation forObjObjMapinterface. It also providessizeInBytes()to track the footprint of the map.Note that this implementation is not synchronized. If multiple threads access a
SmoothieMapconcurrently, and at least one of the threads modifies the map structurally, it must be synchronized externally. (A structural modification is any operation that adds or deletes one or more mappings; merely changing the value associated with a key that an instance already contains is not a structural modification.) This is typically accomplished by synchronizing on some object that naturally encapsulates the map.If no such object exists, the map should be "wrapped" using the
Collections.synchronizedMapmethod. This is best done at creation time, to prevent accidental unsynchronized access to the map:Map m = Collections.synchronizedMap(smoothieMap);
In terms of performance, favor calling bulk methods like
forEach(BiConsumer)to iterating theSmoothieMapviaIterator, including for-each style iterations on map's collections views. Especially if you need to remove entries during iteration (i. e. callIterator.remove()) and hash code for key objects is not cached on their side (like it is cached, for example, inStringclass) - try to express your logic usingremoveIf(BiPredicate)method in this case.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Map<K,V>asMapWithMutableIterators()voidclear()Removes all of the mappings from this map.@Nullable Vcompute(K key, BiFunction<? super K,? super @Nullable V,? extends @Nullable V> remappingFunction)Attempts to compute a mapping for the specified key and its current mapped value (ornullif there is no current mapping).@Nullable VcomputeIfAbsent(K key, Function<? super K,? extends @Nullable V> mappingFunction)If the specified key is not already associated with a value, attempts to compute its value using the given mapping function and enters it into this map unlessnull.@Nullable VcomputeIfPresent(K key, BiFunction<? super K,? super V,? extends @Nullable V> remappingFunction)If the value for the specified key is present and non-null, attempts to compute a new mapping given the key and its current mapped value.booleancontainsEntry(Object key, Object value)Returnstrueif this map contains a mapping of the given key and value.booleancontainsKey(Object key)Returnstrueif this map contains a mapping for the specified key.booleancontainsValue(Object value)Returnstrueif this map has one or more keys associated with the specified value.ObjSet<Map.Entry<K,V>>entrySet()Returns aSetview of the mappings contained in this map.booleanequals(Object obj)Returns true if the other object is aMap; this map and the given map have the same size; and for all entries in the other map,containsEntry(e.getKey(), e.getValue())called on this map returns true.voidforEach(BiConsumer<? super K,? super V> action)Performs the given action for each entry in this map until all entries have been processed or the action throws an exception.booleanforEachWhile(BiPredicate<? super K,? super V> predicate)Checks the givenpredicateon each entry in this map until all entries have been processed or the predicate returns false for some entry, or throws an Exception.@Nullable Vget(Object key)Returns the value to which the specified key is mapped, ornullif this map contains no mapping for the key.@Nullable KgetInternalKey(Object key)Returns the key object held by this map internally and equivalent to the specified key, if there is one, ornullif this map contains no mapping for the key.VgetOrDefault(Object key, V defaultValue)Returns the value to which the specified key is mapped, ordefaultValueif this map contains no mapping for the key.inthashCode()Returns a sum of the following expressions:keyEquivalence().hash(key) ^ valueEquivalence().hash(value)applied to all entries in this map.booleanisEmpty()Equivalence<K>keyEquivalence()Returns the equivalence strategy for keys for this map.ObjSet<K>keySet()Returns aSetview of the keys contained in this map.@Nullable Vmerge(K key, V value, BiFunction<? super V,? super V,? extends @Nullable V> remappingFunction)If the specified key is not already associated with a value or is associated with null, associates it with the given value.Iterator<Map.Entry<K,V>>mutableEntryIterator()Returns an iterator over the entries in this SmoothieMap that supportsIterator.remove()operation.Iterator<K>mutableKeyIterator()Returns an iterator over the keys in this SmoothieMap that supportsIterator.remove()operation.Iterator<V>mutableValueIterator()Returns an iterator over the values in this SmoothieMap that supportsIterator.remove()operation.static <K,V>
SmoothieMapBuilder<K,V>newBuilder()Creates a newSmoothieMapBuilder.@Nullable Vput(K key, V value)Associates the specified value with the specified key in this map.voidputAll(Map<? extends K,? extends V> m)Copies all of the mappings from the specified map to this map.@Nullable VputIfAbsent(K key, V value)If the specified key is not already associated with a value, associates it with the given value and returnsnull, else returns the current value.@Nullable Vremove(Object key)Removes the mapping for a key from this map if it is present.booleanremove(Object key, Object value)Removes the entry for the specified key only if it is currently mapped to the specified value.booleanremoveIf(BiPredicate<? super K,? super V> filter)Removes all of the entries of this map that satisfy the given predicate.Vreplace(K key, V value)Replaces the entry for the specified key only if it is currently mapped to some value.booleanreplace(K key, V oldValue, V newValue)Replaces the entry for the specified key only if currently mapped to the specified value.voidreplaceAll(BiFunction<? super K,? super V,? extends V> function)Replaces each entry's value with the result of invoking the given function on that entry until all entries have been processed or the function throws an exception.intsize()longsizeAsLong()Returns the number of entries in the map as alongvalue (not truncated toInteger.MAX_VALUE, if the map size exceeds it, as returned by theMap.size()method).longsizeInBytes()Returns the approximate footprint of thisSmoothieMapinstance in the heap of the JVM process, in bytes.StringtoString()Equivalence<V>valueEquivalence()Returns the equivalence strategy for values for this map.Collection<V>values()Returns aCollectionview of the values contained in this map.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface io.timeandspace.collect.map.ObjObjMap
mappingCount
-
-
-
-
Method Detail
-
newBuilder
@Contract(value=" -> new", pure=true) public static <K,V> SmoothieMapBuilder<K,V> newBuilder()
Creates a newSmoothieMapBuilder.- Type Parameters:
K- the type of keys in SmoothieMap(s) to be createdV- the type of values in SmoothieMap(s) to be created- Returns:
- a new
SmoothieMapBuilder
-
sizeInBytes
public final long sizeInBytes()
Returns the approximate footprint of thisSmoothieMapinstance in the heap of the JVM process, in bytes. Does not include the footprints of the keys and values stored in theSmoothieMap.- Returns:
- the approximate footprint of this
SmoothieMapproper
-
keyEquivalence
public Equivalence<K> keyEquivalence()
Description copied from interface:ObjObjMapReturns the equivalence strategy for keys for this map. All methods in theMapinterface which are defined in terms ofObject.equals(Object)equality of key objects use this Equivalence instead (includingObjObjMap.equals(java.lang.Object),ObjObjMap.hashCode(), andObjObjMap.keySet()'s andObjObjMap.entrySet()'sequals()andhashCode(), but excludingequals()andhashCode()ofMap.Entryobjects which can be obtained from theObjObjMap.entrySet()).- Specified by:
keyEquivalencein interfaceObjObjMap<K,V>- Returns:
- the equivalence strategy for keys for this map
-
valueEquivalence
public Equivalence<V> valueEquivalence()
Description copied from interface:ObjObjMapReturns the equivalence strategy for values for this map. All methods in theMapinterface which defined in terms ofObject.equals(Object)equality of value objects, such asObjObjMap.containsValue(Object)andObjObjMap.remove(Object, Object)use this Equivalence instead (includingObjObjMap.equals(java.lang.Object),ObjObjMap.hashCode(), andObjObjMap.entrySet()'sequals()andhashCode(), but excludingequals()andhashCode()ofMap.Entryobjects which can be obtained from theObjObjMap.entrySet()).- Specified by:
valueEquivalencein interfaceObjObjMap<K,V>- Returns:
- the equivalence strategy for values for this map
-
sizeAsLong
public final long sizeAsLong()
Description copied from interface:ObjObjMapReturns the number of entries in the map as alongvalue (not truncated toInteger.MAX_VALUE, if the map size exceeds it, as returned by theMap.size()method).- Specified by:
sizeAsLongin interfaceObjObjMap<K,V>- Returns:
- the number of key-value mappings in this map
- See Also:
Map.size(),ObjObjMap.mappingCount()
-
containsKey
public final boolean containsKey(Object key)
Description copied from interface:ObjObjMapReturnstrueif this map contains a mapping for the specified key. More formally, returnstrueif and only if this map contains a mapping for a keyksuch that the specifiedkeyandkare equivalent. (There can be at most one such mapping.)- Specified by:
containsKeyin interfaceMap<K,V>- Specified by:
containsKeyin interfaceObjObjMap<K,V>- Parameters:
key- key whose presence in this map is to be tested- Returns:
trueif this map contains a mapping for the specified key
-
containsEntry
public final boolean containsEntry(Object key, Object value)
Description copied from interface:ObjObjMapReturnstrueif this map contains a mapping of the given key and value. More formally, this map should contain a mapping from a keykto a valuevsuch that the specifiedkeyandkare equivalent with regard toObjObjMap.keyEquivalence(), and the specifiedvalueandvare equivalent with regard toObjObjMap.valueEquivalence(). (There can be at most one such mapping.)- Specified by:
containsEntryin interfaceObjObjMap<K,V>- Parameters:
key- the key of the mapping to check presence ofvalue- the value of the mapping to check presence of- Returns:
trueif this map contains the specified mapping,falseotherwise
-
getOrDefault
public final V getOrDefault(Object key, V defaultValue)
Description copied from interface:ObjObjMapReturns the value to which the specified key is mapped, ordefaultValueif this map contains no mapping for the key.- Specified by:
getOrDefaultin interfaceMap<K,V>- Specified by:
getOrDefaultin interfaceObjObjMap<K,V>- Parameters:
key- the key whose associated value is to be returneddefaultValue- the default mapping of the key- Returns:
- the value to which the specified key is mapped, or
defaultValueif this map contains no mapping for the key
-
remove
@CanIgnoreReturnValue public final @Nullable V remove(Object key)
Description copied from interface:ObjObjMapRemoves the mapping for a key from this map if it is present. More formally, if this map contains a mapping from keykto valuevsuch that the specifiedkeyandkare equivalent, that mapping is removed. (The map can contain at most one such mapping.)Returns the value to which this map previously associated the key, or
nullif the map contained no mapping for the key.The map will not contain a mapping for the specified key once the call returns.
-
remove
public final boolean remove(Object key, Object value)
Description copied from interface:ObjObjMapRemoves the entry for the specified key only if it is currently mapped to the specified value. Values are compared usingObjObjMap.valueEquivalence().
-
replace
public final V replace(K key, V value)
Description copied from interface:ObjObjMapReplaces the entry for the specified key only if it is currently mapped to some value.- Specified by:
replacein interfaceMap<K,V>- Specified by:
replacein interfaceObjObjMap<K,V>- Parameters:
key- key with which the specified value is associatedvalue- value to be associated with the specified key- Returns:
- the previous value associated with the specified key, or
nullif there was no mapping for the key.
-
replace
public final boolean replace(K key, V oldValue, V newValue)
Description copied from interface:ObjObjMapReplaces the entry for the specified key only if currently mapped to the specified value. Values are compared usingObjObjMap.valueEquivalence().- Specified by:
replacein interfaceMap<K,V>- Specified by:
replacein interfaceObjObjMap<K,V>- Parameters:
key- key with which the specified value is associatedoldValue- value expected to be associated with the specified keynewValue- value to be associated with the specified key- Returns:
trueif the value was replaced
-
put
@CanIgnoreReturnValue public final @Nullable V put(K key, V value)
Description copied from interface:ObjObjMapAssociates the specified value with the specified key in this map. If the map previously contained a mapping for the key, the old value is replaced by the specified value. (A mapmis said to contain a mapping for a keykif and only ifm.containsKey(k)would returntrue.)- Specified by:
putin interfaceMap<K,V>- Specified by:
putin interfaceObjObjMap<K,V>- Parameters:
key- key with which the specified value is to be associatedvalue- value to be associated with the specified key- Returns:
- the previous value associated with
key, ornullif there was no mapping forkey
-
putIfAbsent
public final @Nullable V putIfAbsent(K key, V value)
Description copied from interface:ObjObjMapIf the specified key is not already associated with a value, associates it with the given value and returnsnull, else returns the current value.- Specified by:
putIfAbsentin interfaceMap<K,V>- Specified by:
putIfAbsentin interfaceObjObjMap<K,V>- Parameters:
key- key with which the specified value is to be associatedvalue- value to be associated with the specified key- Returns:
- the previous value associated with the specified key, or
nullif there was no mapping for the key
-
get
public final @Nullable V get(Object key)
Description copied from interface:ObjObjMapReturns the value to which the specified key is mapped, ornullif this map contains no mapping for the key.More formally, if this map contains a mapping from a key
kto a valuevsuch that the specifiedkeyandkare equivalent, then this method returnsv; otherwise it returnsnull. (There can be at most one such mapping.)
-
getInternalKey
public final @Nullable K getInternalKey(Object key)
Description copied from interface:ObjObjMapReturns the key object held by this map internally and equivalent to the specified key, if there is one, ornullif this map contains no mapping for the key.This method could be used to deduplicate objects in the application, to reduce the memory footprint and make the application to conform to the "most objects die young" hypothesis that most GC algorithms are optimized for. This method is functionally similar to
String.intern()and Guava's Interner, but allows to piggy-back a map data structure which may already exist in an application.ObjObjMap.keySet().getInternal(key)delegates to this method.- Specified by:
getInternalKeyin interfaceObjObjMap<K,V>- Parameters:
key- the key whose equivalent held by this map internally is to be returned- Returns:
- the map-internal equivalent of the specified key, or
nullif the map contains no mapping for the specified key
-
computeIfPresent
public final @Nullable V computeIfPresent(K key, BiFunction<? super K,? super V,? extends @Nullable V> remappingFunction)
Description copied from interface:ObjObjMapIf the value for the specified key is present and non-null, attempts to compute a new mapping given the key and its current mapped value.If the function returns
null, the mapping is removed. If the function itself throws an (unchecked) exception, the exception is rethrown, and the current mapping is left unchanged.- Specified by:
computeIfPresentin interfaceMap<K,V>- Specified by:
computeIfPresentin interfaceObjObjMap<K,V>- Parameters:
key- key with which the specified value is to be associatedremappingFunction- the function to compute a value- Returns:
- the new value associated with the specified key, or null if none
-
computeIfAbsent
public final @Nullable V computeIfAbsent(K key, Function<? super K,? extends @Nullable V> mappingFunction)
Description copied from interface:ObjObjMapIf the specified key is not already associated with a value, attempts to compute its value using the given mapping function and enters it into this map unlessnull.If the function returns
nullno mapping is recorded. If the function itself throws an (unchecked) exception, the exception is rethrown, and no mapping is recorded. The most common usage is to construct a new object serving as an initial mapped value or memoized result, as in:map.computeIfAbsent(key, k -> new Value(f(k)));Or to implement a multi-value map,
Map<K,Collection<V>>, supporting multiple values per key:map.computeIfAbsent(key, k -> new HashSet<V>()).add(v);- Specified by:
computeIfAbsentin interfaceMap<K,V>- Specified by:
computeIfAbsentin interfaceObjObjMap<K,V>- Parameters:
key- key with which the specified value is to be associatedmappingFunction- the function to compute a value- Returns:
- the current (existing or computed) value associated with the specified key, or null if the computed value is null
-
compute
public final @Nullable V compute(K key, BiFunction<? super K,? super @Nullable V,? extends @Nullable V> remappingFunction)
Description copied from interface:ObjObjMapAttempts to compute a mapping for the specified key and its current mapped value (ornullif there is no current mapping). For example, to either create or append aStringmsg to a value mapping:
(Methodmap.compute(key, (k, v) -> (v == null) ? msg : v.concat(msg))merge()is often simpler to use for such purposes.)If the function returns
null, the mapping is removed (or remains absent if initially absent). If the function itself throws an (unchecked) exception, the exception is rethrown, and the current mapping is left unchanged.
-
merge
public final @Nullable V merge(K key, V value, BiFunction<? super V,? super V,? extends @Nullable V> remappingFunction)
Description copied from interface:ObjObjMapIf the specified key is not already associated with a value or is associated with null, associates it with the given value. Otherwise, replaces the associated value with the results of the given remapping function, or removes if the result isnull. This method may be of use when combining multiple mapped values for a key. For example, to either create or append aString msgto a value mapping:map.merge(key, msg, String::concat)If the function returns
nullthe mapping is removed. If the function itself throws an (unchecked) exception, the exception is rethrown, and the current mapping is left unchanged.- Specified by:
mergein interfaceMap<K,V>- Specified by:
mergein interfaceObjObjMap<K,V>- Parameters:
key- key with which the resulting value is to be associatedvalue- the value to be merged with the existing value associated with the key or, if no existing value is associated with the key, to be associated with the keyremappingFunction- the function to recompute a value if present- Returns:
- the new value associated with the specified key, or null if no value is associated with the key
-
equals
public boolean equals(Object obj)
Description copied from interface:ObjObjMapReturns true if the other object is aMap; this map and the given map have the same size; and for all entries in the other map,containsEntry(e.getKey(), e.getValue())called on this map returns true.Note that the specification above means that
equals()depends onObjObjMap.keyEquivalence()andObjObjMap.valueEquivalence()of this map, if they are custom. This may be inconsistent with the generalMap.equals(java.lang.Object)contract.
-
hashCode
public final int hashCode()
Description copied from interface:ObjObjMapReturns a sum of the following expressions:keyEquivalence().hash(key) ^ valueEquivalence().hash(value)applied to all entries in this map. Note that if this map has a customObjObjMap.keyEquivalence()orObjObjMap.valueEquivalence(), the resulting hash code may be inconsistent with the generalMap.hashCode()contract.
-
forEach
public final void forEach(BiConsumer<? super K,? super V> action)
Description copied from interface:ObjObjMapPerforms the given action for each entry in this map until all entries have been processed or the action throws an exception. Actions are performed in the order of entry set iteration. Exceptions thrown by the action are relayed to the caller.The entries will be processed in the same order as they appear the entry set's iterator and
ObjObjMap.forEachWhile(BiPredicate).
-
forEachWhile
public final boolean forEachWhile(BiPredicate<? super K,? super V> predicate)
Description copied from interface:ObjObjMapChecks the givenpredicateon each entry in this map until all entries have been processed or the predicate returns false for some entry, or throws an Exception. Exceptions thrown by the predicate are relayed to the caller.The entries will be processed in the same order as they appear in the entry set's iterator and
ObjObjMap.forEach(BiConsumer).If the map is empty, this method returns
trueimmediately.- Specified by:
forEachWhilein interfaceObjObjMap<K,V>- Parameters:
predicate- the predicate to be checked for each entry- Returns:
trueif the map is empty, or if the predicate returnedtruefor all entries of the map,falseif the predicate returnedfalsefor some entry- See Also:
ObjObjMap.forEach(BiConsumer)
-
replaceAll
public final void replaceAll(BiFunction<? super K,? super V,? extends V> function)
Description copied from interface:ObjObjMapReplaces each entry's value with the result of invoking the given function on that entry until all entries have been processed or the function throws an exception. Exceptions thrown by the function are relayed to the caller.- Specified by:
replaceAllin interfaceMap<K,V>- Specified by:
replaceAllin interfaceObjObjMap<K,V>- Parameters:
function- the function to apply to each entry
-
containsValue
public final boolean containsValue(Object value)
Description copied from interface:ObjObjMapReturnstrueif this map has one or more keys associated with the specified value. More formally, returnstrueif and only if this map contains at least one mapping to a valuevsuch thatObjObjMap.valueEquivalence().equivalent(value, v) == true. This operation requires time linear in the map size.- Specified by:
containsValuein interfaceMap<K,V>- Specified by:
containsValuein interfaceObjObjMap<K,V>- Parameters:
value- value whose presence in this map is to be tested- Returns:
trueif this map maps one or more keys to the specified value
-
putAll
public final void putAll(Map<? extends K,? extends V> m)
Description copied from interface:ObjObjMapCopies all of the mappings from the specified map to this map. The effect of this call is equivalent to that of callingput(k, v)on this map once for each mapping from keykto valuevin the specified map. The behavior of this operation is undefined if the specified map is modified while the operation is in progress.
-
clear
public final void clear()
Description copied from interface:ObjObjMapRemoves all of the mappings from this map. The map will be empty after this call returns.
-
removeIf
public final boolean removeIf(BiPredicate<? super K,? super V> filter)
Description copied from interface:ObjObjMapRemoves all of the entries of this map that satisfy the given predicate. Errors or runtime exceptions thrown during iteration or by the predicate are relayed to the caller.Note the order in which this method visits entries may be different from the iteration and
ObjObjMap.forEach(BiConsumer)order.
-
keySet
@EnsuresNonNull("keySet") public final ObjSet<K> keySet()
Returns aSetview of the keys contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa.If a structural modification of the map (new entry insertion or an entry removal) is detected while an iteration over the set is in progress (except through the iterator's own
removeoperation),ConcurrentModificationExceptionis thrown.The set supports element removal, which removes the corresponding mapping from the map, via the
Iterator.remove()(optionally),Set.remove(java.lang.Object),Set.removeAll(java.util.Collection<?>),Set.retainAll(java.util.Collection<?>), andSet.clear()operations.Set.remove(java.lang.Object),Set.contains(java.lang.Object), andSet.containsAll(java.util.Collection<?>)operations on the returned set as well as key set's ownequals()andhashCode()respect the map'sObjObjMap.keyEquivalence(). When this map has a customObjObjMap.keyEquivalence(),equals()on the key set works as follows: another object is considered equal to the key set if it is aSetwhich has the same size as this map and for all elements in another set,keySet.contains(elementOfAnotherSet)returns true.hashCode()on the key set returns a sum of results of calls toEquivalence.hash(T)on all elements in the key set.The key set does not support the
Set.add(E)andSet.addAll(java.util.Collection<? extends E>)operations.The set is created the first time this method is called, and returned in response to all subsequent calls. No synchronization is performed, so there is a slight chance that multiple calls to this method will not all return the same set.
Calling
Set.iterator()on the key set returns an iterator that may not supportIterator.remove(). UseasMapWithMutableIterators().keySet()ormutableKeyIterator()methods instead if you need to remove entries while iterating a SmoothieMap.
-
mutableKeyIterator
public Iterator<K> mutableKeyIterator()
Returns an iterator over the keys in this SmoothieMap that supportsIterator.remove()operation. This method may be usable because iterator ofkeySet()may not supportIterator.remove().- Returns:
- a remove-supporting iterator over the keys in this SmoothieMap
-
values
@EnsuresNonNull("values") public final Collection<V> values()
Returns aCollectionview of the values contained in this map. The collection is backed by the map, so changes to the map are reflected in the collection, and vice-versa.If a structural modification of the map (new entry insertion or an entry removal) is detected while an iteration over the collection is in progress (except through the iterator's own
removeoperation),ConcurrentModificationExceptionis thrown.The collection supports element removal, which removes the corresponding mapping from the map, via the
Iterator.remove()(optionally),Collection.remove(java.lang.Object),Collection.removeAll(java.util.Collection<?>),Collection.retainAll(java.util.Collection<?>)andCollection.clear()operations.Collection.remove(java.lang.Object),Collection.contains(java.lang.Object), andCollection.containsAll(java.util.Collection<?>)on the returned collection respect the map'sObjObjMap.valueEquivalence().The values collection does not support the
addoraddAlloperations.The collection is created the first time this method is called, and returned in response to all subsequent calls. No synchronization is performed, so there is a slight chance that multiple calls to this method will not all return the same collection.
Calling
Collection.iterator()on the values view returns an iterator that may not supportIterator.remove(). UseasMapWithMutableIterators().values()ormutableValueIterator()methods instead if you need to remove entries while iterating a SmoothieMap.
-
mutableValueIterator
public Iterator<V> mutableValueIterator()
Returns an iterator over the values in this SmoothieMap that supportsIterator.remove()operation. This method may be usable because iterator ofvalues()may not supportIterator.remove().- Returns:
- a remove-supporting iterator over the values in this SmoothieMap
-
entrySet
@EnsuresNonNull("entrySet") public final ObjSet<Map.Entry<K,V>> entrySet()
Returns aSetview of the mappings contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa.If a structural modification of the map (new entry insertion or an entry removal) is detected while an iteration over the set is in progress (except through the iterator's own
removeoperation),ConcurrentModificationExceptionis thrown.The set supports element removal, which removes the corresponding mapping from the map, via the
Iterator.remove()(optionally),Set.remove(java.lang.Object),Set.removeAll(java.util.Collection<?>),Set.retainAll(java.util.Collection<?>), andSet.clear()operations.Set.remove(java.lang.Object),Set.contains(java.lang.Object), andSet.containsAll(java.util.Collection<?>)operations on the returned set as well as entry set's ownequals()andhashCode()respect the map'sObjObjMap.keyEquivalence()andObjObjMap.valueEquivalence(), but the implementations ofequals()andhashCode()for theMap.Entryobjects which can be obtained from the set use built-in Java object equality and hash code for the map's keys and values.When this map has a custom
ObjObjMap.keyEquivalence()orObjObjMap.valueEquivalence(),equals()on the entry set works as follows: another object is considered equal to the entry set if it is aSetwhich has the same size as this map; all elements in another set areMap.Entryobjects; and for all the entries in another set,thisMap.containsEntry(entryFromAnotherSet.getKey(), entryFromAnotherSet.getValue())returns true.hashCode()on the entry set is the same as on the map itself, seeObjObjMap.hashCode().The entry set does not support the
Set.add(E)andSet.addAll(java.util.Collection<? extends E>)operations.The set is created the first time this method is called, and returned in response to all subsequent calls. No synchronization is performed, so there is a slight chance that multiple calls to this method will not all return the same set.
Calling
Collection.iterator()on the entry set returns an iterator that may not supportIterator.remove(). UseasMapWithMutableIterators().entrySet()ormutableEntryIterator()methods instead if you need to remove entries while iterating a SmoothieMap.An entry set view returned from this method also doesn't support
ObjSet.getInternal(E)operation.
-
mutableEntryIterator
public Iterator<Map.Entry<K,V>> mutableEntryIterator()
Returns an iterator over the entries in this SmoothieMap that supportsIterator.remove()operation. This method may be usable because iterator ofentrySet()may not supportIterator.remove().- Returns:
- a remove-supporting iterator over the entries in this SmoothieMap
-
-