java.io.Externalizable
, java.io.Serializable
, java.lang.Cloneable
, java.lang.Iterable<K>
, java.util.Map<K,V>
, InternalIterable<K>
, MapIterable<K,V>
, MutableMap<K,V>
, MutableMapIterable<K,V>
, UnsortedMapIterable<K,V>
, RichIterable<K>
, BatchIterable<V>
public class UnifiedMapWithHashingStrategy<K,V> extends AbstractMutableMap<K,V> implements java.io.Externalizable, BatchIterable<V>
The difference between UnifiedMap and UnifiedMapWithHashingStrategy is that a HashingStrategy based UnifiedMap does not rely on the hashCode or equality of the object at the key, but instead relies on a HashingStrategy implementation provided by a developer to compute the hashCode and equals for the objects stored in the map.
Constructor | Description |
---|---|
UnifiedMapWithHashingStrategy() |
Deprecated.
No argument default constructor used for serialization. Instantiating an UnifiedMapWithHashingStrategyMultimap with
this constructor will have a null hashingStrategy and throw NullPointerException when used.
|
UnifiedMapWithHashingStrategy(HashingStrategy<? super K> hashingStrategy) |
|
UnifiedMapWithHashingStrategy(HashingStrategy<? super K> hashingStrategy,
int initialCapacity) |
|
UnifiedMapWithHashingStrategy(HashingStrategy<? super K> hashingStrategy,
int initialCapacity,
float loadFactor) |
|
UnifiedMapWithHashingStrategy(HashingStrategy<? super K> hashingStrategy,
java.util.Map<? extends K,? extends V> map) |
|
UnifiedMapWithHashingStrategy(HashingStrategy<? super K> hashingStrategy,
Pair<K,V>... pairs) |
Modifier and Type | Method | Description |
---|---|---|
void |
batchForEach(Procedure<? super V> procedure,
int sectionIndex,
int sectionCount) |
|
void |
clear() |
|
UnifiedMapWithHashingStrategy<K,V> |
clone() |
|
<E> MutableMap<K,V> |
collectKeysAndValues(java.lang.Iterable<E> iterable,
Function<? super E,? extends K> keyFunction,
Function<? super E,? extends V> valueFunction) |
Adds all the entries derived from
iterable to this . |
<R> MutableMap<K,R> |
collectValues(Function2<? super K,? super V,? extends R> function) |
For each key and value of the map the function is evaluated.
|
boolean |
containsKey(java.lang.Object key) |
|
boolean |
containsValue(java.lang.Object value) |
|
java.util.Set<java.util.Map.Entry<K,V>> |
entrySet() |
|
boolean |
equals(java.lang.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(java.lang.Object key) |
|
int |
getBatchCount(int batchSize) |
|
int |
getCollidingBuckets() |
|
V |
getFirst() |
Returns the first element of an iterable.
|
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() . |
HashingStrategy<? super K> |
hashingStrategy() |
|
boolean |
isEmpty() |
Returns true if this iterable has zero items.
|
java.util.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> UnifiedMapWithHashingStrategy<K,V> |
newMap(HashingStrategy<? super K> hashingStrategy) |
|
static <K,V> UnifiedMapWithHashingStrategy<K,V> |
newMap(HashingStrategy<? super K> hashingStrategy,
int size) |
|
static <K,V> UnifiedMapWithHashingStrategy<K,V> |
newMap(HashingStrategy<? super K> hashingStrategy,
int size,
float loadFactor) |
|
static <K,V> UnifiedMapWithHashingStrategy<K,V> |
newMap(HashingStrategy<? super K> hashingStrategy,
java.util.Map<? extends K,? extends V> map) |
|
static <K,V> UnifiedMapWithHashingStrategy<K,V> |
newMap(UnifiedMapWithHashingStrategy<K,V> map) |
|
static <K,V> UnifiedMapWithHashingStrategy<K,V> |
newMapWith(HashingStrategy<? super K> hashingStrategy,
java.lang.Iterable<Pair<K,V>> inputIterable) |
|
static <K,V> UnifiedMapWithHashingStrategy<K,V> |
newMapWith(HashingStrategy<? super K> hashingStrategy,
Pair<K,V>... pairs) |
|
static <K,V> UnifiedMapWithHashingStrategy<K,V> |
newWithKeysValues(HashingStrategy<? super K> hashingStrategy,
K key,
V value) |
|
static <K,V> UnifiedMapWithHashingStrategy<K,V> |
newWithKeysValues(HashingStrategy<? super K> hashingStrategy,
K key1,
V value1,
K key2,
V value2) |
|
static <K,V> UnifiedMapWithHashingStrategy<K,V> |
newWithKeysValues(HashingStrategy<? super K> hashingStrategy,
K key1,
V value1,
K key2,
V value2,
K key3,
V value3) |
|
static <K,V> UnifiedMapWithHashingStrategy<K,V> |
newWithKeysValues(HashingStrategy<? super K> hashingStrategy,
K key1,
V value1,
K key2,
V value2,
K key3,
V value3,
K key4,
V value4) |
|
V |
put(K key,
V value) |
|
void |
putAll(java.util.Map<? extends K,? extends V> map) |
|
void |
readExternal(java.io.ObjectInput in) |
|
V |
remove(java.lang.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.
|
java.lang.String |
toString() |
Returns a string with the elements of the iterable separated by commas with spaces and
enclosed in square brackets.
|
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
MutableMapIterable.updateValue(Object, Function0, Function) with a Function2 and specified parameter which is
passed to the function. |
java.util.Collection<V> |
values() |
|
UnifiedMapWithHashingStrategy<K,V> |
withKeysValues(K key,
V value) |
|
UnifiedMapWithHashingStrategy<K,V> |
withKeysValues(K key1,
V value1,
K key2,
V value2) |
|
UnifiedMapWithHashingStrategy<K,V> |
withKeysValues(K key1,
V value1,
K key2,
V value2,
K key3,
V value3) |
|
UnifiedMapWithHashingStrategy<K,V> |
withKeysValues(K key1,
V value1,
K key2,
V value2,
K key3,
V value3,
K key4,
V value4) |
|
void |
writeExternal(java.io.ObjectOutput out) |
allSatisfy, allSatisfyWith, anySatisfy, anySatisfyWith, asLazy, chunk, contains, detect, detectIfNone, detectOptional, detectWith, detectWithIfNone, detectWithOptional, each, getIfAbsent, getIfAbsentValue, getIfAbsentWith, getLast, getOnly, ifPresentApply, noneSatisfy, noneSatisfyWith, toArray, toArray
asSynchronized, asUnmodifiable, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, flatCollect, flip, groupBy, groupByEach, groupByUniqueKey, partition, partitionWith, reject, reject, rejectWith, select, select, selectInstancesOf, selectWith, tap, withAllKeyValueArguments, withAllKeyValues, withKeyValue, withoutAllKeys, withoutKey, zip, zipWithIndex
aggregateBy, aggregateInPlaceBy, collect, countBy, countByWith, detect, detectOptional, flipUniqueValues, getIfAbsentPutWithKey, iterator, keysView, keyValuesView, sumByDouble, sumByFloat, sumByInt, sumByLong, valuesView
appendString, appendString, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, containsAll, containsAllArguments, containsAllIterable, count, countWith, flatCollect, forEach, groupBy, groupByEach, groupByUniqueKey, injectInto, injectInto, injectInto, injectInto, injectInto, into, max, max, maxBy, min, min, minBy, reject, rejectWith, select, selectWith, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toBag, toList, toMap, toSet, toSortedBag, toSortedBag, toSortedBagBy, toSortedListBy, toSortedMap, toSortedMap, toSortedSet, toSortedSet, toSortedSetBy, zip, zipWithIndex
forEach
forEach, forEach
compute, computeIfAbsent, computeIfPresent, entry, forEach, getOrDefault, merge, of, of, of, of, of, of, of, of, of, of, of, ofEntries, putIfAbsent, remove, replace, replace, replaceAll
detect, detectOptional, getIfAbsent, getIfAbsentValue, getIfAbsentWith, ifPresentApply, keysView, keyValuesView, parallelStream, spliterator, stream, valuesView
aggregateBy, aggregateInPlaceBy, collect, flipUniqueValues
add, countBy, countByWith, getIfAbsentPutWithKey, sumByDouble, sumByFloat, sumByInt, sumByLong
allSatisfy, allSatisfyWith, anySatisfy, anySatisfyWith, appendString, appendString, appendString, asLazy, chunk, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, contains, containsAll, containsAllArguments, containsAllIterable, count, countBy, countByWith, countWith, detect, detectIfNone, detectOptional, detectWith, detectWithIfNone, detectWithOptional, each, flatCollect, getLast, getOnly, groupBy, groupByEach, groupByUniqueKey, injectInto, injectInto, injectInto, injectInto, injectInto, into, makeString, makeString, makeString, max, max, maxBy, maxByOptional, maxOptional, maxOptional, min, min, minBy, minByOptional, minOptional, minOptional, noneSatisfy, noneSatisfyWith, notEmpty, reduce, reduceInPlace, reduceInPlace, reject, rejectWith, select, selectWith, summarizeDouble, summarizeFloat, summarizeInt, summarizeLong, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toArray, toArray, toBag, toList, toMap, toSet, toSortedBag, toSortedBag, toSortedBagBy, toSortedList, toSortedList, toSortedListBy, toSortedMap, toSortedMap, toSortedSet, toSortedSet, toSortedSetBy, zip, zipWithIndex
@Deprecated public UnifiedMapWithHashingStrategy()
public UnifiedMapWithHashingStrategy(HashingStrategy<? super K> hashingStrategy)
public UnifiedMapWithHashingStrategy(HashingStrategy<? super K> hashingStrategy, int initialCapacity)
public UnifiedMapWithHashingStrategy(HashingStrategy<? super K> hashingStrategy, int initialCapacity, float loadFactor)
public UnifiedMapWithHashingStrategy(HashingStrategy<? super K> hashingStrategy, java.util.Map<? extends K,? extends V> map)
public UnifiedMapWithHashingStrategy(HashingStrategy<? super K> hashingStrategy, Pair<K,V>... pairs)
public static <K,V> UnifiedMapWithHashingStrategy<K,V> newMap(HashingStrategy<? super K> hashingStrategy)
public static <K,V> UnifiedMapWithHashingStrategy<K,V> newMap(HashingStrategy<? super K> hashingStrategy, int size)
public static <K,V> UnifiedMapWithHashingStrategy<K,V> newMap(HashingStrategy<? super K> hashingStrategy, int size, float loadFactor)
public static <K,V> UnifiedMapWithHashingStrategy<K,V> newMap(HashingStrategy<? super K> hashingStrategy, java.util.Map<? extends K,? extends V> map)
public static <K,V> UnifiedMapWithHashingStrategy<K,V> newMapWith(HashingStrategy<? super K> hashingStrategy, java.lang.Iterable<Pair<K,V>> inputIterable)
public static <K,V> UnifiedMapWithHashingStrategy<K,V> newMap(UnifiedMapWithHashingStrategy<K,V> map)
public static <K,V> UnifiedMapWithHashingStrategy<K,V> newMapWith(HashingStrategy<? super K> hashingStrategy, Pair<K,V>... pairs)
public static <K,V> UnifiedMapWithHashingStrategy<K,V> newWithKeysValues(HashingStrategy<? super K> hashingStrategy, K key, V value)
public static <K,V> UnifiedMapWithHashingStrategy<K,V> newWithKeysValues(HashingStrategy<? super K> hashingStrategy, K key1, V value1, K key2, V value2)
public static <K,V> UnifiedMapWithHashingStrategy<K,V> newWithKeysValues(HashingStrategy<? super K> hashingStrategy, K key1, V value1, K key2, V value2, K key3, V value3)
public static <K,V> UnifiedMapWithHashingStrategy<K,V> newWithKeysValues(HashingStrategy<? super K> hashingStrategy, K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4)
public UnifiedMapWithHashingStrategy<K,V> withKeysValues(K key, V value)
public UnifiedMapWithHashingStrategy<K,V> withKeysValues(K key1, V value1, K key2, V value2)
public UnifiedMapWithHashingStrategy<K,V> withKeysValues(K key1, V value1, K key2, V value2, K key3, V value3)
public UnifiedMapWithHashingStrategy<K,V> withKeysValues(K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4)
public HashingStrategy<? super K> hashingStrategy()
public UnifiedMapWithHashingStrategy<K,V> clone()
clone
in interface MutableMap<K,V>
clone
in class AbstractMutableMap<K,V>
public MutableMap<K,V> newEmpty()
MutableMapIterable
newEmpty
in interface MutableMap<K,V>
newEmpty
in interface MutableMapIterable<K,V>
public MutableMap<K,V> newEmpty(int capacity)
AbstractMutableMap
newEmpty
in class AbstractMutableMap<K,V>
public V updateValue(K key, Function0<? extends V> factory, Function<? super V,? extends V> function)
MutableMapIterable
key
, 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 MutableMapIterable<K,V>
updateValue
in class AbstractMutableMapIterable<K,V>
public <P> V updateValueWith(K key, Function0<? extends V> factory, Function2<? super V,? super P,? extends V> function, P parameter)
MutableMapIterable
MutableMapIterable.updateValue(Object, Function0, Function)
with a Function2 and specified parameter which is
passed to the function.updateValueWith
in interface MutableMapIterable<K,V>
updateValueWith
in class AbstractMutableMapIterable<K,V>
public V getIfAbsentPut(K key, Function0<? extends V> function)
MutableMapIterable
getIfAbsentPut
in interface MutableMapIterable<K,V>
getIfAbsentPut
in class AbstractMutableMapIterable<K,V>
public V getIfAbsentPut(K key, V value)
MutableMapIterable
getIfAbsentPut
in interface MutableMapIterable<K,V>
getIfAbsentPut
in class AbstractMutableMapIterable<K,V>
public <P> V getIfAbsentPutWith(K key, Function<? super P,? extends V> function, P parameter)
MutableMapIterable
getIfAbsentPutWith
in interface MutableMapIterable<K,V>
getIfAbsentPutWith
in class AbstractMutableMapIterable<K,V>
public int getCollidingBuckets()
public int getMapMemoryUsedInWords()
public V get(java.lang.Object key)
public boolean containsKey(java.lang.Object key)
containsKey
in interface java.util.Map<K,V>
containsKey
in interface MapIterable<K,V>
Map.containsKey(Object)
public boolean containsValue(java.lang.Object value)
containsValue
in interface java.util.Map<K,V>
containsValue
in interface MapIterable<K,V>
Map.containsValue(Object)
public void forEachKeyValue(Procedure2<? super K,? super V> procedure)
MapIterable
procedure
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((Integer key, String value) -> collection.add(String.valueOf(key) + value)); Verify.assertContainsAll(collection, "1One", "2Two", "3Three");
forEachKeyValue
in interface MapIterable<K,V>
public V getFirst()
RichIterable
The order of Sets are not guaranteed (except for TreeSets and other Ordered Set implementations), so if you use this method, the first element could be any element from the Set.
getFirst
in interface RichIterable<K>
getFirst
in class AbstractMapIterable<K,V>
public <E> MutableMap<K,V> collectKeysAndValues(java.lang.Iterable<E> iterable, Function<? super E,? extends K> keyFunction, Function<? super E,? extends V> valueFunction)
MutableMap
iterable
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 its value replaced by that in map
.collectKeysAndValues
in interface MutableMap<K,V>
public V removeKey(K key)
MutableMapIterable
key
.removeKey
in interface MutableMapIterable<K,V>
Map.remove(Object)
public int getBatchCount(int batchSize)
getBatchCount
in interface BatchIterable<K>
public void batchForEach(Procedure<? super V> procedure, int sectionIndex, int sectionCount)
batchForEach
in interface BatchIterable<K>
public void forEachKey(Procedure<? super K> procedure)
MapIterable
procedure
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()
RichIterable
isEmpty
in interface java.util.Map<K,V>
isEmpty
in interface RichIterable<K>
isEmpty
in class AbstractRichIterable<V>
public int size()
RichIterable
size
in interface BatchIterable<K>
size
in interface java.util.Map<K,V>
size
in interface RichIterable<K>
public java.util.Collection<V> values()
public boolean equals(java.lang.Object object)
MapIterable
Map.equals(Object)
.public int hashCode()
MapIterable
Map.hashCode()
.public java.lang.String toString()
AbstractRichIterable
Assert.assertEquals("[]", Lists.mutable.empty().toString()); Assert.assertEquals("[1]", Lists.mutable.with(1).toString()); Assert.assertEquals("[1, 2, 3]", Lists.mutable.with(1, 2, 3).toString());
toString
in interface MapIterable<K,V>
toString
in interface RichIterable<K>
toString
in class AbstractRichIterable<V>
AbstractCollection.toString()
public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException
readExternal
in interface java.io.Externalizable
java.io.IOException
java.lang.ClassNotFoundException
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException
writeExternal
in interface java.io.Externalizable
java.io.IOException
public void forEachWithIndex(ObjectIntProcedure<? super V> objectIntProcedure)
InternalIterable
Example using a Java 8 lambda:
people.forEachWithIndex((Person person, int index) -> LOGGER.info("Index: " + index + " person: " + person.getName()));
Example using an anonymous inner class:
people.forEachWithIndex(new ObjectIntProcedure<Person>() { public void value(Person person, int index) { LOGGER.info("Index: " + index + " person: " + person.getName()); } });
forEachWithIndex
in interface InternalIterable<K>
forEachWithIndex
in class AbstractMapIterable<K,V>
public <P> void forEachWith(Procedure2<? super V,? super P> procedure, P parameter)
InternalIterable
Example using a Java 8 lambda:
people.forEachWith((Person person, Person other) -> { if (person.isRelatedTo(other)) { LOGGER.info(person.getName()); } }, fred);
Example using an anonymous inner class:
people.forEachWith(new Procedure2<Person, Person>() { public void value(Person person, Person other) { if (person.isRelatedTo(other)) { LOGGER.info(person.getName()); } } }, fred);
forEachWith
in interface InternalIterable<K>
forEachWith
in class AbstractMapIterable<K,V>
public <R> MutableMap<K,R> collectValues(Function2<? super K,? super V,? extends R> function)
MapIterable
MapIterable<City, String> collected = peopleByCity.collectValues((City city, Person person) -> person.getFirstName() + " " + person.getLastName());
collectValues
in interface MapIterable<K,V>
collectValues
in interface MutableMap<K,V>
collectValues
in interface MutableMapIterable<K,V>
collectValues
in interface UnsortedMapIterable<K,V>
collectValues
in class AbstractMutableMap<K,V>
public ImmutableMap<K,V> toImmutable()
MutableMapIterable
toImmutable
in interface MapIterable<K,V>
toImmutable
in interface MutableMapIterable<K,V>
toImmutable
in interface UnsortedMapIterable<K,V>
toImmutable
in class AbstractMutableMap<K,V>
Copyright © 2004–2017. All rights reserved.