public interface MutableBiMap<K,V> extends BiMap<K,V>, MutableMap<K,V>
BiMap whose contents can be altered after initialization.| Modifier and Type | Method and Description |
|---|---|
MutableBiMap<K,V> |
asSynchronized()
Returns a synchronized (thread-safe) map backed by the specified map.
|
MutableBiMap<K,V> |
asUnmodifiable()
Returns an unmodifiable view of this map.
|
MutableBiMap<K,V> |
clone() |
<K2,V2> MutableBiMap<K2,V2> |
collect(Function2<? super K,? super V,Pair<K2,V2>> function)
For each key and value of the map the function is evaluated.
|
<R> MutableBiMap<K,R> |
collectValues(Function2<? super K,? super V,? extends R> function)
For each key and value of the map the function is evaluated.
|
MutableBiMap<V,K> |
flipUniqueValues()
Return the MapIterable that is obtained by flipping the direction of this map and making the associations
from value to key.
|
V |
forcePut(K key,
V value)
Similar to
put(Object, Object), except that it quietly removes any existing entry with the same
value before putting the key-value pair. |
MutableBiMap<V,K> |
inverse()
Returns an inversed view of this BiMap, where the associations are in the direction of this bimap’s values to keys.
|
MutableBiMap<K,V> |
newEmpty()
Creates a new instance of the same type, using the default capacity and growth parameters.
|
V |
put(K key,
V value)
Similar to
Map.put(Object, Object), except that it throws on the addition of a duplicate value. |
MutableBiMap<K,V> |
reject(Predicate2<? super K,? super V> predicate)
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.
|
MutableBiMap<K,V> |
select(Predicate2<? super K,? super V> predicate)
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.
|
toImmutableadd, aggregateBy, aggregateInPlaceBy, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectKeysAndValues, collectLong, collectShort, flatCollect, flip, getIfAbsentPut, getIfAbsentPut, getIfAbsentPutWith, getIfAbsentPutWithKey, groupBy, groupByEach, groupByUniqueKey, partition, partitionWith, reject, removeKey, select, selectInstancesOf, toImmutable, updateValue, updateValueWith, withAllKeyValueArguments, withAllKeyValues, withKeyValue, withoutAllKeys, withoutKey, zip, zipWithIndexcontainsKey, containsValue, detect, equals, forEachKey, forEachKeyValue, forEachValue, get, getIfAbsent, getIfAbsentValue, getIfAbsentWith, hashCode, ifPresentApply, keysView, keyValuesView, toString, valuesViewallSatisfy, allSatisfyWith, anySatisfy, anySatisfyWith, appendString, appendString, appendString, asLazy, chunk, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, collectWith, contains, containsAll, containsAllArguments, containsAllIterable, count, countWith, detect, detectIfNone, detectWith, detectWithIfNone, flatCollect, getFirst, getLast, groupBy, groupByEach, injectInto, injectInto, injectInto, injectInto, injectInto, isEmpty, makeString, makeString, makeString, max, max, maxBy, min, min, minBy, noneSatisfy, noneSatisfyWith, notEmpty, reject, rejectWith, rejectWith, select, selectWith, selectWith, size, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toArray, toArray, toBag, toList, toMap, toSet, toSortedList, toSortedList, toSortedListBy, toSortedMap, toSortedMap, toSortedSet, toSortedSet, toSortedSetBy, zip, zipWithIndexforEach, forEachWith, forEachWithIndexforEach, iterator, spliteratorclear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keySet, merge, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, valuesMutableBiMap<K,V> clone()
clone in interface MutableMap<K,V>MutableBiMap<K,V> newEmpty()
MutableMapnewEmpty in interface MutableMap<K,V>MutableBiMap<V,K> inverse()
BiMapV put(K key, V value)
Map.put(Object, Object), except that it throws on the addition of a duplicate value.put in interface Map<K,V>IllegalArgumentException - if the value already exists in the bimap.V forcePut(K key, V value)
put(Object, Object), except that it quietly removes any existing entry with the same
value before putting the key-value pair.MutableBiMap<K,V> asSynchronized()
MutableMapIt is imperative that the user manually synchronize on the returned map when iterating over any of its collection views:
MutableMap map = myMutableMap.asSynchronized();
...
Set set = map.keySet(); // Needn't be in synchronized block
...
synchronized(map)
{ // Synchronizing on map, not set!
Iterator i = s.iterator(); // Must be in synchronized block
while (i.hasNext())
foo(i.next());
}
Failure to follow this advice may result in non-deterministic behavior.
The preferred way of iterating over a synchronized collection is to use the collection.forEach() method which is
properly synchronized internally.
MutableMap map = myMutableMap.asSynchronized();
...
Set set = map.keySet(); // Needn't be in synchronized block
...
Iterate.forEach(set, new Procedure()
{
public void value(Object each)
{
...
}
});
The returned map will be serializable if the specified map is serializable.
asSynchronized in interface MutableMap<K,V>MutableBiMap<K,V> asUnmodifiable()
MutableMapUnsupportedOperationException.
The returned map will be Serializable if this map is Serializable.asUnmodifiable in interface MutableMap<K,V>MutableBiMap<K,V> select(Predicate2<? super K,? super V> predicate)
MapIterablee.g.
peopleByCity.select(new Predicate2<City, Person>()
{
public boolean accept(City city, Person person)
{
return city.getName().equals("Anytown") && person.getLastName().equals("Smith");
}
});
<R> MutableBiMap<K,R> collectValues(Function2<? super K,? super V,? extends R> function)
MapIterablee.g.
peopleByCity.collectValues(new Function2<City, Person, String>()
{
public String value(City city, Person person)
{
return person.getFirstName() + " " + person.getLastName();
}
});
collectValues in interface BiMap<K,V>collectValues in interface MapIterable<K,V>collectValues in interface MutableMap<K,V>collectValues in interface UnsortedMapIterable<K,V><K2,V2> MutableBiMap<K2,V2> collect(Function2<? super K,? super V,Pair<K2,V2>> function)
MapIterablee.g.
peopleByCity.collect(new Function2<City, Person, String>()
{
public String value(City city, Person person)
{
return Pair.of(city.getCountry(), person.getAddress().getCity());
}
});
MutableBiMap<K,V> reject(Predicate2<? super K,? super V> predicate)
MapIterablee.g.
peopleByCity.reject(new Predicate2<City, Person>()
{
public boolean accept(City city, Person person)
{
return city.getName().equals("Anytown") && person.getLastName().equals("Smith");
}
});
MutableBiMap<V,K> flipUniqueValues()
MapIterable
MapIterable map = this.newMapWithKeysValues(1, "1", 2, "2", 3, "3");
MapIterable result = map.flipUniqueValues();
Assert.assertTrue(result.equals(UnifiedMap.newWithKeysValues("1", 1, "2", 2, "3", 3)));
flipUniqueValues in interface MapIterable<K,V>flipUniqueValues in interface MutableMap<K,V>Copyright © 2004–2017. All rights reserved.