Class MapAdapter<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.mutable.MapAdapter<K,V>
- All Implemented Interfaces:
Serializable
,Cloneable
,Iterable<V>
,Map<K,V>
,InternalIterable<V>
,MapIterable<K,V>
,MutableMap<K,V>
,MutableMapIterable<K,V>
,UnsortedMapIterable<K,V>
,RichIterable<V>
public class MapAdapter<K,V> extends AbstractMutableMap<K,V> implements Serializable
This class provides a MutableMap wrapper around a JDK Collections Map interface instance. All of the MutableMap
interface methods are supported in addition to the JDK Map interface methods.
To create a new wrapper around an existing Map instance, use the adapt(Map)
factory method.
- See Also:
- Serialized Form
-
Nested Class Summary
-
Method Summary
Modifier and Type Method Description static <K, V> MutableMap<K,V>
adapt(Map<K,V> map)
void
clear()
MutableMap<K,V>
clone()
<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
.boolean
containsKey(Object key)
boolean
containsValue(Object value)
Set<Map.Entry<K,V>>
entrySet()
boolean
equals(Object o)
Follows the same general contract asMap.equals(Object)
.void
forEachKeyValue(Procedure2<? super K,? super V> procedure)
Calls theprocedure
with each key-value pair of the map.V
get(Object key)
int
hashCode()
Follows the same general contract asMap.hashCode()
.boolean
isEmpty()
Returns true if this iterable has zero items.Iterator<V>
iterator()
Set<K>
keySet()
MutableMap<K,V>
newEmpty()
Creates a new instance of the same type, using the default capacity and growth parameters.<K, V> MutableMap<K,V>
newEmpty(int capacity)
Creates a new instance of the same type, using the given capacity and the default growth parameters.V
put(K key, V value)
void
putAll(Map<? extends K,? extends V> map)
V
remove(Object key)
V
removeKey(K key)
Remove an entry from the map at the specifiedkey
.int
size()
Returns the number of items in this iterable.ImmutableMap<K,V>
toImmutable()
Returns an immutable copy of this map.String
toString()
Returns a string with the elements of the iterable separated by commas with spaces and enclosed in square brackets.Collection<V>
values()
Methods inherited from class org.eclipse.collections.impl.map.mutable.AbstractMutableMap
asSynchronized, asUnmodifiable, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectValues, collectWith, flatCollect, flip, groupBy, groupByEach, groupByUniqueKey, partition, partitionWith, reject, reject, rejectWith, select, select, selectInstancesOf, selectWith, tap, withAllKeyValueArguments, withAllKeyValues, withKeyValue, withoutAllKeys, withoutKey, zip, zipWithIndex
Methods inherited from class org.eclipse.collections.impl.map.mutable.AbstractMutableMapIterable
aggregateBy, aggregateInPlaceBy, collect, countBy, countByEach, countByWith, detect, detectOptional, flipUniqueValues, getIfAbsentPut, getIfAbsentPut, getIfAbsentPutWith, getIfAbsentPutWithKey, keysView, keyValuesView, sumByDouble, sumByFloat, sumByInt, sumByLong, updateValue, updateValueWith, 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, noneSatisfy, noneSatisfyWith, toArray, toArray
Methods inherited from class org.eclipse.collections.impl.AbstractRichIterable
appendString, appendString, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, containsAll, containsAllArguments, containsAllIterable, count, countWith, flatCollect, forEach, groupBy, groupByEach, groupByUniqueKey, injectInto, injectInto, injectInto, injectInto, injectInto, into, 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, zip, zipWithIndex
Methods inherited from interface org.eclipse.collections.api.InternalIterable
forEach, forEachWith, forEachWithIndex
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, merge, putIfAbsent, remove, replace, replace, replaceAll
Methods inherited from interface org.eclipse.collections.api.map.MapIterable
detect, detectOptional, forEachKey, forEachValue, getIfAbsent, getIfAbsentValue, getIfAbsentWith, ifPresentApply, keysView, keyValuesView, parallelStream, spliterator, stream, valuesView
Methods inherited from interface org.eclipse.collections.api.map.MutableMap
aggregateBy, aggregateBy, aggregateInPlaceBy, collect, flatCollectWith, flipUniqueValues, withMap
Methods inherited from interface org.eclipse.collections.api.map.MutableMapIterable
add, countBy, countByEach, countByWith, getIfAbsentPut, getIfAbsentPut, getIfAbsentPutWith, getIfAbsentPutWithKey, getOrDefault, putPair, removeAllKeys, removeIf, sumByDouble, sumByFloat, sumByInt, sumByLong, updateValue, updateValueWith
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, containsBy, 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, into, 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, summarizeDouble, summarizeFloat, summarizeInt, summarizeLong, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toArray, toArray, toBag, toBiMap, toList, toMap, toMap, toSet, toSortedBag, toSortedBag, toSortedBagBy, toSortedList, toSortedList, toSortedListBy, toSortedMap, toSortedMap, toSortedMapBy, toSortedSet, toSortedSet, toSortedSetBy, zip, zipWithIndex
-
Method Details
-
adapt
-
toString
Description copied from class:AbstractRichIterable
Returns a string with the elements of the iterable separated by commas with spaces and enclosed in square brackets.Assert.assertEquals("[]", Lists.mutable.empty().toString()); Assert.assertEquals("[1]", Lists.mutable.with(1).toString()); Assert.assertEquals("[1, 2, 3]", Lists.mutable.with(1, 2, 3).toString());
- Specified by:
toString
in interfaceMapIterable<K,V>
- Specified by:
toString
in interfaceRichIterable<K>
- Overrides:
toString
in classAbstractRichIterable<V>
- Returns:
- a string representation of this collection.
- See Also:
AbstractCollection.toString()
-
clone
- Specified by:
clone
in interfaceMutableMap<K,V>
- Specified by:
clone
in classAbstractMutableMap<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>
-
size
public int size()Description copied from interface:RichIterable
Returns the number of items in this iterable. -
isEmpty
public boolean isEmpty()Description copied from interface:RichIterable
Returns true if this iterable has zero items.- Specified by:
isEmpty
in interfaceMap<K,V>
- Specified by:
isEmpty
in interfaceRichIterable<K>
- Overrides:
isEmpty
in classAbstractRichIterable<V>
-
iterator
-
remove
-
keySet
-
values
-
entrySet
-
clear
public void clear() -
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>
-
forEachKeyValue
Description copied from interface:MapIterable
Calls theprocedure
with each key-value pair of the map.final Collection<String> collection = new ArrayList<String>(); MutableMap<Integer, String> map = this.newMapWithKeysValues(1, "One", 2, "Two", 3, "Three"); map.forEachKeyValue((Integer key, String value) -> collection.add(String.valueOf(key) + value)); Verify.assertContainsAll(collection, "1One", "2Two", "3Three");
- Specified by:
forEachKeyValue
in interfaceMapIterable<K,V>
-
get
- Specified by:
get
in interfaceMap<K,V>
- Specified by:
get
in interfaceMapIterable<K,V>
- See Also:
Map.get(Object)
-
put
-
putAll
-
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>
-
removeKey
Description copied from interface:MutableMapIterable
Remove an entry from the map at the specifiedkey
.- Specified by:
removeKey
in interfaceMutableMapIterable<K,V>
- Returns:
- The value removed from entry at key, or null if not found.
- See Also:
Map.remove(Object)
-
containsKey
- Specified by:
containsKey
in interfaceMap<K,V>
- Specified by:
containsKey
in interfaceMapIterable<K,V>
- See Also:
Map.containsKey(Object)
-
containsValue
- Specified by:
containsValue
in interfaceMap<K,V>
- Specified by:
containsValue
in interfaceMapIterable<K,V>
- See Also:
Map.containsValue(Object)
-
equals
Description copied from interface:MapIterable
Follows the same general contract asMap.equals(Object)
. -
hashCode
public int hashCode()Description copied from interface:MapIterable
Follows the same general contract asMap.hashCode()
. -
toImmutable
Description copied from interface:MutableMapIterable
Returns an immutable copy of this map. If the map is immutable, it returns itself.- Specified by:
toImmutable
in interfaceMapIterable<K,V>
- Specified by:
toImmutable
in interfaceMutableMapIterable<K,V>
- Specified by:
toImmutable
in interfaceUnsortedMapIterable<K,V>
- Overrides:
toImmutable
in classAbstractMutableMap<K,V>
-