Top Description Inners Fields Constructors Methods
com.google.common.collect

public final Class HashBiMap<K extends @Nullable Object, V extends @Nullable Object>

extends Maps.IteratorBasedAbstractMap<K extends @Nullable Object, V extends @Nullable Object>
implements BiMap<K extends @Nullable Object, V extends @Nullable Object>, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, com.google.common.collect.BiMap, java.util.Map
Annotations
@GwtCompatible
emulated:true
@ElementTypesAreNonnullByDefault
Static Imports
com.google.common.base.Preconditions.checkArgument, .Preconditions.checkNotNull, com.google.common.collect.CollectPreconditions.checkNonnegative, .Hashing.smearedHash, java.util.Objects.requireNonNull

A BiMap backed by two hash tables. This implementation allows null keys and values. A HashBiMap and its inverse are both serializable.

This implementation guarantees insertion-based iteration order of its keys.

See the Guava User Guide article on BiMap .

Authors
Louis Wasserman, Mike Bostock
Since
2.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private class
private static class
pack-priv abstract class
private class

Field Summary

Modifier and TypeField and Description
private transient HashBiMap.BiEntry<K, V>
private transient @Nullable HashBiMap.BiEntry<K, V>[]
private transient @Nullable HashBiMap.BiEntry<K, V>[]
private transient BiMap<V, K>
private transient HashBiMap.BiEntry<K, V>
private static final double
private transient int
private transient int
private static final long
private transient int

Constructor Summary

AccessConstructor and Description
private
HashBiMap(int expectedSize)

Method Summary

Modifier and TypeMethod and Description
public void
clear()

Overrides com.google.common.collect.Maps.IteratorBasedAbstractMap.clear.

Implements java.util.Map.clear.

Removes all of the mappings from this map (optional operation).
public boolean
containsKey(Object
key whose presence in this map is to be tested
key
)

Overrides java.util.AbstractMap.containsKey.

Implements java.util.Map.containsKey.

Returns true if this map contains a mapping for the specified key.
public boolean

Returns:

true if a mapping exists from a key to the specified value
containsValue
(Object
the object to search for in the values of this BiMap
value
)

Overrides java.util.AbstractMap.containsValue.

Implements java.util.Map.containsValue.

Returns true if this BiMap contains an entry whose value is equal to value (or, equivalently, if this inverse view contains a key that is equal to value).
public static <K extends @Nullable Object, V extends @Nullable Object> HashBiMap<K, V>
create()

Returns a new, empty HashBiMap with the default initial capacity (16).

public static <K extends @Nullable Object, V extends @Nullable Object> HashBiMap<K, V>
create(int
the expected number of entries
expectedSize
)

Constructs a new, empty bimap with the specified expected size.

public static <K extends @Nullable Object, V extends @Nullable Object> HashBiMap<K, V>
create(Map<? extends K, ? extends V> map)

Constructs a new bimap containing initial values from map.

private @Nullable HashBiMap.BiEntry<K, V>[]
createTable(int length)

private void
delete(HashBiMap.BiEntry<K, V> entry)

Finds and removes entry from the bucket linked lists in both the key-to-value direction and the value-to-key direction.

pack-priv Iterator<Map.Entry<K, V>>
public V
forcePut(K
the key with which the specified value is to be associated
key
,
V
the value to be associated with the specified key
value
)

Implements com.google.common.collect.BiMap.forcePut.

An alternate form of put that silently removes any existing entry with the value value before proceeding with the put operation.
public void
forEach(BiConsumer<? super K, ? super V>
The action to be performed for each entry
action
)

Overrides default java.util.Map.forEach.

Performs the given action for each entry in this map until all entries have been processed or the action throws an exception.
public V
get(Object
the key whose associated value is to be returned
key
)

Overrides java.util.AbstractMap.get.

Implements java.util.Map.get.

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.
private void
init(int expectedSize)

private void
insert(HashBiMap.BiEntry<K, V> entry, HashBiMap.BiEntry<K, V> oldEntryForKey)

public BiMap<V, K>
inverse()

Implements com.google.common.collect.BiMap.inverse.

Returns the inverse view of this bimap, which maps each of this bimap's values to its associated key.
public Set<K>
keySet()

Overrides java.util.AbstractMap.keySet.

Implements java.util.Map.keySet.

Returns a Set view of the keys contained in this map.
public V
put(K
key with which the specified value is to be associated
key
,
V
value to be associated with the specified key
value
)

Overrides java.util.AbstractMap.put.

Implements com.google.common.collect.BiMap.put, java.util.Map.put.

Associates the specified value with the specified key in this map (optional operation).
private V
put(K key, V value, boolean force)

private K
putInverse(V value, K key, boolean force)

private void
private void
public V
remove(Object
key whose mapping is to be removed from the map
key
)

Overrides java.util.AbstractMap.remove.

Implements java.util.Map.remove.

Removes the mapping for a key from this map if it is present (optional operation).
public void
replaceAll(BiFunction<? super K, ? super V, ? extends V>
the function to apply to each entry
function
)

Overrides default java.util.Map.replaceAll.

Replaces each entry's value with the result of invoking the given function on that entry until all entries have been processed or the function throws an exception.
private HashBiMap.BiEntry<K, V>
seekByKey(Object key, int keyHash)

private HashBiMap.BiEntry<K, V>
seekByValue(Object value, int valueHash)

public int
size()

Implements abstract com.google.common.collect.Maps.IteratorBasedAbstractMap.size.

Implements java.util.Map.size.

Returns the number of key-value mappings in this map.
public Set<V>
values()

Overrides java.util.AbstractMap.values.

Implements com.google.common.collect.BiMap.values, java.util.Map.values.

Returns a Collection view of the values contained in this map.
private void
Inherited from com.google.common.collect.Maps.IteratorBasedAbstractMap:
entrySetentrySpliteratorforEachEntry