Top Description Methods
org.eclipse.collections.api.bimap

public Interface BiMap<K, V>

extends MapIterable<K, V>
Known Direct Subinterfaces
org.eclipse.collections.api.bimap.ImmutableBiMap, org.eclipse.collections.api.bimap.MutableBiMap
Imports
org.eclipse.collections.api.block.function.Function, .Function2, org.eclipse.collections.api.block.predicate.Predicate, .Predicate2, org.eclipse.collections.api.block.procedure.Procedure, org.eclipse.collections.api.map.MapIterable, org.eclipse.collections.api.multimap.set.SetMultimap, org.eclipse.collections.api.ordered.OrderedIterable, org.eclipse.collections.api.partition.set.PartitionUnsortedSet, org.eclipse.collections.api.set.SetIterable, org.eclipse.collections.api.tuple.Pair

A map that allows users to look up key-value pairs from either direction. Uniqueness is enforced on both the keys and values.
Since
4.2

Method Summary

Modifier and TypeMethod and Description
public <K2, V2> BiMap<K2, V2>
collect(Function2<? super K, ? super V, Pair<K2, V2>> function)

Redeclares org.eclipse.collections.api.map.MapIterable.collect.

For each key and value of the map the function is evaluated.

public <R> BiMap<R, V>
collectKeysUnique(Function2<? super K, ? super V, ? extends R> function)

Redeclares org.eclipse.collections.api.map.MapIterable.collectKeysUnique.

For each key and value of the map the function is evaluated.

public <R> BiMap<K, R>
collectValues(Function2<? super K, ? super V, ? extends R> function)

Redeclares org.eclipse.collections.api.map.MapIterable.collectValues.

For each key and value of the map the function is evaluated.

public SetMultimap<V, K>
flip()

Redeclares org.eclipse.collections.api.map.MapIterable.flip.

Given a map from Domain -> Range return a multimap from Range -> Domain.

public BiMap<V, K>
flipUniqueValues()

Redeclares org.eclipse.collections.api.map.MapIterable.flipUniqueValues.

Return the MapIterable that is obtained by flipping the direction of this map and making the associations from value to key.

public <V1> SetMultimap<V1, V>
groupBy(Function<? super V, ? extends V1> function)

Redeclares org.eclipse.collections.api.RichIterable.groupBy.

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.

public <V1> SetMultimap<V1, V>
groupByEach(Function<? super V, ? extends Iterable<V1>> function)

Redeclares org.eclipse.collections.api.RichIterable.groupByEach.

Similar to groupBy(Function), except the result of evaluating function will return a collection of keys for each value.

public <VV> BiMap<VV, V>
groupByUniqueKey(Function<? super V, ? extends VV> function)

Redeclares org.eclipse.collections.api.RichIterable.groupByUniqueKey.

For each element of the iterable, the function is evaluated, and the results of these evaluations are collected into a new map, where the transformed value is the key.

public BiMap<V, K>
inverse()

Returns an inversed view of this BiMap, where the associations are in the direction of this bimap's values to keys.

public PartitionUnsortedSet<V>
partition(Predicate<? super V> predicate)

Redeclares org.eclipse.collections.api.RichIterable.partition.

Filters a collection into a PartitionedIterable based on the evaluation of the predicate.

public <P> PartitionUnsortedSet<V>
partitionWith(Predicate2<? super V, ? super P> predicate, P parameter)

Redeclares org.eclipse.collections.api.RichIterable.partitionWith.

Filters a collection into a PartitionIterable based on the evaluation of the predicate.

public BiMap<K, V>
reject(Predicate2<? super K, ? super V> predicate)

Redeclares org.eclipse.collections.api.map.MapIterable.reject.

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.

public SetIterable<V>
reject(Predicate<? super V> predicate)

Redeclares org.eclipse.collections.api.RichIterable.reject.

Returns all elements of the source collection that return false when evaluating of the predicate.

public <P> SetIterable<V>
rejectWith(Predicate2<? super V, ? super P> predicate, P parameter)

Redeclares org.eclipse.collections.api.RichIterable.rejectWith.

Similar to reject(Predicate), except with an evaluation parameter for the second generic argument in Predicate2.

public BiMap<K, V>
select(Predicate2<? super K, ? super V> predicate)

Redeclares org.eclipse.collections.api.map.MapIterable.select.

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.

public SetIterable<V>
select(Predicate<? super V> predicate)

Redeclares org.eclipse.collections.api.RichIterable.select.

Returns all elements of the source collection that return true when evaluating the predicate.

public <S> SetIterable<S>
selectInstancesOf(Class<S> clazz)

Redeclares org.eclipse.collections.api.RichIterable.selectInstancesOf.

Returns all elements of the source collection that are instances of the Class clazz.

public <P> SetIterable<V>
selectWith(Predicate2<? super V, ? super P> predicate, P parameter)

Redeclares org.eclipse.collections.api.RichIterable.selectWith.

Similar to select(Predicate), except with an evaluation parameter for the second generic argument in Predicate2.

public BiMap<K, V>
tap(Procedure<? super V> procedure)

Redeclares org.eclipse.collections.api.map.MapIterable.tap.

Executes the Procedure for each value of the map and returns this.

public ImmutableBiMap<K, V>
toImmutable()

Redeclares org.eclipse.collections.api.map.MapIterable.toImmutable.

Converts the BiMap to an ImmutableBiMap.

public <S> SetIterable<Pair<V, S>>
zip(Iterable<S> that)

Redeclares org.eclipse.collections.api.RichIterable.zip.

Deprecated in 8.0. Use OrderedIterable#zip(Iterable) instead.

Returns a RichIterable formed from this RichIterable and another RichIterable by combining corresponding elements in pairs.

public SetIterable<Pair<V, Integer>>
zipWithIndex()

Redeclares org.eclipse.collections.api.RichIterable.zipWithIndex.

Deprecated in 8.0. Use OrderedIterable#zipWithIndex() instead.

Zips this RichIterable with its indices.

Inherited from org.eclipse.collections.api.map.MapIterable:
aggregateBycontainsKeycontainsValuedetectdetectOptionalequalsforEachforEachKeyforEachKeyValueforEachValuegetgetIfAbsentgetIfAbsentValuegetIfAbsentWithgetOrDefaulthashCodeifPresentApplyinjectIntoKeyValuekeysViewkeyValuesViewparallelStreamspliteratorstreamtoStringvaluesView

Method Detail

collectback to summary
public <K2, V2> BiMap<K2, V2> collect(Function2<? super K, ? super V, Pair<K2, V2>> function)

Redeclares org.eclipse.collections.api.map.MapIterable.collect.

Doc from org.eclipse.collections.api.map.MapIterable.collect.

For each key and value of the map the function is evaluated. The results of these evaluations are returned in a new map. The map returned will use the values projected from the function rather than the original values.

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), ImmutableBiMap#newWithKeyValue(Object, Object), or equivalent, not MutableBiMap#forcePut(Object, Object).
Annotations
@Override
Exceptions
RuntimeException:
when function returns colliding keys or values.
collectKeysUniqueback to summary
public <R> BiMap<R, V> collectKeysUnique(Function2<? super K, ? super V, ? extends R> function)

Redeclares org.eclipse.collections.api.map.MapIterable.collectKeysUnique.

Doc from org.eclipse.collections.api.map.MapIterable.collectKeysUnique.

For each key and value of the map the function is evaluated. The results of these evaluations are returned in a new map. The map returned will use the keys projected from the function rather than the original keys.

Annotations
@Override
collectValuesback to summary
public <R> BiMap<K, R> collectValues(Function2<? super K, ? super V, ? extends R> function)

Redeclares org.eclipse.collections.api.map.MapIterable.collectValues.

Doc from org.eclipse.collections.api.map.MapIterable.collectValues.

For each key and value of the map the function is evaluated. The results of these evaluations are returned in a new map. The map returned will use the values projected from the function rather than the original values.

MapIterable<City, String> collected =
    peopleByCity.collectValues((City city, Person person) -> person.getFirstName() + " " + person.getLastName());
Implementations are expected to delegate to MutableBiMap#put(Object, Object), ImmutableBiMap#newWithKeyValue(Object, Object), or equivalent, not MutableBiMap#forcePut(Object, Object).
Annotations
@Override
Exceptions
RuntimeException:
when function returns colliding values.
flipback to summary
public SetMultimap<V, K> flip()

Redeclares org.eclipse.collections.api.map.MapIterable.flip.

Doc from org.eclipse.collections.api.map.MapIterable.flip.

Given a map from Domain -> 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.

Annotations
@Override
flipUniqueValuesback to summary
public BiMap<V, K> flipUniqueValues()

Redeclares org.eclipse.collections.api.map.MapIterable.flipUniqueValues.

Doc from org.eclipse.collections.api.map.MapIterable.flipUniqueValues.

Return the MapIterable that is obtained by flipping the direction of this map and making the associations from value to key.

    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)));
Annotations
@Override
groupByback to summary
public <V1> SetMultimap<V1, V> groupBy(Function<? super V, ? extends V1> function)

Redeclares org.eclipse.collections.api.RichIterable.groupBy.

Doc from org.eclipse.collections.api.RichIterable.groupBy.

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.

Example using a Java 8 method reference:

Multimap<String, Person> peopleByLastName =
    people.groupBy(Person::getLastName);
Annotations
@Override
groupByEachback to summary
public <V1> SetMultimap<V1, V> groupByEach(Function<? super V, ? extends Iterable<V1>> function)

Redeclares org.eclipse.collections.api.RichIterable.groupByEach.

Doc from org.eclipse.collections.api.RichIterable.groupByEach.

Similar to groupBy(Function), except the result of evaluating function will return a collection of keys for each value.

Annotations
@Override
groupByUniqueKeyback to summary
public <VV> BiMap<VV, V> groupByUniqueKey(Function<? super V, ? extends VV> function)

Redeclares org.eclipse.collections.api.RichIterable.groupByUniqueKey.

Doc from org.eclipse.collections.api.RichIterable.groupByUniqueKey.

For each element of the iterable, the function is evaluated, and the results of these evaluations are collected into a new map, where the transformed value is the key. The generated keys must each be unique, or else an exception is thrown.

Annotations
@Override
inverseback to summary
public BiMap<V, K> inverse()

Returns an inversed view of this BiMap, where the associations are in the direction of this bimap's values to keys.

partitionback to summary
public PartitionUnsortedSet<V> partition(Predicate<? super V> predicate)

Redeclares org.eclipse.collections.api.RichIterable.partition.

Doc from org.eclipse.collections.api.RichIterable.partition.

Filters a collection into a PartitionedIterable based on the evaluation of the predicate.

Example using a Java 8 lambda expression:

PartitionIterable<Person> newYorkersAndNonNewYorkers =
    people.partition(person -> person.getAddress().getState().getName().equals("New York"));
Annotations
@Override
partitionWithback to summary
public <P> PartitionUnsortedSet<V> partitionWith(Predicate2<? super V, ? super P> predicate, P parameter)

Redeclares org.eclipse.collections.api.RichIterable.partitionWith.

Doc from org.eclipse.collections.api.RichIterable.partitionWith.

Filters a collection into a PartitionIterable based on the evaluation of the predicate.

Example using a Java 8 lambda expression:

PartitionIterable<Person> newYorkersAndNonNewYorkers =
    people.partitionWith((Person person, String state) -> person.getAddress().getState().getName().equals(state), "New York");
Annotations
@Override
rejectback to summary
public BiMap<K, V> reject(Predicate2<? super K, ? super V> predicate)

Redeclares org.eclipse.collections.api.map.MapIterable.reject.

Doc from org.eclipse.collections.api.map.MapIterable.reject.

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<City, Person> rejected =
    peopleByCity.reject((city, person) -> city.getName().equals("Anytown") && person.getLastName().equals("Smith"));
Annotations
@Override
rejectback to summary
public SetIterable<V> reject(Predicate<? super V> predicate)

Redeclares org.eclipse.collections.api.RichIterable.reject.

Doc from org.eclipse.collections.api.RichIterable.reject.

Returns all elements of the source collection that return false when evaluating of the predicate. This method is also sometimes called filterNot and is the equivalent of calling iterable.select(Predicates.not(predicate)).

Example using a Java 8 lambda expression:

RichIterable<Person> rejected =
    people.reject(person -> person.person.getLastName().equals("Smith"));
Annotations
@Override
rejectWithback to summary
public <P> SetIterable<V> rejectWith(Predicate2<? super V, ? super P> predicate, P parameter)

Redeclares org.eclipse.collections.api.RichIterable.rejectWith.

Doc from org.eclipse.collections.api.RichIterable.rejectWith.

Similar to 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));
Annotations
@Override
selectback to summary
public BiMap<K, V> select(Predicate2<? super K, ? super V> predicate)

Redeclares org.eclipse.collections.api.map.MapIterable.select.

Doc from org.eclipse.collections.api.map.MapIterable.select.

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<City, Person> selected =
    peopleByCity.select((city, person) -> city.getName().equals("Anytown") && person.getLastName().equals("Smith"));
Annotations
@Override
selectback to summary
public SetIterable<V> select(Predicate<? super V> predicate)

Redeclares org.eclipse.collections.api.RichIterable.select.

Doc from org.eclipse.collections.api.RichIterable.select.

Returns all elements of the source collection that return true when evaluating the predicate. This method is also commonly called filter.

Example using a Java 8 lambda expression:

RichIterable<Person> selected =
    people.select(person -> person.getAddress().getCity().equals("London"));
Annotations
@Override
selectInstancesOfback to summary
public <S> SetIterable<S> selectInstancesOf(Class<S> clazz)

Redeclares org.eclipse.collections.api.RichIterable.selectInstancesOf.

Doc from org.eclipse.collections.api.RichIterable.selectInstancesOf.

Returns all elements of the source collection that are instances of the Class clazz.

RichIterable<Integer> integers =
    List.mutable.with(new Integer(0), new Long(0L), new Double(0.0)).selectInstancesOf(Integer.class);
Annotations
@Override
selectWithback to summary
public <P> SetIterable<V> selectWith(Predicate2<? super V, ? super P> predicate, P parameter)

Redeclares org.eclipse.collections.api.RichIterable.selectWith.

Doc from org.eclipse.collections.api.RichIterable.selectWith.

Similar to 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));
Annotations
@Override
tapback to summary
public BiMap<K, V> tap(Procedure<? super V> procedure)

Redeclares org.eclipse.collections.api.map.MapIterable.tap.

Doc from org.eclipse.collections.api.map.MapIterable.tap.

Executes the Procedure for each value of the map and returns this.

return peopleByCity.tap(person -> LOGGER.info(person.getName()));
Annotations
@Override
toImmutableback to summary
public ImmutableBiMap<K, V> toImmutable()

Redeclares org.eclipse.collections.api.map.MapIterable.toImmutable.

Converts the BiMap to an ImmutableBiMap. If the bimap is immutable, it returns itself.

Annotations
@Override
zipback to summary
public <S> SetIterable<Pair<V, S>> zip(Iterable<S> that)

Redeclares org.eclipse.collections.api.RichIterable.zip.

Doc from org.eclipse.collections.api.RichIterable.zip.

Deprecated

in 8.0. Use OrderedIterable#zip(Iterable) instead.

Returns a RichIterable formed from this RichIterable and another RichIterable by combining corresponding elements in pairs. If one of the two RichIterables is longer than the other, its remaining elements are ignored.

Annotations
@Override
@Deprecated
zipWithIndexback to summary
public SetIterable<Pair<V, Integer>> zipWithIndex()

Redeclares org.eclipse.collections.api.RichIterable.zipWithIndex.

Doc from org.eclipse.collections.api.RichIterable.zipWithIndex.

Deprecated

in 8.0. Use OrderedIterable#zipWithIndex() instead.

Zips this RichIterable with its indices.

Annotations
@Override
@Deprecated