Top Description Fields Constructors Methods
org.eclipse.collections.impl.map.mutable

public Class MapAdapter<K, V>

extends AbstractMutableMap<K, V>
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Imports
java.io.Serializable, java.util.Collection, .Iterator, .Map, .Set, java.util.function.BiFunction, org.eclipse.collections.api.block.function.Function, org.eclipse.collections.api.block.procedure.Procedure2, org.eclipse.collections.api.factory.Maps, org.eclipse.collections.api.map.ImmutableMap, .MutableMap, org.eclipse.collections.impl.utility.Iterate, .MapIterate

This class provides a MutableMap wrapper around a JDK Collections Map interface instance. All 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.

Field Summary

Modifier and TypeField and Description
protected final Map<K, V>
private static final long

Constructor Summary

AccessConstructor and Description
protected
MapAdapter(Map<K, V> newDelegate)

Method Summary

Modifier and TypeMethod and Description
public static <K, V> MutableMap<K, V>
adapt(Map<K, V> map)

public void
clear()

Implements java.util.Map.clear.

Removes all of the mappings from this map (optional operation).

public MutableMap<K, V>
clone()

Implements abstract org.eclipse.collections.impl.map.mutable.AbstractMutableMap.clone.

Implements org.eclipse.collections.api.map.MutableMap.clone.

Creates and returns a copy of this object.

public <E> MutableMap<K, V>
collectKeysAndValues(Iterable<E> iterable, Function<? super E, ? extends K> keyFunction, Function<? super E, ? extends V> valueFunction)

Implements org.eclipse.collections.api.map.MutableMap.collectKeysAndValues.

Adds all the entries derived from iterable to this.

public boolean
containsKey(Object key)

Implements org.eclipse.collections.api.map.MapIterable.containsKey, java.util.Map.containsKey.

Returns true if this map contains a mapping for the specified key.

public boolean
containsValue(Object value)

Implements org.eclipse.collections.api.map.MapIterable.containsValue, java.util.Map.containsValue.

Returns true if this map maps one or more keys to the specified value.

public Set<Map.Entry<K, V>>
entrySet()

Implements java.util.Map.entrySet.

Returns a Set view of the mappings contained in this map.

public boolean
public void
forEachKeyValue(Procedure2<? super K, ? super V> procedure)

Implements org.eclipse.collections.api.map.MapIterable.forEachKeyValue.

Calls the procedure with each key-value pair of the map.

public V
get(Object key)

Implements org.eclipse.collections.api.map.MapIterable.get, java.util.Map.get.

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

public int
public boolean
public Iterator<V>
public Set<K>
keySet()

Implements java.util.Map.keySet.

Returns a Set view of the keys contained in this map.

public V
merge(K key, V value, BiFunction<? super V, ? super V, ? extends V> remappingFunction)

Overrides default java.util.Map.merge.

If the specified key is not already associated with a value or is associated with null, associates it with the given non-null value (optional operation).

public <K, V> MutableMap<K, V>
newEmpty(int capacity)

Implements abstract org.eclipse.collections.impl.map.mutable.AbstractMutableMap.newEmpty.

Creates a new instance of the same type, using the given capacity and the default growth parameters.

public MutableMap<K, V>
newEmpty()

Implements org.eclipse.collections.api.map.MutableMap.newEmpty, org.eclipse.collections.api.map.MutableMapIterable.newEmpty.

Creates a new instance of the same type, using the default capacity and growth parameters.

public V
put(K key, V value)

Implements java.util.Map.put.

Associates the specified value with the specified key in this map (optional operation).

public void
putAll(Map<? extends K, ? extends V> map)

Implements java.util.Map.putAll.

Copies all of the mappings from the specified map to this map (optional operation).

public V
remove(Object key)

Implements java.util.Map.remove.

Removes the mapping for a key from this map if it is present (optional operation).

public V
removeKey(K key)

Implements org.eclipse.collections.api.map.MutableMapIterable.removeKey.

Remove an entry from the map at the specified key.

public int
size()

Implements org.eclipse.collections.api.RichIterable.size, java.util.Map.size.

Returns the number of key-value mappings in this map.

public ImmutableMap<K, V>
public String
toString()

Overrides org.eclipse.collections.impl.AbstractRichIterable.toString.

Implements org.eclipse.collections.api.map.MapIterable.toString, org.eclipse.collections.api.RichIterable.toString.

Returns a string with the keys and values of this map separated by commas with spaces and enclosed in curly braces.

public Collection<V>
values()

Implements java.util.Map.values.

Returns a Collection view of the values contained in this map.

Inherited from org.eclipse.collections.impl.map.mutable.AbstractMutableMap:
asSynchronizedasUnmodifiablecollectcollectBooleancollectBytecollectCharcollectDoublecollectFloatcollectIfcollectIntcollectKeysUniquecollectLongcollectShortcollectValuescollectWithflatCollectflipgroupBygroupByEachgroupByUniqueKeypartitionpartitionWithrejectrejectrejectWithreplaceAllselectselectselectInstancesOfselectWithtapwithAllKeyValueArgumentswithAllKeyValueswithKeyValuewithoutAllKeyswithoutKeyzipzipWithIndex

Field Detail

delegateback to summary
protected final Map<K, V> delegate
serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

MapAdapterback to summary
protected MapAdapter(Map<K, V> newDelegate)

Method Detail

adaptback to summary
public static <K, V> MutableMap<K, V> adapt(Map<K, V> map)
clearback to summary
public void clear()

Implements java.util.Map.clear.

Doc from java.util.Map.clear.

Removes all of the mappings from this map (optional operation). The map will be empty after this call returns.

Annotations
@Override
cloneback to summary
public MutableMap<K, V> clone()

Implements abstract org.eclipse.collections.impl.map.mutable.AbstractMutableMap.clone.

Implements org.eclipse.collections.api.map.MutableMap.clone.

Doc from java.lang.Object.clone.

Creates and returns a copy of this object. The precise meaning of "copy" may depend on the class of the object. The general intent is that, for any object x, the expression:

x.clone() != x
will be true, and that the expression:
x.clone().getClass() == x.getClass()
will be true, but these are not absolute requirements. While it is typically the case that:
x.clone().equals(x)
will be true, this is not an absolute requirement.

By convention, the returned object should be obtained by calling super.clone. If a class and all of its superclasses (except Object) obey this convention, it will be the case that x.clone().getClass() == x.getClass().

By convention, the object returned by this method should be independent of this object (which is being cloned). To achieve this independence, it may be necessary to modify one or more fields of the object returned by super.clone before returning it. Typically, this means copying any mutable objects that comprise the internal "deep structure" of the object being cloned and replacing the references to these objects with references to the copies. If a class contains only primitive fields or references to immutable objects, then it is usually the case that no fields in the object returned by super.clone need to be modified.

Annotations
@Override
collectKeysAndValuesback to summary
public <E> MutableMap<K, V> collectKeysAndValues(Iterable<E> iterable, Function<? super E, ? extends K> keyFunction, Function<? super E, ? extends V> valueFunction)

Implements org.eclipse.collections.api.map.MutableMap.collectKeysAndValues.

Doc from org.eclipse.collections.api.map.MutableMap.collectKeysAndValues.

Adds all the entries derived from iterable to this. The key and value for each entry is determined by applying the keyFunction and valueFunction to each item in collection. Any entry in map that has the same key as an entry in this will have its value replaced by that in map.

Annotations
@Override
containsKeyback to summary
public boolean containsKey(Object key)

Implements org.eclipse.collections.api.map.MapIterable.containsKey, java.util.Map.containsKey.

Doc from java.util.Map.containsKey.

Returns true if this map contains a mapping for the specified key. More formally, returns true if and only if this map contains a mapping for a key k such that Objects.equals(key, k). (There can be at most one such mapping.)

Annotations
@Override
containsValueback to summary
public boolean containsValue(Object value)

Implements org.eclipse.collections.api.map.MapIterable.containsValue, java.util.Map.containsValue.

Doc from java.util.Map.containsValue.

Returns true if this map maps one or more keys to the specified value. More formally, returns true if and only if this map contains at least one mapping to a value v such that Objects.equals(value, v). This operation will probably require time linear in the map size for most implementations of the Map interface.

Annotations
@Override
entrySetback to summary
public Set<Map.Entry<K, V>> entrySet()

Implements java.util.Map.entrySet.

Doc from java.util.Map.entrySet.

Returns a Set view 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 the map is modified while an iteration over the set is in progress (except through the iterator's own remove operation, or through the setValue operation on a map entry returned by the iterator) the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.

Annotations
@Override
equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Implements org.eclipse.collections.api.map.MapIterable.equals, java.util.Map.equals.

Doc from org.eclipse.collections.api.map.MapIterable.equals.

Follows the same general contract as Map#equals(Object).

Annotations
@Override
forEachKeyValueback to summary
public void forEachKeyValue(Procedure2<? super K, ? super V> procedure)

Implements org.eclipse.collections.api.map.MapIterable.forEachKeyValue.

Doc from org.eclipse.collections.api.map.MapIterable.forEachKeyValue.

Calls the procedure 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");
Annotations
@Override
getback to summary
public V get(Object key)

Implements org.eclipse.collections.api.map.MapIterable.get, java.util.Map.get.

Doc from java.util.Map.get.

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

More formally, if this map contains a mapping from a key k to a value v such that Objects.equals(key, k), then this method returns v; otherwise it returns null. (There can be at most one such mapping.)

If this map permits null values, then a return value of null does not necessarily indicate that the map contains no mapping for the key; it's also possible that the map explicitly maps the key to null. The containsKey operation may be used to distinguish these two cases.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Implements org.eclipse.collections.api.map.MapIterable.hashCode, java.util.Map.hashCode.

Doc from org.eclipse.collections.api.map.MapIterable.hashCode.

Follows the same general contract as Map#hashCode().

Annotations
@Override
isEmptyback to summary
public boolean isEmpty()

Overrides org.eclipse.collections.impl.AbstractRichIterable.isEmpty.

Implements org.eclipse.collections.api.RichIterable.isEmpty, java.util.Map.isEmpty.

Doc from java.util.Map.isEmpty.

Returns true if this map contains no key-value mappings.

Annotations
@Override
iteratorback to summary
public Iterator<V> iterator()

Overrides org.eclipse.collections.impl.map.mutable.AbstractMutableMapIterable.iterator.

Implements java.lang.Iterable.iterator.

Doc from java.lang.Iterable.iterator.

Returns an iterator over elements of type T.

Annotations
@Override
keySetback to summary
public Set<K> keySet()

Implements java.util.Map.keySet.

Doc from java.util.Map.keySet.

Returns a Set view 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 the map is modified while an iteration over the set is in progress (except through the iterator's own remove operation), the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll, and clear operations. It does not support the add or addAll operations.

Annotations
@Override
mergeback to summary
public V merge(K key, V value, BiFunction<? super V, ? super V, ? extends V> remappingFunction)

Overrides default java.util.Map.merge.

Doc from java.util.Map.merge.

If the specified key is not already associated with a value or is associated with null, associates it with the given non-null value (optional operation). Otherwise, replaces the associated value with the results of the given remapping function, or removes if the result is null. This method may be of use when combining multiple mapped values for a key. For example, to either create or append a String msg to a value mapping:

 map.merge(key, msg, String::concat)

If the remapping function returns null, the mapping is removed. If the remapping function itself throws an (unchecked) exception, the exception is rethrown, and the current mapping is left unchanged.

The remapping function should not modify this map during computation.

Annotations
@Override
newEmptyback to summary
public <K, V> MutableMap<K, V> newEmpty(int capacity)

Implements abstract org.eclipse.collections.impl.map.mutable.AbstractMutableMap.newEmpty.

Doc from org.eclipse.collections.impl.map.mutable.AbstractMutableMap.newEmpty.

Creates a new instance of the same type, using the given capacity and the default growth parameters.

Annotations
@Override
newEmptyback to summary
public MutableMap<K, V> newEmpty()

Implements org.eclipse.collections.api.map.MutableMap.newEmpty, org.eclipse.collections.api.map.MutableMapIterable.newEmpty.

Doc from org.eclipse.collections.api.map.MutableMapIterable.newEmpty.

Creates a new instance of the same type, using the default capacity and growth parameters.

Annotations
@Override
putback to summary
public V put(K key, V value)

Implements java.util.Map.put.

Doc from java.util.Map.put.

Associates the specified value with the specified key in this map (optional operation). If the map previously contained a mapping for the key, the old value is replaced by the specified value. (A map m is said to contain a mapping for a key k if and only if m.containsKey(k) would return true.)

Annotations
@Override
putAllback to summary
public void putAll(Map<? extends K, ? extends V> map)

Implements java.util.Map.putAll.

Doc from java.util.Map.putAll.

Copies all of the mappings from the specified map to this map (optional operation). The effect of this call is equivalent to that of calling put(k, v) on this map once for each mapping from key k to value v in the specified map. The behavior of this operation is undefined if the specified map is modified while the operation is in progress. If the specified map has a defined encounter order, processing of its mappings generally occurs in that order.

Annotations
@Override
removeback to summary
public V remove(Object key)

Implements java.util.Map.remove.

Doc from java.util.Map.remove.

Removes the mapping for a key from this map if it is present (optional operation). More formally, if this map contains a mapping from key k to value v such that Objects.equals(key, k), 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 null if the map contained no mapping for the key.

If this map permits null values, then a return value of null does not necessarily indicate that the map contained no mapping for the key; it's also possible that the map explicitly mapped the key to null.

The map will not contain a mapping for the specified key once the call returns.

Annotations
@Override
removeKeyback to summary
public V removeKey(K key)

Implements org.eclipse.collections.api.map.MutableMapIterable.removeKey.

Doc from org.eclipse.collections.api.map.MutableMapIterable.removeKey.

Remove an entry from the map at the specified key.

Annotations
@Override
sizeback to summary
public int size()

Implements org.eclipse.collections.api.RichIterable.size, java.util.Map.size.

Doc from java.util.Map.size.

Returns the number of key-value mappings in this map. If the map contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Annotations
@Override
toImmutableback to summary
public ImmutableMap<K, V> toImmutable()

Overrides org.eclipse.collections.impl.map.mutable.AbstractMutableMap.toImmutable.

Implements org.eclipse.collections.api.map.MutableMapIterable.toImmutable, org.eclipse.collections.api.map.UnsortedMapIterable.toImmutable, org.eclipse.collections.api.map.MapIterable.toImmutable.

Doc from org.eclipse.collections.api.map.MutableMapIterable.toImmutable.

Returns an immutable copy of this map. If the map is immutable, it returns itself.

Annotations
@Override
toStringback to summary
public String toString()

Overrides org.eclipse.collections.impl.AbstractRichIterable.toString.

Implements org.eclipse.collections.api.map.MapIterable.toString, org.eclipse.collections.api.RichIterable.toString.

Doc from org.eclipse.collections.api.map.MapIterable.toString.

Returns a string with the keys and values of this map separated by commas with spaces and enclosed in curly braces. Each key and value is separated by an equals sign.

Assert.assertEquals("{1=1, 2=2, 3=3}", Maps.mutable.with(1, 1, 2, 2, 3, 3).toString());
Annotations
@Override
valuesback to summary
public Collection<V> values()

Implements java.util.Map.values.

Doc from java.util.Map.values.

Returns a Collection view 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 the map is modified while an iteration over the collection is in progress (except through the iterator's own remove operation), the results of the iteration are undefined. The collection supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Collection.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.

Annotations
@Override