Package org.ethelred.util.collect
Class BiMap<A,B>
java.lang.Object
org.ethelred.util.collect.BiMap<A,B>
- Type Parameters:
A- Type of one of the keys/valuesB- Type of the other keys/values
A bidirectional mapping. Does not implement Map because I don't find that useful now. May not contain nulls or
duplicate keys/values. Immutable.
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <A,B> BiMap.Entry<A, B> entry(A a, B b) Construct an entry for building a BiMap.Get the B value corresponding to the A key.Get the A value corresponding to the B key.keysA()keysB()mapByA()mapByB()static <A,B> BiMap<A, B> ofEntries(Iterable<BiMap.Entry<A, B>> entries) Construct a BiMap from given entries.static <A,B> BiMap<A, B> ofEntries(Collection<BiMap.Entry<A, B>> entries) Construct a BiMap from given entries.static <A,B> BiMap<A, B> ofEntries(BiMap.Entry<A, B>... entries) Construct a BiMap from given entries.intsize()static <A,B> Collector<BiMap.Entry<A, B>, ?, BiMap<A, B>> toBiMap()
-
Constructor Details
-
BiMap
Construct a BiMap from the entries in map.- Parameters:
map- entries to use- Throws:
NullPointerException- when any key or value in map is nullIllegalArgumentException- when there are duplicate keys or values
-
-
Method Details
-
size
public int size() -
getByA
Get the B value corresponding to the A key.- Parameters:
key- A key- Returns:
- Optional containing value, empty if not found
-
getByB
Get the A value corresponding to the B key.- Parameters:
key- B key- Returns:
- Optional containing value, empty if not found
-
entry
Construct an entry for building a BiMap.- Type Parameters:
A- the type of the first key/valueB- the type of the second key/value- Parameters:
a- one of the keys/valuesb- the other key/value- Returns:
- an entry
-
ofEntries
Construct a BiMap from given entries.- Parameters:
entries- entries to use- Throws:
IllegalArgumentException- when there are duplicate keys or values
-
ofEntries
Construct a BiMap from given entries.- Parameters:
entries- entries to use- Throws:
IllegalArgumentException- when there are duplicate keys or values
-
ofEntries
Construct a BiMap from given entries.- Parameters:
entries- entries to use- Throws:
IllegalArgumentException- when there are duplicate keys or values
-
mapByA
- Returns:
- An unmodifiable view of the mapping from A keys
-
mapByB
- Returns:
- An unmodifiable view of the mapping from B keys
-
keysA
- Returns:
- An unmodifiable view of the set of A keys
-
keysB
- Returns:
- An unmodifiable view of the set of B keys
-
toBiMap
- Type Parameters:
A- Type of one of the keys/valuesB- Type of the other keys/values- Returns:
- Collect a stream of Entry into a BiMap
-