Class AbstractMemoryEfficientMutableMap<K,V>
java.lang.Object
org.eclipse.collections.impl.AbstractRichIterable<V>
org.eclipse.collections.impl.map.AbstractMapIterable<K,V>
org.eclipse.collections.impl.map.mutable.AbstractMutableMapIterable<K,V>
org.eclipse.collections.impl.map.mutable.AbstractMutableMap<K,V>
org.eclipse.collections.impl.map.fixed.AbstractMemoryEfficientMutableMap<K,V>
- All Implemented Interfaces:
Cloneable
,Iterable<V>
,Map<K,
,V> InternalIterable<V>
,FixedSizeMap<K,
,V> MapIterable<K,
,V> MutableMap<K,
,V> MutableMapIterable<K,
,V> UnsortedMapIterable<K,
,V> RichIterable<V>
- Direct Known Subclasses:
DoubletonMap
,EmptyMap
,SingletonMap
,TripletonMap
abstract class AbstractMemoryEfficientMutableMap<K,V>
extends AbstractMutableMap<K,V>
implements FixedSizeMap<K,V>
-
Nested Class Summary
Nested classes/interfaces inherited from class org.eclipse.collections.impl.map.mutable.AbstractMutableMap
AbstractMutableMap.ValuesCollectionCommon<V>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
abstract <K2,
V2> FixedSizeMap <K2, V2> For each key and value of the map the function is evaluated.<E> MutableMap
<K, V> collectKeysAndValues
(Iterable<E> iterable, Function<? super E, ? extends K> keyFunction, Function<? super E, ? extends V> valueFunction) Adds all the entries derived fromiterable
tothis
.abstract <R> FixedSizeMap
<K, R> collectValues
(Function2<? super K, ? super V, ? extends R> function) For each key and value of the map the function is evaluated.MutableMap
<K, V> newEmpty()
Creates a new instance of the same type, using the default capacity and growth parameters.MutableMap
<K, V> newEmpty
(int capacity) Creates a new instance of the same type, using the given capacity and the default growth parameters.void
abstract FixedSizeMap
<K, V> reject
(Predicate2<? super K, ? super V> predicate) For each key and value of the map the predicate is evaluated, if the result of the evaluation is false, that key and value are returned in a new map.boolean
removeAllKeys
(Set<? extends K> keys) Remove entries from the map at the specifiedkeys
.boolean
removeIf
(Predicate2<? super K, ? super V> predicate) Remove an entry from the map if thepredicate
evaluates to true.Remove an entry from the map at the specifiedkey
.abstract FixedSizeMap
<K, V> select
(Predicate2<? super K, ? super V> predicate) For each key and value of the map the predicate is evaluated, if the result of the evaluation is true, that key and value are returned in a new map.Executes the Procedure for each value of the map and returnsthis
.Looks up the value associated withkey
, applies thefunction
to it, and replaces the value.<P> V
updateValueWith
(K key, Function0<? extends V> factory, Function2<? super V, ? super P, ? extends V> function, P parameter) Same asMutableMapIterable.updateValue(Object, Function0, Function)
with a Function2 and specified parameter which is passed to the function.MutableMap
<K, V> withAllKeyValueArguments
(Pair<? extends K, ? extends V>... keyValues) Convenience var-args version of withAllKeyValuesMutableMap
<K, V> withAllKeyValues
(Iterable<? extends Pair<? extends K, ? extends V>> keyValues) This method allows mutable, fixed size, and immutable maps the ability to add elements to their existing elements.MutableMap
<K, V> withoutAllKeys
(Iterable<? extends K> keys) This method allows mutable, fixed size, and immutable maps the ability to remove elements from their existing elements.Methods inherited from class org.eclipse.collections.impl.map.mutable.AbstractMutableMap
asSynchronized, asUnmodifiable, clone, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, flatCollect, flip, groupBy, groupByEach, groupByUniqueKey, partition, partitionWith, reject, rejectWith, select, selectInstancesOf, selectWith, toImmutable, withKeyValue, withoutKey, zip, zipWithIndex
Methods inherited from class org.eclipse.collections.impl.map.mutable.AbstractMutableMapIterable
aggregateBy, countBy, countByEach, countByWith, detect, detectOptional, flipUniqueValues, getIfAbsentPut, getIfAbsentPut, getIfAbsentPutWith, getIfAbsentPutWithKey, iterator, keysView, keyValuesView, sumByDouble, sumByFloat, sumByInt, sumByLong, valuesView
Methods inherited from class org.eclipse.collections.impl.map.AbstractMapIterable
allSatisfy, allSatisfyWith, anySatisfy, anySatisfyWith, asLazy, chunk, contains, detect, detectIfNone, detectOptional, detectWith, detectWithIfNone, detectWithOptional, each, forEachKey, forEachValue, forEachWith, forEachWithIndex, getFirst, getIfAbsent, getIfAbsentValue, getIfAbsentWith, getLast, getOnly, getOrDefault, ifPresentApply, isAbsent, keyAndValueEquals, keyAndValueHashCode, noneSatisfy, noneSatisfyWith, toArray, toArray
Methods inherited from class org.eclipse.collections.impl.AbstractRichIterable
appendString, appendString, collect, collectIf, collectWith, containsAll, containsAllArguments, containsAllIterable, count, countWith, flatCollect, forEach, groupBy, groupByEach, groupByUniqueKey, injectInto, injectInto, injectInto, injectInto, injectInto, into, isEmpty, max, max, maxBy, min, min, minBy, reject, rejectWith, select, selectWith, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toBag, toBiMap, toList, toMap, toSet, toSortedBag, toSortedBag, toSortedBagBy, toSortedListBy, toSortedMap, toSortedMap, toSortedMapBy, toSortedSet, toSortedSet, toSortedSetBy, toString, zip, zipWithIndex
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.eclipse.collections.api.map.FixedSizeMap
putAllMapIterable, withMap, withMapIterable
Methods inherited from interface org.eclipse.collections.api.InternalIterable
forEach, forEachWith, forEachWithIndex
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, equals, forEach, get, hashCode, isEmpty, keySet, merge, putIfAbsent, remove, replace, replace, replaceAll, size, values
Methods inherited from interface org.eclipse.collections.api.map.MapIterable
containsKey, containsValue, detect, detectOptional, equals, forEachKey, forEachKeyValue, forEachValue, get, getIfAbsent, getIfAbsentValue, getIfAbsentWith, hashCode, ifPresentApply, injectIntoKeyValue, keysView, keyValuesView, parallelStream, spliterator, stream, toString, valuesView
Methods inherited from interface org.eclipse.collections.api.map.MutableMap
aggregateBy, aggregateBy, aggregateInPlaceBy, asSynchronized, asUnmodifiable, clone, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, flatCollect, flatCollectWith, flip, flipUniqueValues, groupBy, groupByEach, groupByUniqueKey, partition, partitionWith, reject, rejectWith, select, selectInstancesOf, selectWith, withKeyValue, withoutKey, zip, zipWithIndex
Methods inherited from interface org.eclipse.collections.api.map.MutableMapIterable
add, countBy, countByEach, countByWith, getIfAbsentPut, getIfAbsentPut, getIfAbsentPutWith, getIfAbsentPutWithKey, getOrDefault, putPair, sumByDouble, sumByFloat, sumByInt, sumByLong, toImmutable
Methods inherited from interface org.eclipse.collections.api.RichIterable
aggregateBy, allSatisfy, allSatisfyWith, anySatisfy, anySatisfyWith, appendString, appendString, appendString, asLazy, chunk, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, contains, containsAll, containsAllArguments, containsAllIterable, containsAny, containsAnyIterable, containsBy, containsNone, containsNoneIterable, count, countBy, countByEach, countByWith, countWith, detect, detectIfNone, detectOptional, detectWith, detectWithIfNone, detectWithOptional, each, flatCollect, flatCollectBoolean, flatCollectByte, flatCollectChar, flatCollectDouble, flatCollectFloat, flatCollectInt, flatCollectLong, flatCollectShort, flatCollectWith, forEach, getAny, getFirst, getLast, getOnly, groupBy, groupByAndCollect, groupByEach, groupByUniqueKey, injectInto, injectInto, injectInto, injectInto, injectInto, injectIntoDouble, injectIntoFloat, injectIntoInt, injectIntoLong, into, isEmpty, makeString, makeString, makeString, makeString, max, max, maxBy, maxByOptional, maxOptional, maxOptional, min, min, minBy, minByOptional, minOptional, minOptional, noneSatisfy, noneSatisfyWith, notEmpty, reduce, reduceInPlace, reduceInPlace, reject, rejectWith, select, selectWith, size, summarizeDouble, summarizeFloat, summarizeInt, summarizeLong, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toArray, toArray, toBag, toBiMap, toImmutableBag, toImmutableBiMap, toImmutableList, toImmutableMap, toImmutableSet, toImmutableSortedBag, toImmutableSortedBag, toImmutableSortedBagBy, toImmutableSortedList, toImmutableSortedList, toImmutableSortedListBy, toImmutableSortedSet, toImmutableSortedSet, toImmutableSortedSetBy, toList, toMap, toMap, toSet, toSortedBag, toSortedBag, toSortedBagBy, toSortedList, toSortedList, toSortedListBy, toSortedMap, toSortedMap, toSortedMapBy, toSortedSet, toSortedSet, toSortedSetBy, zip, zipWithIndex
Methods inherited from interface org.eclipse.collections.api.map.UnsortedMapIterable
toImmutable
-
Constructor Details
-
AbstractMemoryEfficientMutableMap
AbstractMemoryEfficientMutableMap()
-
-
Method Details
-
put
-
remove
-
putAll
-
clear
public void clear() -
removeKey
Description copied from interface:MutableMapIterable
Remove an entry from the map at the specifiedkey
.- Specified by:
removeKey
in interfaceFixedSizeMap<K,
V> - Specified by:
removeKey
in interfaceMutableMapIterable<K,
V> - Returns:
- The value removed from entry at key, or null if not found.
- See Also:
-
removeAllKeys
Description copied from interface:MutableMapIterable
Remove entries from the map at the specifiedkeys
.- Specified by:
removeAllKeys
in interfaceFixedSizeMap<K,
V> - Specified by:
removeAllKeys
in interfaceMutableMapIterable<K,
V> - Returns:
true
if this map changed as a result of the call
-
removeIf
Description copied from interface:MutableMapIterable
Remove an entry from the map if thepredicate
evaluates to true.- Specified by:
removeIf
in interfaceFixedSizeMap<K,
V> - Specified by:
removeIf
in interfaceMutableMapIterable<K,
V> - Returns:
- true if any entry is removed.
-
collectKeysAndValues
public <E> MutableMap<K,V> collectKeysAndValues(Iterable<E> iterable, Function<? super E, ? extends K> keyFunction, Function<? super E, ? extends V> valueFunction) Description copied from interface:MutableMap
Adds all the entries derived fromiterable
tothis
. The key and value for each entry is determined by applying thekeyFunction
andvalueFunction
to each item incollection
. Any entry inmap
that has the same key as an entry inthis
will have its value replaced by that inmap
.- Specified by:
collectKeysAndValues
in interfaceMutableMap<K,
V>
-
updateValue
public V updateValue(K key, Function0<? extends V> factory, Function<? super V, ? extends V> function) Description copied from interface:MutableMapIterable
Looks up the value associated withkey
, applies thefunction
to it, and replaces the value. If there is no value associated withkey
, starts it off with a value supplied byfactory
.- Specified by:
updateValue
in interfaceMutableMapIterable<K,
V> - Overrides:
updateValue
in classAbstractMutableMapIterable<K,
V>
-
updateValueWith
public <P> V updateValueWith(K key, Function0<? extends V> factory, Function2<? super V, ? super P, ? extends V> function, P parameter) Description copied from interface:MutableMapIterable
Same asMutableMapIterable.updateValue(Object, Function0, Function)
with a Function2 and specified parameter which is passed to the function.- Specified by:
updateValueWith
in interfaceMutableMapIterable<K,
V> - Overrides:
updateValueWith
in classAbstractMutableMapIterable<K,
V>
-
newEmpty
Description copied from interface:MutableMapIterable
Creates a new instance of the same type, using the default capacity and growth parameters.- Specified by:
newEmpty
in interfaceMutableMap<K,
V> - Specified by:
newEmpty
in interfaceMutableMapIterable<K,
V>
-
newEmpty
Description copied from class:AbstractMutableMap
Creates a new instance of the same type, using the given capacity and the default growth parameters.- Specified by:
newEmpty
in classAbstractMutableMap<K,
V>
-
withAllKeyValues
public MutableMap<K,V> withAllKeyValues(Iterable<? extends Pair<? extends K, ? extends V>> keyValues) Description copied from interface:MutableMapIterable
This method allows mutable, fixed size, and immutable maps the ability to add elements to their existing elements. In order to support fixed size maps, a new instance of a map would have to be returned including the keys and values of the original plus all the additional keys and values. In the case of mutable maps, the original map is modified and then returned. In order to use this method properly with mutable and fixed size maps the following approach must be taken:map = map.withAllKeyValues(FastList.newListWith(PairImpl.of("new key", "new value")));
In the case of FixedSizeMap, a new instance will be returned by withAllKeyValues, and any variables that previously referenced the original map will need to be redirected to reference the new instance. In the case of a FastMap or UnifiedMap, you will be replacing the reference to map with map, since FastMap and UnifiedMap will both return "this" after calling put on themselves.- Specified by:
withAllKeyValues
in interfaceMutableMap<K,
V> - Specified by:
withAllKeyValues
in interfaceMutableMapIterable<K,
V> - Overrides:
withAllKeyValues
in classAbstractMutableMap<K,
V> - See Also:
-
withAllKeyValueArguments
Description copied from interface:MutableMapIterable
Convenience var-args version of withAllKeyValues- Specified by:
withAllKeyValueArguments
in interfaceMutableMap<K,
V> - Specified by:
withAllKeyValueArguments
in interfaceMutableMapIterable<K,
V> - Overrides:
withAllKeyValueArguments
in classAbstractMutableMap<K,
V> - See Also:
-
withoutAllKeys
Description copied from interface:MutableMapIterable
This method allows mutable, fixed size, and immutable maps the ability to remove elements from their existing elements. In order to support fixed size maps, a new instance of a map would have to be returned including the keys and values of the original minus all the keys and values to be removed. In the case of mutable maps, the original map is modified and then returned. In order to use this method properly with mutable and fixed size maps the following approach must be taken:map = map.withoutAllKeys(FastList.newListWith("key1", "key2"));
In the case of FixedSizeMap, a new instance will be returned by withoutAllKeys, and any variables that previously referenced the original map will need to be redirected to reference the new instance. In the case of a FastMap or UnifiedMap, you will be replacing the reference to map with map, since FastMap and UnifiedMap will both return "this" after calling remove on themselves.- Specified by:
withoutAllKeys
in interfaceMutableMap<K,
V> - Specified by:
withoutAllKeys
in interfaceMutableMapIterable<K,
V> - Overrides:
withoutAllKeys
in classAbstractMutableMap<K,
V> - See Also:
-
tap
Description copied from interface:MapIterable
Executes the Procedure for each value of the map and returnsthis
.return peopleByCity.tap(person -> LOGGER.info(person.getName()));
- Specified by:
tap
in interfaceFixedSizeMap<K,
V> - Specified by:
tap
in interfaceMapIterable<K,
V> - Specified by:
tap
in interfaceMutableMap<K,
V> - Specified by:
tap
in interfaceMutableMapIterable<K,
V> - Specified by:
tap
in interfaceRichIterable<K>
- Specified by:
tap
in interfaceUnsortedMapIterable<K,
V> - Overrides:
tap
in classAbstractMutableMap<K,
V> - See Also:
-
select
Description copied from interface:MapIterable
For each key and value of the map the predicate is evaluated, if the result of the evaluation is true, that key and value are returned in a new map.MapIterable<City, Person> selected = peopleByCity.select((city, person) -> city.getName().equals("Anytown") && person.getLastName().equals("Smith"));
- Specified by:
select
in interfaceMapIterable<K,
V> - Specified by:
select
in interfaceMutableMap<K,
V> - Specified by:
select
in interfaceMutableMapIterable<K,
V> - Specified by:
select
in interfaceUnsortedMapIterable<K,
V> - Overrides:
select
in classAbstractMutableMap<K,
V>
-
collectValues
public abstract <R> FixedSizeMap<K,R> collectValues(Function2<? super K, ? super V, ? extends R> function) Description copied from interface:MapIterable
For each key and value of the map the function is evaluated. The results of these evaluations are returned in a new map. The map returned will use the values projected from the function rather than the original values.MapIterable<City, String> collected = peopleByCity.collectValues((City city, Person person) -> person.getFirstName() + " " + person.getLastName());
- Specified by:
collectValues
in interfaceMapIterable<K,
V> - Specified by:
collectValues
in interfaceMutableMap<K,
V> - Specified by:
collectValues
in interfaceMutableMapIterable<K,
V> - Specified by:
collectValues
in interfaceUnsortedMapIterable<K,
V> - Overrides:
collectValues
in classAbstractMutableMap<K,
V>
-
collect
public abstract <K2,V2> FixedSizeMap<K2,V2> collect(Function2<? super K, ? super V, Pair<K2, V2>> function) Description copied from interface:MapIterable
For each key and value of the map the function is evaluated. The results of these evaluations are returned in a new map. The map returned will use the values projected from the function rather than the original values.MapIterable<String, String> collected = peopleByCity.collect((City city, Person person) -> Pair.of(city.getCountry(), person.getAddress().getCity()));
- Specified by:
collect
in interfaceMapIterable<K,
V> - Specified by:
collect
in interfaceMutableMap<K,
V> - Specified by:
collect
in interfaceMutableMapIterable<K,
V> - Specified by:
collect
in interfaceUnsortedMapIterable<K,
V> - Overrides:
collect
in classAbstractMutableMapIterable<K,
V>
-
reject
Description copied from interface:MapIterable
For each key and value of the map the predicate is evaluated, if the result of the evaluation is false, that key and value are returned in a new map.MapIterable<City, Person> rejected = peopleByCity.reject((city, person) -> city.getName().equals("Anytown") && person.getLastName().equals("Smith"));
- Specified by:
reject
in interfaceMapIterable<K,
V> - Specified by:
reject
in interfaceMutableMap<K,
V> - Specified by:
reject
in interfaceMutableMapIterable<K,
V> - Specified by:
reject
in interfaceUnsortedMapIterable<K,
V> - Overrides:
reject
in classAbstractMutableMap<K,
V>
-