@Immutable public class ImmutableUnifiedMap<K,V> extends AbstractImmutableMap<K,V> implements BatchIterable<V>, Serializable
Constructor and Description |
---|
ImmutableUnifiedMap(Map<K,V> delegate) |
ImmutableUnifiedMap(Pair<K,V>... pairs) |
Modifier and Type | Method and Description |
---|---|
void |
batchForEach(Procedure<? super V> procedure,
int sectionIndex,
int sectionCount) |
boolean |
containsKey(Object key) |
boolean |
containsValue(Object value) |
boolean |
equals(Object o)
Follows the same general contract as
Map.equals(Object) . |
void |
forEachKey(Procedure<? super K> procedure)
Calls the
procedure with each key of the map. |
void |
forEachKeyValue(Procedure2<? super K,? super V> procedure)
Calls the
procedure with each key-value pair of the map. |
void |
forEachValue(Procedure<? super V> procedure)
Calls the procedure with each value of the map.
|
<P> void |
forEachWith(Procedure2<? super V,? super P> procedure,
P parameter)
The procedure2 is evaluated for each element in the iterable with the specified parameter provided
as the second argument.
|
void |
forEachWithIndex(ObjectIntProcedure<? super V> objectIntProcedure)
Iterates over the iterable passing each element and the current relative int index to the specified instance of
ObjectIntProcedure.
|
V |
get(Object key) |
int |
getBatchCount(int batchSize) |
V |
getIfAbsent(K key,
Function0<? extends V> function)
Return the value in the Map that corresponds to the specified key, or if there is no value at the key, return the
result of evaluating the specified Function0.
|
V |
getIfAbsentValue(K key,
V value)
Return the value in the Map that corresponds to the specified key, or if there is no value at the key, return
value . |
<P> V |
getIfAbsentWith(K key,
Function<? super P,? extends V> function,
P parameter)
Return the value in the Map that corresponds to the specified key, or if there is no value at the key, return the
result of evaluating the specified function and parameter.
|
int |
hashCode()
Follows the same general contract as
Map.hashCode() . |
<A> A |
ifPresentApply(K key,
Function<? super V,? extends A> function)
If there is a value in the Map that corresponds to the specified key return the result of applying the specified
Function on the value, otherwise return null.
|
Set<K> |
keySet() |
RichIterable<K> |
keysView()
Returns an unmodifiable lazy iterable wrapped around the keySet for the map
|
RichIterable<Pair<K,V>> |
keyValuesView()
Returns an unmodifiable lazy iterable of key/value pairs wrapped around the entrySet for the map
|
int |
size()
Returns the number of items in this iterable.
|
String |
toString()
Returns a string representation of this collection.
|
Collection<V> |
values() |
RichIterable<V> |
valuesView()
Returns an unmodifiable lazy iterable wrapped around the values for the map
|
aggregateBy, aggregateInPlaceBy, castToMap, clear, collect, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectValues, collectWith, detect, entrySet, flatCollect, flip, flipUniqueValues, groupBy, groupByEach, groupByUniqueKey, iterator, newWithAllKeyValueArguments, newWithAllKeyValues, newWithKeyValue, newWithoutAllKeys, newWithoutKey, partition, partitionWith, put, putAll, reject, reject, rejectWith, remove, select, select, selectInstancesOf, selectWith, tap, toImmutable, toMap, zip, zipWithIndex
allSatisfy, allSatisfyWith, anySatisfy, anySatisfyWith, asLazy, chunk, contains, detect, detectIfNone, detectWith, detectWithIfNone, each, getFirst, getLast, 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, isEmpty, 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
forEach
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, isEmpty, 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
forEach, spliterator
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, isEmpty, merge, putIfAbsent, remove, replace, replace, replaceAll
public boolean equals(Object o)
MapIterable
Map.equals(Object)
.public int hashCode()
MapIterable
Map.hashCode()
.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 int size()
RichIterable
size
in interface Map<K,V>
size
in interface RichIterable<V>
size
in interface BatchIterable<V>
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 V get(Object key)
get
in interface Map<K,V>
get
in interface MapIterable<K,V>
Map.get(Object)
public int getBatchCount(int batchSize)
getBatchCount
in interface BatchIterable<V>
public void batchForEach(Procedure<? super V> procedure, int sectionIndex, int sectionCount)
batchForEach
in interface BatchIterable<V>
public void forEachValue(Procedure<? super V> procedure)
MapIterable
Set<String> result = UnifiedSet.newSet(); MutableMap<Integer, String> map = this.newMapWithKeysValues(1, "One", 2, "Two", 3, "Three", 4, "Four"); map.forEachValue(new CollectionAddProcedure<String>(result)); Verify.assertSetsEqual(UnifiedSet.newSetWith("One", "Two", "Three", "Four"), result);
forEachValue
in interface MapIterable<K,V>
forEachValue
in class AbstractMapIterable<K,V>
public void forEachKey(Procedure<? super K> procedure)
MapIterable
procedure
with each key of the map.
final Collection<Integer> result = new ArrayList<Integer>(); MutableMap<Integer, String> map = this.newMapWithKeysValues(1, "1", 2, "2", 3, "3"); map.forEachKey(new CollectionAddProcedure<Integer>(result)); Verify.assertContainsAll(result, 1, 2, 3);
forEachKey
in interface MapIterable<K,V>
forEachKey
in class AbstractMapIterable<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 RichIterable<K> keysView()
MapIterable
keysView
in interface MapIterable<K,V>
public RichIterable<V> valuesView()
MapIterable
valuesView
in interface MapIterable<K,V>
public RichIterable<Pair<K,V>> keyValuesView()
MapIterable
keyValuesView
in interface MapIterable<K,V>
public void forEachWithIndex(ObjectIntProcedure<? super V> objectIntProcedure)
InternalIterable
Example using a Java 8 lambda:
people.forEachWithIndex((Person person, int index) -> LOGGER.info("Index: " + index + " person: " + person.getName()));
Example using an anonymous inner class:
people.forEachWithIndex(new ObjectIntProcedure() { public void value(Person person, int index) { LOGGER.info("Index: " + index + " person: " + person.getName()); } });
forEachWithIndex
in interface InternalIterable<V>
forEachWithIndex
in class AbstractMapIterable<K,V>
public <P> void forEachWith(Procedure2<? super V,? super P> procedure, P parameter)
InternalIterable
Example using a Java 8 lambda:
people.forEachWith((Person person, Person other) -> { if (person.isRelatedTo(other)) { LOGGER.info(person.getName()); } }, fred);
Example using an anonymous inner class:
people.forEachWith(new Procedure2() { public void value(Person person, Person other) { if (person.isRelatedTo(other)) { LOGGER.info(person.getName()); } } }, fred);
forEachWith
in interface InternalIterable<V>
forEachWith
in class AbstractMapIterable<K,V>
public <A> A ifPresentApply(K key, Function<? super V,? extends A> function)
MapIterable
ifPresentApply
in interface MapIterable<K,V>
ifPresentApply
in class AbstractMapIterable<K,V>
public V getIfAbsent(K key, Function0<? extends V> function)
MapIterable
getIfAbsent
in interface MapIterable<K,V>
getIfAbsent
in class AbstractMapIterable<K,V>
public V getIfAbsentValue(K key, V value)
MapIterable
value
.getIfAbsentValue
in interface MapIterable<K,V>
getIfAbsentValue
in class AbstractMapIterable<K,V>
public <P> V getIfAbsentWith(K key, Function<? super P,? extends V> function, P parameter)
MapIterable
getIfAbsentWith
in interface MapIterable<K,V>
getIfAbsentWith
in class AbstractMapIterable<K,V>
Copyright © 2004–2016. All rights reserved.