@NotThreadSafe public class UnifiedMap<K,V> extends AbstractMutableMap<K,V> implements Externalizable, BatchIterable<V>
| Constructor and Description |
|---|
UnifiedMap() |
UnifiedMap(int initialCapacity) |
UnifiedMap(int initialCapacity,
float loadFactor) |
UnifiedMap(Map<? extends K,? extends V> map) |
UnifiedMap(Pair<K,V>... pairs) |
| Modifier and Type | Method and Description |
|---|---|
void |
batchForEach(Procedure<? super V> procedure,
int sectionIndex,
int sectionCount) |
void |
clear() |
UnifiedMap<K,V> |
clone()
Returns a string representation of this map.
|
<E> MutableMap<K,V> |
collectKeysAndValues(Iterable<E> iterable,
Function<? super E,? extends K> keyFunction,
Function<? super E,? extends V> valueFunction)
Adds all the entries derived from
collection to this. |
boolean |
containsKey(Object key) |
boolean |
containsValue(Object value) |
Set<Map.Entry<K,V>> |
entrySet() |
boolean |
equals(Object object)
Follows the same general contract as
Map.equals(Object). |
void |
forEachKey(Procedure<? super K> procedure)
Calls the
procedure with each key of the map. |
void |
forEachKeyValue(Procedure2<? super K,? super V> procedure)
Calls the
procedure with each key-value pair of the map. |
void |
forEachValue(Procedure<? super V> procedure)
Calls the procedure with each value of the map.
|
<P> void |
forEachWith(Procedure2<? super V,? super P> procedure,
P parameter)
The procedure2 is evaluated for each element in the iterable with the specified parameter provided
as the second argument.
|
void |
forEachWithIndex(ObjectIntProcedure<? super V> objectIntProcedure)
Iterates over the iterable passing each element and the current relative int index to the specified instance of
ObjectIntProcedure
|
V |
get(Object key) |
int |
getBatchCount(int batchSize) |
int |
getCollidingBuckets() |
V |
getIfAbsentPut(K key,
Function0<? extends V> function)
Get and return the value in the Map at the specified key.
|
V |
getIfAbsentPut(K key,
V value)
Get and return the value in the Map at the specified key.
|
<P> V |
getIfAbsentPutWith(K key,
Function<? super P,? extends V> function,
P parameter)
Get and return the value in the Map at the specified key.
|
int |
getMapMemoryUsedInWords()
Returns the number of JVM words that is used by this map.
|
int |
hashCode()
Follows the same general contract as
Map.hashCode(). |
boolean |
isEmpty()
Returns true if this iterable has zero items.
|
Set<K> |
keySet() |
MutableMap<K,V> |
newEmpty()
Creates a new instance of the same type, using the default capacity and growth parameters.
|
MutableMap<K,V> |
newEmpty(int capacity)
Creates a new instance of the same type, using the given capacity and the default growth parameters.
|
static <K,V> UnifiedMap<K,V> |
newMap() |
static <K,V> UnifiedMap<K,V> |
newMap(int size) |
static <K,V> UnifiedMap<K,V> |
newMap(int size,
float loadFactor) |
static <K,V> UnifiedMap<K,V> |
newMap(Map<? extends K,? extends V> map) |
static <K,V> UnifiedMap<K,V> |
newMapWith(Pair<K,V>... pairs) |
static <K,V> UnifiedMap<K,V> |
newWithKeysValues(K key,
V value) |
static <K,V> UnifiedMap<K,V> |
newWithKeysValues(K key1,
V value1,
K key2,
V value2) |
static <K,V> UnifiedMap<K,V> |
newWithKeysValues(K key1,
V value1,
K key2,
V value2,
K key3,
V value3) |
static <K,V> UnifiedMap<K,V> |
newWithKeysValues(K key1,
V value1,
K key2,
V value2,
K key3,
V value3,
K key4,
V value4) |
V |
put(K key,
V value) |
void |
putAll(Map<? extends K,? extends V> map) |
void |
readExternal(ObjectInput in) |
V |
remove(Object key) |
V |
removeKey(K key)
Remove an entry from the map at the specified
key. |
int |
size()
Returns the number of items in this iterable.
|
ImmutableMap<K,V> |
toImmutable()
Returns an immutable copy of this map.
|
String |
toString()
Returns a string representation of this MapIterable.
|
V |
updateValue(K key,
Function0<? extends V> factory,
Function<? super V,? extends V> function)
Looks up the value associated with
key, applies the function to it, and replaces the value. |
<P> V |
updateValueWith(K key,
Function0<? extends V> factory,
Function2<? super V,? super P,? extends V> function,
P parameter)
Same as
MutableMap.updateValue(Object, Function0, Function) with a Function2 and specified parameter which is
passed to the function. |
Collection<V> |
values() |
UnifiedMap<K,V> |
withKeysValues(K key,
V value) |
UnifiedMap<K,V> |
withKeysValues(K key1,
V value1,
K key2,
V value2) |
UnifiedMap<K,V> |
withKeysValues(K key1,
V value1,
K key2,
V value2,
K key3,
V value3) |
UnifiedMap<K,V> |
withKeysValues(K key1,
V value1,
K key2,
V value2,
K key3,
V value3,
K key4,
V value4) |
void |
writeExternal(ObjectOutput out) |
add, aggregateBy, aggregateInPlaceBy, asSynchronized, asUnmodifiable, collect, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectValues, collectWith, detect, flatCollect, flip, flipUniqueValues, getIfAbsentPutWithKey, groupBy, groupByEach, groupByUniqueKey, iterator, keysView, keyValuesView, partition, partitionWith, reject, reject, select, select, selectInstancesOf, selectWith, valuesView, withAllKeyValueArguments, withAllKeyValues, withKeyValue, withoutAllKeys, withoutKey, zip, zipWithIndexallSatisfy, allSatisfyWith, anySatisfy, anySatisfyWith, appendString, appendString, appendString, asLazy, chunk, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, contains, containsAll, containsAllArguments, containsAllIterable, count, countWith, detect, detectIfNone, detectWith, detectWithIfNone, flatCollect, forEach, getFirst, getIfAbsent, getIfAbsentValue, getIfAbsentWith, getLast, groupBy, groupByEach, ifPresentApply, injectInto, injectInto, injectInto, injectInto, injectInto, makeString, makeString, makeString, max, max, maxBy, min, min, minBy, noneSatisfy, noneSatisfyWith, notEmpty, reject, rejectWith, rejectWith, select, selectWith, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toArray, toArray, toBag, toList, toMap, toSet, toSortedList, toSortedList, toSortedListBy, toSortedMap, toSortedMap, toSortedSet, toSortedSet, toSortedSetBy, zip, zipWithIndexforEachgetIfAbsent, getIfAbsentValue, getIfAbsentWith, ifPresentApplyallSatisfy, allSatisfyWith, anySatisfy, anySatisfyWith, appendString, appendString, appendString, asLazy, chunk, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, contains, containsAll, containsAllArguments, containsAllIterable, count, countWith, detect, detectIfNone, detectWith, detectWithIfNone, flatCollect, getFirst, getLast, groupBy, groupByEach, injectInto, injectInto, injectInto, injectInto, injectInto, makeString, makeString, makeString, max, max, maxBy, min, min, minBy, noneSatisfy, noneSatisfyWith, notEmpty, reject, rejectWith, rejectWith, select, selectWith, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toArray, toArray, toBag, toList, toMap, toSet, toSortedList, toSortedList, toSortedListBy, toSortedMap, toSortedMap, toSortedSet, toSortedSet, toSortedSetBy, zip, zipWithIndexforEachforEach, spliteratorcompute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAllpublic UnifiedMap()
public UnifiedMap(int initialCapacity)
public UnifiedMap(int initialCapacity,
float loadFactor)
public static <K,V> UnifiedMap<K,V> newMap()
public static <K,V> UnifiedMap<K,V> newMap(int size)
public static <K,V> UnifiedMap<K,V> newMap(int size, float loadFactor)
public static <K,V> UnifiedMap<K,V> newMap(Map<? extends K,? extends V> map)
public static <K,V> UnifiedMap<K,V> newMapWith(Pair<K,V>... pairs)
public static <K,V> UnifiedMap<K,V> newWithKeysValues(K key, V value)
public static <K,V> UnifiedMap<K,V> newWithKeysValues(K key1, V value1, K key2, V value2)
public static <K,V> UnifiedMap<K,V> newWithKeysValues(K key1, V value1, K key2, V value2, K key3, V value3)
public static <K,V> UnifiedMap<K,V> newWithKeysValues(K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4)
public UnifiedMap<K,V> withKeysValues(K key, V value)
public UnifiedMap<K,V> withKeysValues(K key1, V value1, K key2, V value2, K key3, V value3)
public UnifiedMap<K,V> withKeysValues(K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4)
public UnifiedMap<K,V> clone()
AbstractMutableMapThis implementation creates an empty string buffer, appends a left brace, and iterates over the map's entrySet view, appending the string representation of each map.entry in turn. After appending each entry except the last, the string ", " is appended. Finally a right brace is appended. A string is obtained from the stringbuffer, and returned.
clone in interface MutableMap<K,V>clone in class AbstractMutableMap<K,V>public MutableMap<K,V> newEmpty()
MutableMapnewEmpty in interface MutableMap<K,V>public MutableMap<K,V> newEmpty(int capacity)
AbstractMutableMapnewEmpty in class AbstractMutableMap<K,V>public V updateValue(K key, Function0<? extends V> factory, Function<? super V,? extends V> function)
MutableMapkey, applies the function to it, and replaces the value. If there
is no value associated with key, starts it off with a value supplied by factory.updateValue in interface MutableMap<K,V>updateValue in class AbstractMutableMap<K,V>public <P> V updateValueWith(K key, Function0<? extends V> factory, Function2<? super V,? super P,? extends V> function, P parameter)
MutableMapMutableMap.updateValue(Object, Function0, Function) with a Function2 and specified parameter which is
passed to the function.updateValueWith in interface MutableMap<K,V>updateValueWith in class AbstractMutableMap<K,V>public V getIfAbsentPut(K key, Function0<? extends V> function)
MutableMapgetIfAbsentPut in interface MutableMap<K,V>getIfAbsentPut in class AbstractMutableMap<K,V>public V getIfAbsentPut(K key, V value)
MutableMapgetIfAbsentPut in interface MutableMap<K,V>getIfAbsentPut in class AbstractMutableMap<K,V>public <P> V getIfAbsentPutWith(K key, Function<? super P,? extends V> function, P parameter)
MutableMapgetIfAbsentPutWith in interface MutableMap<K,V>getIfAbsentPutWith in class AbstractMutableMap<K,V>public int getCollidingBuckets()
public int getMapMemoryUsedInWords()
public V get(Object key)
get in interface MapIterable<K,V>get in interface Map<K,V>Map.get(Object)public boolean containsKey(Object key)
containsKey in interface MapIterable<K,V>containsKey in interface Map<K,V>Map.containsKey(Object)public boolean containsValue(Object value)
containsValue in interface MapIterable<K,V>containsValue in interface Map<K,V>Map.containsValue(Object)public void forEachKeyValue(Procedure2<? super K,? super V> procedure)
MapIterableprocedure with each key-value pair of the map.
final Collection<String> collection = new ArrayList<String>();
MutableMap<Integer, String> map = this.newMapWithKeysValues(1, "One", 2, "Two", 3, "Three");
map.forEachKeyValue(new Procedure2<Integer, String>()
{
public void value(final Integer key, final String value)
{
collection.add(String.valueOf(key) + value);
}
});
Verify.assertContainsAll(collection, "1One", "2Two", "3Three");
forEachKeyValue in interface MapIterable<K,V>public <E> MutableMap<K,V> collectKeysAndValues(Iterable<E> iterable, Function<? super E,? extends K> keyFunction, Function<? super E,? extends V> valueFunction)
MutableMapcollection to this. The key and value for each entry
is determined by applying the keyFunction and valueFunction to each item in
collection. Any entry in map that has the same key as an entry in this
will have it's value replaced by that in map.collectKeysAndValues in interface MutableMap<K,V>public V removeKey(K key)
MutableMapkey.removeKey in interface MutableMap<K,V>Map.remove(Object)public int getBatchCount(int batchSize)
getBatchCount in interface BatchIterable<V>public void batchForEach(Procedure<? super V> procedure, int sectionIndex, int sectionCount)
batchForEach in interface BatchIterable<V>public void forEachKey(Procedure<? super K> procedure)
MapIterableprocedure with each key of the map.
final Collection<Integer> result = new ArrayList<Integer>();
MutableMap<Integer, String> map = this.newMapWithKeysValues(1, "1", 2, "2", 3, "3");
map.forEachKey(new CollectionAddProcedure<Integer>(result));
Verify.assertContainsAll(result, 1, 2, 3);
forEachKey in interface MapIterable<K,V>forEachKey in class AbstractMapIterable<K,V>public void forEachValue(Procedure<? super V> procedure)
MapIterable
Set<String> result = UnifiedSet.newSet();
MutableMap<Integer, String> map = this.newMapWithKeysValues(1, "One", 2, "Two", 3, "Three", 4, "Four");
map.forEachValue(new CollectionAddProcedure<String>(result));
Verify.assertSetsEqual(UnifiedSet.newSetWith("One", "Two", "Three", "Four"), result);
forEachValue in interface MapIterable<K,V>forEachValue in class AbstractMapIterable<K,V>public boolean isEmpty()
RichIterablepublic int size()
RichIterablesize in interface RichIterable<V>size in interface BatchIterable<V>size in interface Map<K,V>public boolean equals(Object object)
MapIterableMap.equals(Object).public int hashCode()
MapIterableMap.hashCode().public String toString()
MapIterableString.valueOf(Object).toString in interface MapIterable<K,V>toString in interface RichIterable<V>toString in class Objectpublic void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
readExternal in interface ExternalizableIOExceptionClassNotFoundExceptionpublic void writeExternal(ObjectOutput out) throws IOException
writeExternal in interface ExternalizableIOExceptionpublic void forEachWithIndex(ObjectIntProcedure<? super V> objectIntProcedure)
InternalIterablee.g. people.forEachWithIndex(new ObjectIntProcedure() { public void value(Person person, int index) { LOGGER.info("Index: " + index + " person: " + person.getName()); } });
forEachWithIndex in interface InternalIterable<V>forEachWithIndex in class AbstractMapIterable<K,V>public <P> void forEachWith(Procedure2<? super V,? super P> procedure, P parameter)
InternalIterablee.g. people.forEachWith(new Procedure2() { public void value(Person person, Person other) { if (person.isRelatedTo(other)) { LOGGER.info(person.getName()); } } }, fred);
forEachWith in interface InternalIterable<V>forEachWith in class AbstractMapIterable<K,V>public ImmutableMap<K,V> toImmutable()
MutableMaptoImmutable in interface MutableMap<K,V>toImmutable in interface UnsortedMapIterable<K,V>toImmutable in class AbstractMutableMap<K,V>Copyright © 2004–2017. All rights reserved.