public class MapAdapter<K,V> extends AbstractMutableMap<K,V> implements Serializable
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()
Returns a string representation of this map.
|
<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
collection 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 MapIterable.
|
Collection<V> |
values() |
add, aggregateBy, aggregateInPlaceBy, asSynchronized, asUnmodifiable, collect, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectValues, collectWith, detect, flatCollect, flip, flipUniqueValues, getIfAbsentPut, getIfAbsentPut, getIfAbsentPutWith, getIfAbsentPutWithKey, groupBy, groupByEach, groupByUniqueKey, keysView, keyValuesView, partition, partitionWith, reject, reject, select, select, selectInstancesOf, selectWith, updateValue, updateValueWith, valuesView, withAllKeyValueArguments, withAllKeyValues, withKeyValue, withoutAllKeys, withoutKey, zip, zipWithIndexallSatisfy, 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, flatCollect, forEach, forEachKey, forEachValue, forEachWith, forEachWithIndex, getFirst, getIfAbsent, getIfAbsentValue, getIfAbsentWith, getLast, groupBy, groupByEach, ifPresentApply, injectInto, injectInto, injectInto, injectInto, injectInto, makeString, makeString, makeString, max, max, maxBy, min, min, minBy, noneSatisfy, noneSatisfyWith, notEmpty, reject, rejectWith, rejectWith, select, selectWith, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toArray, toArray, toBag, toList, toMap, toSet, toSortedList, toSortedList, toSortedListBy, toSortedMap, toSortedMap, toSortedSet, toSortedSet, toSortedSetBy, zip, zipWithIndexforEachKey, forEachValue, getIfAbsent, getIfAbsentValue, getIfAbsentWith, ifPresentApplyallSatisfy, 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, flatCollect, getFirst, getLast, groupBy, groupByEach, injectInto, injectInto, injectInto, injectInto, injectInto, makeString, makeString, makeString, max, max, maxBy, min, min, minBy, noneSatisfy, noneSatisfyWith, notEmpty, reject, rejectWith, rejectWith, select, selectWith, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toArray, toArray, toBag, toList, toMap, toSet, toSortedList, toSortedList, toSortedListBy, toSortedMap, toSortedMap, toSortedSet, toSortedSet, toSortedSetBy, zip, zipWithIndexforEach, forEachWith, forEachWithIndexforEach, spliteratorcompute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAllpublic static <K,V> MutableMap<K,V> adapt(Map<K,V> map)
public String toString()
MapIterableString.valueOf(Object).toString in interface MapIterable<K,V>toString in interface RichIterable<V>toString in class Objectpublic MutableMap<K,V> clone()
AbstractMutableMapThis implementation creates an empty string buffer, appends a left brace, and iterates over the map's entrySet view, appending the string representation of each map.entry in turn. After appending each entry except the last, the string ", " is appended. Finally a right brace is appended. A string is obtained from the stringbuffer, and returned.
clone in interface MutableMap<K,V>clone in class AbstractMutableMap<K,V>public <K,V> MutableMap<K,V> newEmpty(int capacity)
AbstractMutableMapnewEmpty in class AbstractMutableMap<K,V>public int size()
RichIterablepublic boolean isEmpty()
RichIterablepublic MutableMap<K,V> newEmpty()
MutableMapnewEmpty in interface MutableMap<K,V>public void forEachKeyValue(Procedure2<? super K,? super V> procedure)
MapIterableprocedure 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 MapIterable<K,V>get in interface Map<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)
MutableMapcollection 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 it's value replaced by that in map.collectKeysAndValues in interface MutableMap<K,V>public V removeKey(K key)
MutableMapkey.removeKey in interface MutableMap<K,V>Map.remove(Object)public boolean containsKey(Object key)
containsKey in interface MapIterable<K,V>containsKey in interface Map<K,V>Map.containsKey(Object)public boolean containsValue(Object value)
containsValue in interface MapIterable<K,V>containsValue in interface Map<K,V>Map.containsValue(Object)public boolean equals(Object o)
MapIterableMap.equals(Object).public int hashCode()
MapIterableMap.hashCode().public ImmutableMap<K,V> toImmutable()
MutableMaptoImmutable in interface MutableMap<K,V>toImmutable in interface UnsortedMapIterable<K,V>toImmutable in class AbstractMutableMap<K,V>Copyright © 2004–2017. All rights reserved.