public class MapAdapter<K,V> extends AbstractMutableMap<K,V> implements Serializable
To create a new wrapper around an existing Map instance, use the adapt(Map)
factory method.
Modifier and Type | Method and 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 from
iterable to this . |
boolean |
containsKey(Object key) |
boolean |
containsValue(Object value) |
Set<Map.Entry<K,V>> |
entrySet() |
boolean |
equals(Object o)
Follows the same general contract as
Map.equals(Object) . |
void |
forEachKeyValue(Procedure2<? super K,? super V> procedure)
Calls the
procedure with each key-value pair of the map. |
V |
get(Object key) |
int |
hashCode()
Follows the same general contract as
Map.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 specified
key . |
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 representation of this collection.
|
Collection<V> |
values() |
asSynchronized, asUnmodifiable, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectValues, collectWith, flatCollect, flip, groupBy, groupByEach, partition, partitionWith, reject, reject, rejectWith, select, select, selectInstancesOf, selectWith, tap, withAllKeyValueArguments, withAllKeyValues, withKeyValue, withoutAllKeys, withoutKey, zip, zipWithIndex
add, aggregateBy, aggregateInPlaceBy, collect, detect, flipUniqueValues, getIfAbsentPut, getIfAbsentPut, getIfAbsentPutWith, getIfAbsentPutWithKey, groupByUniqueKey, keysView, keyValuesView, updateValue, updateValueWith, valuesView
allSatisfy, allSatisfyWith, anySatisfy, anySatisfyWith, asLazy, chunk, contains, detect, detectIfNone, detectWith, detectWithIfNone, each, forEachKey, forEachValue, forEachWith, forEachWithIndex, getFirst, getIfAbsent, getIfAbsentValue, getIfAbsentWith, getLast, ifPresentApply, noneSatisfy, noneSatisfyWith, toArray, toArray
appendString, 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, makeString, makeString, makeString, max, max, maxBy, min, min, minBy, notEmpty, reject, rejectWith, select, selectWith, sumByDouble, sumByFloat, sumByInt, sumByLong, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toBag, toList, toMap, toSet, toSortedBag, toSortedBag, toSortedBagBy, toSortedList, toSortedList, toSortedListBy, toSortedMap, toSortedMap, toSortedSet, toSortedSet, toSortedSetBy, zip, zipWithIndex
aggregateBy, aggregateInPlaceBy, collect, flipUniqueValues, groupByUniqueKey
add, getIfAbsentPut, getIfAbsentPut, getIfAbsentPutWith, getIfAbsentPutWithKey, updateValue, updateValueWith
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
detect, forEachKey, forEachValue, getIfAbsent, getIfAbsentValue, getIfAbsentWith, ifPresentApply, keysView, keyValuesView, valuesView
allSatisfy, allSatisfyWith, anySatisfy, anySatisfyWith, appendString, appendString, appendString, asLazy, chunk, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, contains, containsAll, containsAllArguments, containsAllIterable, count, countWith, detect, detectIfNone, detectWith, detectWithIfNone, each, flatCollect, getFirst, getLast, groupBy, groupByEach, groupByUniqueKey, injectInto, injectInto, injectInto, injectInto, injectInto, makeString, makeString, makeString, max, max, maxBy, min, min, minBy, noneSatisfy, noneSatisfyWith, notEmpty, reject, rejectWith, select, selectWith, sumByDouble, sumByFloat, sumByInt, sumByLong, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toArray, toArray, toBag, toList, toMap, toSet, toSortedBag, toSortedBag, toSortedBagBy, toSortedList, toSortedList, toSortedListBy, toSortedMap, toSortedMap, toSortedSet, toSortedSet, toSortedSetBy, zip, zipWithIndex
forEach, forEachWith, forEachWithIndex
forEach, spliterator
public static <K,V> MutableMap<K,V> adapt(Map<K,V> map)
public String toString()
AbstractRichIterable
This implementation creates an empty string buffer, appends a left square bracket, and iterates over the collection appending the string representation of each element in turn. After appending each element except the last, the string ", " is appended. Finally a right bracket is appended. A string is obtained from the string buffer, and returned.
toString
in interface MapIterable<K,V>
toString
in interface RichIterable<V>
toString
in class AbstractRichIterable<V>
public MutableMap<K,V> clone()
clone
in interface MutableMap<K,V>
clone
in class AbstractMutableMap<K,V>
public <K,V> MutableMap<K,V> newEmpty(int capacity)
AbstractMutableMap
newEmpty
in class AbstractMutableMap<K,V>
public int size()
RichIterable
public boolean isEmpty()
RichIterable
isEmpty
in interface Map<K,V>
isEmpty
in interface RichIterable<V>
isEmpty
in class AbstractRichIterable<V>
public MutableMap<K,V> newEmpty()
MutableMapIterable
newEmpty
in interface MutableMap<K,V>
newEmpty
in interface MutableMapIterable<K,V>
public void forEachKeyValue(Procedure2<? super K,? super V> procedure)
MapIterable
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(new Procedure2<Integer, String>() { public void value(final Integer key, final String value) { collection.add(String.valueOf(key) + value); } }); Verify.assertContainsAll(collection, "1One", "2Two", "3Three");
forEachKeyValue
in interface MapIterable<K,V>
public V get(Object key)
get
in interface Map<K,V>
get
in interface MapIterable<K,V>
Map.get(Object)
public <E> MutableMap<K,V> collectKeysAndValues(Iterable<E> iterable, Function<? super E,? extends K> keyFunction, Function<? super E,? extends V> valueFunction)
MutableMap
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
.collectKeysAndValues
in interface MutableMap<K,V>
public V removeKey(K key)
MutableMapIterable
key
.removeKey
in interface MutableMapIterable<K,V>
Map.remove(Object)
public boolean containsKey(Object key)
containsKey
in interface Map<K,V>
containsKey
in interface MapIterable<K,V>
Map.containsKey(Object)
public boolean containsValue(Object value)
containsValue
in interface Map<K,V>
containsValue
in interface MapIterable<K,V>
Map.containsValue(Object)
public boolean equals(Object o)
MapIterable
Map.equals(Object)
.public int hashCode()
MapIterable
Map.hashCode()
.public ImmutableMap<K,V> toImmutable()
MutableMapIterable
toImmutable
in interface MapIterable<K,V>
toImmutable
in interface MutableMapIterable<K,V>
toImmutable
in interface UnsortedMapIterable<K,V>
toImmutable
in class AbstractMutableMap<K,V>
Copyright © 2004–2016. All rights reserved.