|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.google.common.collect.ImmutableBiMapBuilder<K,V>
public class ImmutableBiMapBuilder<K,V>
A convenient way to populate immutable BiMap instances, especially static-final "constant BiMaps". Code such as
static final BiMap<String,Integer> ENGLISH_TO_INTEGER_BIMAP = createNumbersMap(); static BiMap<String,Integer> createNumbersMap() { BiMap<String,Integer> bimap = StandardBiMap.newInstance(); bimap.put("one", 1); bimap.put("two", 2); bimap.put("three", 3); return StandardBiMap.unmodifiableBiMap(bimap); }... can be rewritten far more simply as ...
static final BiMap<String,Integer> ENGLISH_TO_INTEGER_BIMAP = new ImmutableBiMapBuilder<String,Integer>() .put("one", 1) .put("two", 2) .put("three", 3) .getBiMap();(Actually, for small immutable bimaps, you can use members of the even-more-convenient
Maps.immutableBiMap()
family of methods.)
Constructor Summary | |
---|---|
ImmutableBiMapBuilder()
Creates a new ImmutableBiMapBuilder with an unspecified expected size. |
|
ImmutableBiMapBuilder(int expectedSize)
Creates a new ImmutableBiMapBuilder with the given expected size. |
Method Summary | |
---|---|
BiMap<K,V> |
getBiMap()
Returns a newly-created, immutable BiMap instance containing the keys and values that were specified using put() . |
ImmutableBiMapBuilder<K,V> |
put(K key,
V value)
Adds a key-value mapping to the bimap that will be returned by getBiMap() . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ImmutableBiMapBuilder()
public ImmutableBiMapBuilder(int expectedSize)
expectedSize
- the approximate number of key-value pairs you expect
this bimap to containMethod Detail |
---|
public ImmutableBiMapBuilder<K,V> put(@Nullable K key, @Nullable V value)
getBiMap()
.
key
- key with which the specified value is to be associatedvalue
- value to be associated with the specified key
IllegalStateException
- if getBiMap()
has already been
calledpublic BiMap<K,V> getBiMap()
put()
.
BiMap
instance
IllegalStateException
- if getBiMap()
has already been
called
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |