BiMap<K,V>
, ImmutableMapIterable<K,V>
, InternalIterable<K>
, Iterable<K>
, MapIterable<K,V>
, RichIterable<K>
AbstractImmutableBiMap
public interface ImmutableBiMap<K,V> extends BiMap<K,V>, ImmutableMapIterable<K,V>
BiMap
whose contents cannot be altered after initialization.Modifier and Type | Method | Description |
---|---|---|
<V1> ImmutableBagIterable<V1> |
collect(Function<? super V,? extends V1> function) |
Returns a new collection with the results of applying the specified function on each element of the source
collection.
|
<K2,V2> ImmutableBiMap<K2,V2> |
collect(Function2<? super K,? super V,Pair<K2,V2>> function) |
For each key and value of the map the function is evaluated.
|
<V1> ImmutableBagIterable<V1> |
collectIf(Predicate<? super V> predicate,
Function<? super V,? extends V1> function) |
Returns a new collection with the results of applying the specified function on each element of the source
collection, but only for those elements which return true upon evaluation of the predicate.
|
<R> ImmutableBiMap<K,R> |
collectValues(Function2<? super K,? super V,? extends R> function) |
For each key and value of the map the function is evaluated.
|
<P,V1> ImmutableBagIterable<V1> |
collectWith(Function2<? super V,? super P,? extends V1> function,
P parameter) |
Same as
RichIterable.collect(Function) with a Function2 and specified parameter which is passed to the block. |
<V1> ImmutableBagIterable<V1> |
flatCollect(Function<? super V,? extends Iterable<V1>> function) |
flatCollect is a special case of RichIterable.collect(Function) . |
default <P,V1> ImmutableBagIterable<V1> |
flatCollectWith(Function2<? super V,? super P,? extends Iterable<V1>> function,
P parameter) |
|
ImmutableSetMultimap<V,K> |
flip() |
Given a map from Domain
-> Range return a multimap from Range -> Domain. |
ImmutableBiMap<V,K> |
flipUniqueValues() |
Return the MapIterable that is obtained by flipping the direction of this map and making the associations
from value to key.
|
<V1> ImmutableSetMultimap<V1,V> |
groupBy(Function<? super V,? extends V1> function) |
For each element of the iterable, the function is evaluated and the results of these evaluations are collected
into a new multimap, where the transformed value is the key and the original values are added to the same (or similar)
species of collection as the source iterable.
|
<V1> ImmutableSetMultimap<V1,V> |
groupByEach(Function<? super V,? extends Iterable<V1>> function) |
Similar to
RichIterable.groupBy(Function) , except the result of evaluating function will return a collection of keys
for each value. |
<VV> ImmutableBiMap<VV,V> |
groupByUniqueKey(Function<? super V,? extends VV> function) |
For each element of the iterable, the function is evaluated and he results of these evaluations are collected
into a new map, where the transformed value is the key.
|
ImmutableBiMap<V,K> |
inverse() |
Returns an inversed view of this BiMap, where the associations are in the direction of this bimap's values to keys.
|
ImmutableBiMap<K,V> |
newWithAllKeyValueArguments(Pair<? extends K,? extends V>... keyValuePairs) |
|
ImmutableBiMap<K,V> |
newWithAllKeyValues(Iterable<? extends Pair<? extends K,? extends V>> keyValues) |
|
ImmutableBiMap<K,V> |
newWithKeyValue(K key,
V value) |
|
ImmutableBiMap<K,V> |
newWithoutAllKeys(Iterable<? extends K> keys) |
|
ImmutableBiMap<K,V> |
newWithoutKey(K key) |
|
PartitionImmutableSet<V> |
partition(Predicate<? super V> predicate) |
Filters a collection into a PartitionedIterable based on the evaluation of the predicate.
|
<P> PartitionImmutableSet<V> |
partitionWith(Predicate2<? super V,? super P> predicate,
P parameter) |
Filters a collection into a PartitionIterable based on the evaluation of the predicate.
|
ImmutableSet<V> |
reject(Predicate<? super V> predicate) |
Returns all elements of the source collection that return false when evaluating of the predicate.
|
ImmutableBiMap<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.
|
<P> ImmutableSet<V> |
rejectWith(Predicate2<? super V,? super P> predicate,
P parameter) |
Similar to
RichIterable.reject(Predicate) , except with an evaluation parameter for the second generic argument in Predicate2 . |
ImmutableSet<V> |
select(Predicate<? super V> predicate) |
Returns all elements of the source collection that return true when evaluating the predicate.
|
ImmutableBiMap<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.
|
<S> ImmutableSet<S> |
selectInstancesOf(Class<S> clazz) |
Returns all elements of the source collection that are instances of the Class
clazz . |
<P> ImmutableSet<V> |
selectWith(Predicate2<? super V,? super P> predicate,
P parameter) |
Similar to
RichIterable.select(Predicate) , except with an evaluation parameter for the second generic argument in Predicate2 . |
ImmutableBiMap<K,V> |
tap(Procedure<? super V> procedure) |
Executes the Procedure for each value of the map and returns
this . |
<S> ImmutableSet<Pair<V,S>> |
zip(Iterable<S> that) |
Deprecated.
in 8.0. Use
OrderedIterable.zip(Iterable) instead. |
ImmutableSet<Pair<V,Integer>> |
zipWithIndex() |
Deprecated.
in 8.0. Use
OrderedIterable.zipWithIndex() instead. |
toImmutable
aggregateBy, aggregateInPlaceBy, castToMap, countBy, countByEach, countByWith
forEach, forEachWith, forEachWithIndex
containsKey, containsValue, detect, detectOptional, equals, forEachKey, forEachKeyValue, forEachValue, get, getIfAbsent, getIfAbsentValue, getIfAbsentWith, hashCode, ifPresentApply, keysView, keyValuesView, parallelStream, spliterator, stream, toString, valuesView
allSatisfy, allSatisfyWith, anySatisfy, anySatisfyWith, appendString, appendString, appendString, asLazy, chunk, collect, collectBoolean, collectBoolean, collectByte, collectByte, collectChar, collectChar, collectDouble, collectDouble, collectFloat, collectFloat, collectIf, collectInt, collectInt, collectLong, collectLong, collectShort, collectShort, collectWith, contains, containsAll, containsAllArguments, containsAllIterable, count, countBy, countByEach, countByWith, countWith, detect, detectIfNone, detectOptional, detectWith, detectWithIfNone, detectWithOptional, each, flatCollect, flatCollectWith, forEach, getAny, getFirst, getLast, getOnly, groupBy, groupByEach, groupByUniqueKey, injectInto, injectInto, injectInto, injectInto, injectInto, into, isEmpty, makeString, makeString, makeString, max, max, maxBy, maxByOptional, maxOptional, maxOptional, min, min, minBy, minByOptional, minOptional, minOptional, noneSatisfy, noneSatisfyWith, notEmpty, reduce, reduceInPlace, reduceInPlace, reject, rejectWith, select, selectWith, size, sumByDouble, sumByFloat, sumByInt, sumByLong, summarizeDouble, summarizeFloat, summarizeInt, summarizeLong, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toArray, toArray, toBag, toBiMap, toList, toMap, toMap, toSet, toSortedBag, toSortedBag, toSortedBagBy, toSortedList, toSortedList, toSortedListBy, toSortedMap, toSortedMap, toSortedMapBy, toSortedSet, toSortedSet, toSortedSetBy, zip, zipWithIndex
ImmutableBiMap<K,V> newWithKeyValue(K key, V value)
newWithKeyValue
in interface ImmutableMapIterable<K,V>
ImmutableBiMap<K,V> newWithAllKeyValues(Iterable<? extends Pair<? extends K,? extends V>> keyValues)
newWithAllKeyValues
in interface ImmutableMapIterable<K,V>
ImmutableBiMap<K,V> newWithAllKeyValueArguments(Pair<? extends K,? extends V>... keyValuePairs)
newWithAllKeyValueArguments
in interface ImmutableMapIterable<K,V>
ImmutableBiMap<K,V> newWithoutKey(K key)
newWithoutKey
in interface ImmutableMapIterable<K,V>
ImmutableBiMap<K,V> newWithoutAllKeys(Iterable<? extends K> keys)
newWithoutAllKeys
in interface ImmutableMapIterable<K,V>
ImmutableBiMap<V,K> inverse()
BiMap
ImmutableSetMultimap<V,K> flip()
MapIterable
->
Range return a multimap from Range ->
Domain. We chose the name 'flip'
rather than 'invert' or 'transpose' since this method does not have the property of applying twice
returns the original.
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.
ImmutableBiMap<V,K> flipUniqueValues()
MapIterable
MapIterable<Integer, String> map = this.newMapWithKeysValues(1, "1", 2, "2", 3, "3"); MapIterable<String, Integer> result = map.flipUniqueValues(); Assert.assertTrue(result.equals(UnifiedMap.newWithKeysValues("1", 1, "2", 2, "3", 3)));
flipUniqueValues
in interface BiMap<K,V>
flipUniqueValues
in interface ImmutableMapIterable<K,V>
flipUniqueValues
in interface MapIterable<K,V>
ImmutableBiMap<K,V> tap(Procedure<? super V> procedure)
MapIterable
this
.
return peopleByCity.tap(person -> LOGGER.info(person.getName()));
tap
in interface BiMap<K,V>
tap
in interface ImmutableMapIterable<K,V>
tap
in interface MapIterable<K,V>
tap
in interface RichIterable<K>
RichIterable.forEach(Procedure)
ImmutableBiMap<K,V> select(Predicate2<? super K,? super V> predicate)
MapIterable
MapIterable<City, Person> selected = peopleByCity.select((city, person) -> city.getName().equals("Anytown") && person.getLastName().equals("Smith"));
ImmutableBiMap<K,V> reject(Predicate2<? super K,? super V> predicate)
MapIterable
MapIterable<City, Person> rejected = peopleByCity.reject((city, person) -> city.getName().equals("Anytown") && person.getLastName().equals("Smith"));
<K2,V2> ImmutableBiMap<K2,V2> collect(Function2<? super K,? super V,Pair<K2,V2>> function)
BiMap
MapIterable<String, String> collected = peopleByCity.collect((City city, Person person) -> Pair.of(city.getCountry(), person.getAddress().getCity()));Implementations are expected to delegate to
MutableBiMap.put(Object, Object)
,
newWithKeyValue(Object, Object)
, or equivalent, not MutableBiMap.forcePut(Object, Object)
.<R> ImmutableBiMap<K,R> collectValues(Function2<? super K,? super V,? extends R> function)
BiMap
MapIterable<City, String> collected = peopleByCity.collectValues((City city, Person person) -> person.getFirstName() + " " + person.getLastName());Implementations are expected to delegate to
MutableBiMap.put(Object, Object)
,
newWithKeyValue(Object, Object)
, or equivalent, not MutableBiMap.forcePut(Object, Object)
.collectValues
in interface BiMap<K,V>
collectValues
in interface ImmutableMapIterable<K,V>
collectValues
in interface MapIterable<K,V>
ImmutableSet<V> select(Predicate<? super V> predicate)
RichIterable
Example using a Java 8 lambda expression:
RichIterable<Person> selected = people.select(person -> person.getAddress().getCity().equals("London"));
Example using an anonymous inner class:
RichIterable<Person> selected = people.select(new Predicate<Person>() { public boolean accept(Person person) { return person.getAddress().getCity().equals("London"); } });
<P> ImmutableSet<V> selectWith(Predicate2<? super V,? super P> predicate, P parameter)
RichIterable
RichIterable.select(Predicate)
, except with an evaluation parameter for the second generic argument in Predicate2
.
E.g. return a Collection
of Person elements where the person has an age greater than or equal to 18 years
Example using a Java 8 lambda expression:
RichIterable<Person> selected = people.selectWith((Person person, Integer age) -> person.getAge()>= age, Integer.valueOf(18));
Example using an anonymous inner class:
RichIterable<Person> selected = people.selectWith(new Predicate2<Person, Integer>() { public boolean accept(Person person, Integer age) { return person.getAge()>= age; } }, Integer.valueOf(18));
selectWith
in interface BiMap<K,V>
selectWith
in interface ImmutableMapIterable<K,V>
selectWith
in interface RichIterable<K>
predicate
- a Predicate2
to use as the select criteriaparameter
- a parameter to pass in for evaluation of the second argument P
in predicate
RichIterable.select(Predicate)
ImmutableSet<V> reject(Predicate<? super V> predicate)
RichIterable
Example using a Java 8 lambda expression:
RichIterable<Person> rejected = people.reject(person -> person.person.getLastName().equals("Smith"));
Example using an anonymous inner class:
RichIterable<Person> rejected = people.reject(new Predicate<Person>() { public boolean accept(Person person) { return person.person.getLastName().equals("Smith"); } });
reject
in interface BiMap<K,V>
reject
in interface ImmutableMapIterable<K,V>
reject
in interface RichIterable<K>
predicate
- a Predicate
to use as the reject criteriaPredicate.accept(Object)
method to evaluate to false<P> ImmutableSet<V> rejectWith(Predicate2<? super V,? super P> predicate, P parameter)
RichIterable
RichIterable.reject(Predicate)
, except with an evaluation parameter for the second generic argument in Predicate2
.
E.g. return a Collection
of Person elements where the person has an age greater than or equal to 18 years
Example using a Java 8 lambda expression:
RichIterable<Person> rejected = people.rejectWith((Person person, Integer age) -> person.getAge() < age, Integer.valueOf(18));
Example using an anonymous inner class:
MutableList<Person> rejected = people.rejectWith(new Predicate2<Person, Integer>() { public boolean accept(Person person, Integer age) { return person.getAge() < age; } }, Integer.valueOf(18));
rejectWith
in interface BiMap<K,V>
rejectWith
in interface ImmutableMapIterable<K,V>
rejectWith
in interface RichIterable<K>
predicate
- a Predicate2
to use as the select criteriaparameter
- a parameter to pass in for evaluation of the second argument P
in predicate
RichIterable.select(Predicate)
PartitionImmutableSet<V> partition(Predicate<? super V> predicate)
RichIterable
Example using a Java 8 lambda expression:
PartitionIterable<Person> newYorkersAndNonNewYorkers = people.partition(person -> person.getAddress().getState().getName().equals("New York"));
Example using an anonymous inner class:
PartitionIterable<Person> newYorkersAndNonNewYorkers = people.partition(new Predicate<Person>() { public boolean accept(Person person) { return person.getAddress().getState().getName().equals("New York"); } });
<P> PartitionImmutableSet<V> partitionWith(Predicate2<? super V,? super P> predicate, P parameter)
RichIterable
Example using a Java 8 lambda expression:
PartitionIterable<Person> newYorkersAndNonNewYorkers = people.partitionWith((Person person, String state) -> person.getAddress().getState().getName().equals(state), "New York");
Example using an anonymous inner class:
PartitionIterable<Person> newYorkersAndNonNewYorkers = people.partitionWith(new Predicate2<Person, String>() { public boolean accept(Person person, String state) { return person.getAddress().getState().getName().equals(state); } }, "New York");
partitionWith
in interface BiMap<K,V>
partitionWith
in interface RichIterable<K>
<S> ImmutableSet<S> selectInstancesOf(Class<S> clazz)
RichIterable
clazz
.
RichIterable<Integer> integers = List.mutable.with(new Integer(0), new Long(0L), new Double(0.0)).selectInstancesOf(Integer.class);
selectInstancesOf
in interface BiMap<K,V>
selectInstancesOf
in interface ImmutableMapIterable<K,V>
selectInstancesOf
in interface RichIterable<K>
<V1> ImmutableBagIterable<V1> collect(Function<? super V,? extends V1> function)
RichIterable
Example using a Java 8 lambda expression:
RichIterable<String> names = people.collect(person -> person.getFirstName() + " " + person.getLastName());
Example using an anonymous inner class:
RichIterable<String> names = people.collect(new Function<Person, String>() { public String valueOf(Person person) { return person.getFirstName() + " " + person.getLastName(); } });
collect
in interface RichIterable<K>
<P,V1> ImmutableBagIterable<V1> collectWith(Function2<? super V,? super P,? extends V1> function, P parameter)
RichIterable
RichIterable.collect(Function)
with a Function2
and specified parameter which is passed to the block.
Example using a Java 8 lambda expression:
RichIterable<Integer> integers = Lists.mutable.with(1, 2, 3).collectWith((each, parameter) -> each + parameter, Integer.valueOf(1));
Example using an anonymous inner class:
Function2<Integer, Integer, Integer> addParameterFunction = new Function2<Integer, Integer, Integer>() { public Integer value(Integer each, Integer parameter) { return each + parameter; } }; RichIterable<Integer> integers = Lists.mutable.with(1, 2, 3).collectWith(addParameterFunction, Integer.valueOf(1));
collectWith
in interface RichIterable<K>
function
- A Function2
to use as the collect transformation functionparameter
- A parameter to pass in for evaluation of the second argument P
in function
RichIterable
that contains the transformed elements returned by Function2.value(Object, Object)
RichIterable.collect(Function)
<V1> ImmutableBagIterable<V1> collectIf(Predicate<? super V> predicate, Function<? super V,? extends V1> function)
RichIterable
Example using a Java 8 lambda and method reference:
RichIterable<String> strings = Lists.mutable.with(1, 2, 3).collectIf(e -> e != null, Object::toString);
Example using Predicates factory:
RichIterable<String> strings = Lists.mutable.with(1, 2, 3).collectIf(Predicates.notNull(), Functions.getToString());
collectIf
in interface RichIterable<K>
<V1> ImmutableBagIterable<V1> flatCollect(Function<? super V,? extends Iterable<V1>> function)
RichIterable
flatCollect
is a special case of RichIterable.collect(Function)
. With collect
, when the Function
returns
a collection, the result is a collection of collections. flatCollect
outputs a single "flattened" collection
instead. This method is commonly called flatMap.
Consider the following example where we have a Person
class, and each Person
has a list of Address
objects. Take the following Function
:
Function<Person, List<Address>> addressFunction = Person::getAddresses; RichIterable<Person> people = ...;Using
collect
returns a collection of collections of addresses.
RichIterable<List<Address>> addresses = people.collect(addressFunction);Using
flatCollect
returns a single flattened list of addresses.
RichIterable<Address> addresses = people.flatCollect(addressFunction);
flatCollect
in interface RichIterable<K>
function
- The Function
to applyfunction
default <P,V1> ImmutableBagIterable<V1> flatCollectWith(Function2<? super V,? super P,? extends Iterable<V1>> function, P parameter)
flatCollectWith
in interface RichIterable<K>
<V1> ImmutableSetMultimap<V1,V> groupBy(Function<? super V,? extends V1> function)
RichIterable
Example using a Java 8 method reference:
Multimap<String, Person> peopleByLastName = people.groupBy(Person::getLastName);
Example using an anonymous inner class:
Multimap<String, Person> peopleByLastName = people.groupBy(new Function<Person, String>() { public String valueOf(Person person) { return person.getLastName(); } });
<V1> ImmutableSetMultimap<V1,V> groupByEach(Function<? super V,? extends Iterable<V1>> function)
RichIterable
RichIterable.groupBy(Function)
, except the result of evaluating function will return a collection of keys
for each value.groupByEach
in interface BiMap<K,V>
groupByEach
in interface ImmutableMapIterable<K,V>
groupByEach
in interface RichIterable<K>
<VV> ImmutableBiMap<VV,V> groupByUniqueKey(Function<? super V,? extends VV> function)
RichIterable
groupByUniqueKey
in interface BiMap<K,V>
groupByUniqueKey
in interface ImmutableMapIterable<K,V>
groupByUniqueKey
in interface RichIterable<K>
RichIterable.groupBy(Function)
@Deprecated <S> ImmutableSet<Pair<V,S>> zip(Iterable<S> that)
OrderedIterable.zip(Iterable)
instead.RichIterable
RichIterable
formed from this RichIterable
and another RichIterable
by
combining corresponding elements in pairs. If one of the two RichIterable
s is longer than the other, its
remaining elements are ignored.zip
in interface BiMap<K,V>
zip
in interface ImmutableMapIterable<K,V>
zip
in interface RichIterable<K>
S
- the type of the second half of the returned pairsthat
- The RichIterable
providing the second half of each result pairRichIterable
containing pairs consisting of corresponding elements of this
RichIterable
and that. The length of the returned RichIterable
is the minimum of the lengths of
this RichIterable
and that.@Deprecated ImmutableSet<Pair<V,Integer>> zipWithIndex()
OrderedIterable.zipWithIndex()
instead.RichIterable
RichIterable
with its indices.zipWithIndex
in interface BiMap<K,V>
zipWithIndex
in interface ImmutableMapIterable<K,V>
zipWithIndex
in interface RichIterable<K>
RichIterable
containing pairs consisting of all elements of this RichIterable
paired with their index. Indices start at 0.RichIterable.zip(Iterable)
Copyright © 2004–2019. All rights reserved.