public abstract class ImmutableBiMap<K,V> extends ImmutableBiMapFauxverideShim<K,V> implements BiMap<K,V>
BiMap
whose contents will never change, with many other important properties detailed
at ImmutableCollection
.Modifier and Type | Class and Description |
---|---|
static class |
ImmutableBiMap.Builder<K,V>
A builder for creating immutable bimap instances, especially
public static final bimaps
("constant bimaps"). |
private static class |
ImmutableBiMap.SerializedForm<K,V>
Serialized type for all ImmutableBiMap instances.
|
ImmutableMap.IteratorBasedImmutableMap<K,V>
EMPTY_ENTRY_ARRAY
Constructor and Description |
---|
ImmutableBiMap() |
Modifier and Type | Method and Description |
---|---|
static <K,V> ImmutableBiMap.Builder<K,V> |
builder()
Returns a new builder.
|
static <K,V> ImmutableBiMap.Builder<K,V> |
builderWithExpectedSize(int expectedSize)
Returns a new builder, expecting the specified number of entries to be added.
|
static <K,V> ImmutableBiMap<K,V> |
copyOf(java.lang.Iterable<? extends java.util.Map.Entry<? extends K,? extends V>> entries)
Returns an immutable bimap containing the given entries.
|
static <K,V> ImmutableBiMap<K,V> |
copyOf(java.util.Map<? extends K,? extends V> map)
Returns an immutable bimap containing the same entries as
map . |
(package private) ImmutableSet<V> |
createValues() |
V |
forcePut(K key,
V value)
Deprecated.
Unsupported operation.
|
abstract ImmutableBiMap<V,K> |
inverse()
Returns the inverse view of this bimap, which maps each of this bimap's values to its
associated key.
|
static <K,V> ImmutableBiMap<K,V> |
of()
Returns the empty bimap.
|
static <K,V> ImmutableBiMap<K,V> |
of(K k1,
V v1)
Returns an immutable bimap containing a single entry.
|
static <K,V> ImmutableBiMap<K,V> |
of(K k1,
V v1,
K k2,
V v2)
Returns an immutable map containing the given entries, in order.
|
static <K,V> ImmutableBiMap<K,V> |
of(K k1,
V v1,
K k2,
V v2,
K k3,
V v3)
Returns an immutable map containing the given entries, in order.
|
static <K,V> ImmutableBiMap<K,V> |
of(K k1,
V v1,
K k2,
V v2,
K k3,
V v3,
K k4,
V v4)
Returns an immutable map containing the given entries, in order.
|
static <K,V> ImmutableBiMap<K,V> |
of(K k1,
V v1,
K k2,
V v2,
K k3,
V v3,
K k4,
V v4,
K k5,
V v5)
Returns an immutable map containing the given entries, in order.
|
static <K,V> ImmutableBiMap<K,V> |
of(K k1,
V v1,
K k2,
V v2,
K k3,
V v3,
K k4,
V v4,
K k5,
V v5,
K k6,
V v6)
Returns an immutable map containing the given entries, in order.
|
static <K,V> ImmutableBiMap<K,V> |
of(K k1,
V v1,
K k2,
V v2,
K k3,
V v3,
K k4,
V v4,
K k5,
V v5,
K k6,
V v6,
K k7,
V v7)
Returns an immutable map containing the given entries, in order.
|
static <K,V> ImmutableBiMap<K,V> |
of(K k1,
V v1,
K k2,
V v2,
K k3,
V v3,
K k4,
V v4,
K k5,
V v5,
K k6,
V v6,
K k7,
V v7,
K k8,
V v8)
Returns an immutable map containing the given entries, in order.
|
static <K,V> ImmutableBiMap<K,V> |
of(K k1,
V v1,
K k2,
V v2,
K k3,
V v3,
K k4,
V v4,
K k5,
V v5,
K k6,
V v6,
K k7,
V v7,
K k8,
V v8,
K k9,
V v9)
Returns an immutable map containing the given entries, in order.
|
static <K,V> ImmutableBiMap<K,V> |
of(K k1,
V v1,
K k2,
V v2,
K k3,
V v3,
K k4,
V v4,
K k5,
V v5,
K k6,
V v6,
K k7,
V v7,
K k8,
V v8,
K k9,
V v9,
K k10,
V v10)
Returns an immutable map containing the given entries, in order.
|
static <K,V> ImmutableBiMap<K,V> |
ofEntries(java.util.Map.Entry<? extends K,? extends V>... entries)
Returns an immutable map containing the given entries, in order.
|
static <T,K,V> java.util.stream.Collector<T,?,ImmutableBiMap<K,V>> |
toImmutableBiMap(java.util.function.Function<? super T,? extends K> keyFunction,
java.util.function.Function<? super T,? extends V> valueFunction)
Returns a
Collector that accumulates elements into an ImmutableBiMap whose keys
and values are the result of applying the provided mapping functions to the input elements. |
ImmutableSet<V> |
values()
Returns an immutable set of the values in this map, in the same order they appear in
ImmutableMap.entrySet . |
(package private) java.lang.Object |
writeReplace()
Returns a serializable form of this object.
|
toImmutableMap, toImmutableMap
asMultimap, checkNoConflict, clear, compute, computeIfAbsent, computeIfPresent, conflictException, containsKey, containsValue, createEntrySet, createKeySet, entryOf, entrySet, equals, get, getOrDefault, hashCode, isEmpty, isHashCodeFast, isPartialView, keyIterator, keySet, keySpliterator, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, toString
public static <T,K,V> java.util.stream.Collector<T,?,ImmutableBiMap<K,V>> toImmutableBiMap(java.util.function.Function<? super T,? extends K> keyFunction, java.util.function.Function<? super T,? extends V> valueFunction)
Collector
that accumulates elements into an ImmutableBiMap
whose keys
and values are the result of applying the provided mapping functions to the input elements.
Entries appear in the result ImmutableBiMap
in encounter order.
If the mapped keys or values contain duplicates (according to Object.equals(Object)
,
an IllegalArgumentException
is thrown when the collection operation is performed. (This
differs from the Collector
returned by Collectors.toMap(Function, Function)
,
which throws an IllegalStateException
.)
public static <K,V> ImmutableBiMap<K,V> of()
Performance note: the instance returned is a singleton.
public static <K,V> ImmutableBiMap<K,V> of(K k1, V v1)
public static <K,V> ImmutableBiMap<K,V> of(K k1, V v1, K k2, V v2)
java.lang.IllegalArgumentException
- if duplicate keys or values are addedpublic static <K,V> ImmutableBiMap<K,V> of(K k1, V v1, K k2, V v2, K k3, V v3)
java.lang.IllegalArgumentException
- if duplicate keys or values are addedpublic static <K,V> ImmutableBiMap<K,V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4)
java.lang.IllegalArgumentException
- if duplicate keys or values are addedpublic static <K,V> ImmutableBiMap<K,V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5)
java.lang.IllegalArgumentException
- if duplicate keys or values are addedpublic static <K,V> ImmutableBiMap<K,V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6)
java.lang.IllegalArgumentException
- if duplicate keys or values are addedpublic static <K,V> ImmutableBiMap<K,V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7)
java.lang.IllegalArgumentException
- if duplicate keys or values are addedpublic static <K,V> ImmutableBiMap<K,V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8)
java.lang.IllegalArgumentException
- if duplicate keys or values are addedpublic static <K,V> ImmutableBiMap<K,V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8, K k9, V v9)
java.lang.IllegalArgumentException
- if duplicate keys or values are addedpublic static <K,V> ImmutableBiMap<K,V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8, K k9, V v9, K k10, V v10)
java.lang.IllegalArgumentException
- if duplicate keys or values are added@SafeVarargs public static <K,V> ImmutableBiMap<K,V> ofEntries(java.util.Map.Entry<? extends K,? extends V>... entries)
java.lang.IllegalArgumentException
- if duplicate keys or values are providedpublic static <K,V> ImmutableBiMap.Builder<K,V> builder()
ImmutableBiMap.Builder
constructor.public static <K,V> ImmutableBiMap.Builder<K,V> builderWithExpectedSize(int expectedSize)
If expectedSize
is exactly the number of entries added to the builder before ImmutableBiMap.Builder.build()
is called, the builder is likely to perform better than an unsized builder()
would have.
It is not specified if any performance benefits apply if expectedSize
is close to,
but not exactly, the number of entries added to the builder.
public static <K,V> ImmutableBiMap<K,V> copyOf(java.util.Map<? extends K,? extends V> map)
map
. If map
somehow
contains entries with duplicate keys (for example, if it is a SortedMap
whose
comparator is not consistent with equals), the results of this method are undefined.
The returned BiMap
iterates over entries in the same order as the entrySet
of the original map.
Despite the method name, this method attempts to avoid actually copying the data when it is safe to do so. The exact circumstances under which a copy will or will not be performed are undocumented and subject to change.
java.lang.IllegalArgumentException
- if two keys have the same value or two values have the same
keyjava.lang.NullPointerException
- if any key or value in map
is nullpublic static <K,V> ImmutableBiMap<K,V> copyOf(java.lang.Iterable<? extends java.util.Map.Entry<? extends K,? extends V>> entries)
java.lang.IllegalArgumentException
- if two keys have the same value or two values have the same
keyjava.lang.NullPointerException
- if any key, value, or entry is nullpublic abstract ImmutableBiMap<V,K> inverse()
Note:There is no guaranteed correspondence between the iteration order of a bimap and that of its inverse.
The inverse of an ImmutableBiMap
is another ImmutableBiMap
.
public ImmutableSet<V> values()
ImmutableMap.entrySet
.final ImmutableSet<V> createValues()
createValues
in class ImmutableMap<K,V>
@Deprecated @CheckForNull public final V forcePut(K key, V value)
forcePut
in interface BiMap<K,V>
key
- the key with which the specified value is to be associatedvalue
- the value to be associated with the specified keynull
if there was no
previous entry. (If the bimap contains null values, then forcePut
, like put
, returns null
both if the key is absent and if it is present with a null
value.)java.lang.UnsupportedOperationException
- alwaysjava.lang.Object writeReplace()
ImmutableMap
writeReplace
in class ImmutableMap<K,V>