public interface MapIterable<K,V> extends RichIterable<V>
Modifier and Type | Method and Description |
---|---|
<K2,V2> MapIterable<K2,V2> |
collect(Function2<? super K,? super V,Pair<K2,V2>> function)
For each key and value of the map the function is evaluated.
|
<R> MapIterable<K,R> |
collectValues(Function2<? super K,? super V,? extends R> function)
For each key and value of the map the function is evaluated.
|
boolean |
containsKey(Object key) |
boolean |
containsValue(Object value) |
Pair<K,V> |
detect(Predicate2<? super K,? super V> predicate)
Return the first key and value of the map for which the predicate evaluates to true when they are given
as arguments.
|
boolean |
equals(Object o)
Follows the same general contract as
Map.equals(Object) . |
Multimap<V,K> |
flip()
Given a map from Domain -> Range return a multimap from Range -> Domain.
|
MapIterable<V,K> |
flipUniqueValues()
Return the MapIterable that is obtained by flipping the direction of this map and making the associations
from value to key.
|
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.
|
V |
get(Object key) |
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.
|
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
|
MapIterable<K,V> |
reject(Predicate2<? super K,? super V> predicate)
For each key and value of the map the predicate is evaluated, if the result of the evaluation is false,
that key and value are returned in a new map.
|
MapIterable<K,V> |
select(Predicate2<? super K,? super V> predicate)
For each key and value of the map the predicate is evaluated, if the result of the evaluation is true,
that key and value are returned in a new map.
|
MapIterable<K,V> |
tap(Procedure<? super V> procedure)
Executes the Procedure for each value of the map and returns
this . |
ImmutableMapIterable<K,V> |
toImmutable() |
String |
toString()
Returns a string representation of this MapIterable.
|
RichIterable<V> |
valuesView()
Returns an unmodifiable lazy iterable wrapped around the values for the map
|
aggregateBy, aggregateInPlaceBy, allSatisfy, allSatisfyWith, anySatisfy, anySatisfyWith, appendString, appendString, appendString, asLazy, chunk, collect, collect, collectBoolean, collectBoolean, collectByte, collectByte, collectChar, collectChar, collectDouble, collectDouble, collectFloat, collectFloat, collectIf, collectIf, collectInt, collectInt, collectLong, collectLong, collectShort, collectShort, collectWith, collectWith, contains, containsAll, containsAllArguments, containsAllIterable, count, countWith, detect, detectIfNone, detectWith, detectWithIfNone, each, flatCollect, flatCollect, getFirst, getLast, groupBy, groupBy, groupByEach, groupByEach, groupByUniqueKey, groupByUniqueKey, injectInto, injectInto, injectInto, injectInto, injectInto, isEmpty, makeString, makeString, makeString, max, max, maxBy, min, min, minBy, noneSatisfy, noneSatisfyWith, notEmpty, partition, partitionWith, reject, reject, rejectWith, rejectWith, select, select, selectInstancesOf, selectWith, selectWith, size, 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, zip, zipWithIndex, zipWithIndex
forEach, forEachWith, forEachWithIndex
forEach, iterator, spliterator
V get(Object key)
Map.get(Object)
boolean containsKey(Object key)
Map.containsKey(Object)
boolean containsValue(Object value)
Map.containsValue(Object)
void forEachValue(Procedure<? super V> procedure)
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);
MapIterable<K,V> tap(Procedure<? super V> procedure)
this
.
e.g. return peopleByCity.tap(new Procedure() { public void value(Person person) { LOGGER.info(person.getName()); } });
tap
in interface RichIterable<V>
InternalIterable.forEach(Procedure)
void forEachKey(Procedure<? super K> procedure)
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);
void forEachKeyValue(Procedure2<? super K,? super V> procedure)
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");
MapIterable<V,K> flipUniqueValues()
MapIterablemap = this.newMapWithKeysValues(1, "1", 2, "2", 3, "3"); MapIterable result = map.flipUniqueValues(); Assert.assertTrue(result.equals(UnifiedMap.newWithKeysValues("1", 1, "2", 2, "3", 3)));
IllegalStateException
- if the MapIterable contains duplicate values.V getIfAbsent(K key, Function0<? extends V> function)
V getIfAbsentValue(K key, V value)
value
.<P> V getIfAbsentWith(K key, Function<? super P,? extends V> function, P parameter)
<A> A ifPresentApply(K key, Function<? super V,? extends A> function)
RichIterable<K> keysView()
RichIterable<V> valuesView()
RichIterable<Pair<K,V>> keyValuesView()
Multimap<V,K> flip()
Since the keys in the input are unique, the values in the output are unique, so the return type should be a SetMultimap. However since SetMultimap and SortedSetMultimap don't inherit from one another, SetMultimap here does not allow SortedMapIterable to have a SortedSetMultimap return. Thus we compromise and call this Multimap, even though all implementations will be a SetMultimap or SortedSetMultimap.
MapIterable<K,V> select(Predicate2<? super K,? super V> predicate)
e.g. peopleByCity.select(new Predicate2<City, Person>() { public boolean accept(City city, Person person) { return city.getName().equals("Anytown") && person.getLastName().equals("Smith"); } });
MapIterable<K,V> reject(Predicate2<? super K,? super V> predicate)
e.g. peopleByCity.reject(new Predicate2<City, Person>() { public boolean accept(City city, Person person) { return city.getName().equals("Anytown") && person.getLastName().equals("Smith"); } });
<K2,V2> MapIterable<K2,V2> collect(Function2<? super K,? super V,Pair<K2,V2>> function)
e.g. peopleByCity.collect(new Function2<City, Person, String>() { public String value(City city, Person person) { return Pair.of(city.getCountry(), person.getAddress().getCity()); } });
<R> MapIterable<K,R> collectValues(Function2<? super K,? super V,? extends R> function)
e.g. peopleByCity.collectValues(new Function2<City, Person, String>() { public String value(City city, Person person) { return person.getFirstName() + " " + person.getLastName(); } });
Pair<K,V> detect(Predicate2<? super K,? super V> predicate)
e.g. peopleByCity.detect(new Predicate2<City, Person>() { public boolean accept(City city, Person person) { return city.getName().equals("Anytown") && person.getLastName().equals("Smith"); } });
boolean equals(Object o)
Map.equals(Object)
.int hashCode()
Map.hashCode()
.String toString()
String.valueOf(Object)
.toString
in interface RichIterable<V>
toString
in class Object
ImmutableMapIterable<K,V> toImmutable()
Copyright © 2004–2016. All rights reserved.