Top Description Inners Fields Constructors Methods
org.eclipse.collections.impl.map.mutable

public Class UnifiedMap<K, V>

extends AbstractMutableMap<K, V>
implements Externalizable, BatchIterable<V>
Class Inheritance
All Implemented Interfaces
org.eclipse.collections.impl.parallel.BatchIterable, java.io.Externalizable, java.io.Serializable
Annotations
@SuppressWarnings:ObjectEquality
Imports
java.io.Externalizable, .IOException, .ObjectInput, .ObjectInputStream, .ObjectOutput, .Serializable, java.lang.ref.WeakReference, java.lang.reflect.Array, java.util.Collection, .Iterator, .Map, .NoSuchElementException, .Objects, .Optional, .Set, java.util.function.BiFunction, .Consumer, org.eclipse.collections.api.block.function.Function, .Function0, .Function2, org.eclipse.collections.api.block.predicate.Predicate, .Predicate2, org.eclipse.collections.api.block.procedure.Procedure, .Procedure2, org.eclipse.collections.api.block.procedure.primitive.ObjectIntProcedure, org.eclipse.collections.api.factory.Sets, org.eclipse.collections.api.list.MutableList, org.eclipse.collections.api.map.MapIterable, .MutableMap, .UnsortedMapIterable, org.eclipse.collections.api.set.MutableSet, org.eclipse.collections.api.tuple.Pair, org.eclipse.collections.impl.block.factory.Functions, .Predicates, org.eclipse.collections.impl.block.procedure.AppendStringProcedure, .MapCollectProcedure, org.eclipse.collections.impl.list.mutable.FastList, org.eclipse.collections.impl.parallel.BatchIterable, org.eclipse.collections.impl.set.mutable.UnifiedSet, org.eclipse.collections.impl.tuple.ImmutableEntry, .Tuples, org.eclipse.collections.impl.utility.ArrayIterate, .Iterate

UnifiedMap stores key/value pairs in a single array, where alternate slots are keys and values. This is nicer to CPU caches as consecutive memory addresses are very cheap to access. Entry objects are not stored in the table like in java.util.HashMap. Instead of trying to deal with collisions in the main array using Entry objects, we put a special object in the key slot and put a regular Object[] in the value slot. The array contains the key value pairs in consecutive slots, just like the main array, but it's a linear list with no hashing.

The final result is a Map implementation that's leaner than java.util.HashMap and faster than Trove's THashMap. The best of both approaches unified together, and thus the name UnifiedMap.

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected class
protected class
protected class
protected class
protected abstract class
protected class
protected class
protected static class

Field Summary

Modifier and TypeField and Description
protected static final Object
protected static final int
protected static final float
protected float
protected int
protected static final Object
protected transient int
private static final long
protected transient Object[]

Constructor Summary

AccessConstructor and Description
public
public
UnifiedMap(int initialCapacity)

public
UnifiedMap(int initialCapacity, float loadFactor)

public
UnifiedMap(Map<? extends K, ? extends V> map)

public
UnifiedMap(Pair<K, V>... pairs)

Method Summary

Modifier and TypeMethod and Description
protected int
allocate(int capacity)

protected void
allocateTable(int sizeToAllocate)

public boolean
allSatisfy(Predicate<? super V> predicate)

Overrides org.eclipse.collections.impl.map.AbstractMapIterable.allSatisfy.

Implements org.eclipse.collections.api.RichIterable.allSatisfy.

Returns true if the predicate evaluates to true for every element of the iterable or if the iterable is empty.

public <P> boolean
allSatisfyWith(Predicate2<? super V, ? super P> predicate, P parameter)

Overrides org.eclipse.collections.impl.map.AbstractMapIterable.allSatisfyWith.

Implements org.eclipse.collections.api.RichIterable.allSatisfyWith.

Returns true if the predicate evaluates to true for every element of the collection, or returns false.

public boolean
anySatisfy(Predicate<? super V> predicate)

Overrides org.eclipse.collections.impl.map.AbstractMapIterable.anySatisfy.

Implements org.eclipse.collections.api.RichIterable.anySatisfy.

Returns true if the predicate evaluates to true for any element of the iterable.

public <P> boolean
anySatisfyWith(Predicate2<? super V, ? super P> predicate, P parameter)

Overrides org.eclipse.collections.impl.map.AbstractMapIterable.anySatisfyWith.

Implements org.eclipse.collections.api.RichIterable.anySatisfyWith.

Returns true if the predicate evaluates to true for any element of the collection, or return false.

public void
batchForEach(Procedure<? super V> procedure, int sectionIndex, int sectionCount)

Implements org.eclipse.collections.impl.parallel.BatchIterable.batchForEach.

private boolean
chainContainsKey(Object[] chain, K key)

private boolean
chainedContainsValue(Object[] chain, V value)

private boolean
chainedEquals(Object[] chain, Map<?, ?> other)

private void
chainedForEachEntry(Object[] chain, Procedure2<? super K, ? super V> procedure)

private void
chainedForEachKey(Object[] chain, Procedure<? super K> procedure)

private void
chainedForEachValue(Object[] chain, Procedure<? super V> procedure)

private <P> void
chainedForEachValueWith(Object[] chain, Procedure2<? super V, ? super P> procedure, P parameter)

private int
chainedForEachValueWithIndex(Object[] chain, ObjectIntProcedure<? super V> objectIntProcedure, int index)

private V
chainedGetIfAbsentPut(K key, int index, Function0<? extends V> function)

private V
chainedGetIfAbsentPut(K key, int index, V value)

private <P> V
chainedGetIfAbsentPutWith(K key, int index, Function<? super P, ? extends V> function, P parameter)

private int
private V
chainedMerge(K key, int index, V value, BiFunction<? super V, ? super V, ? extends V> remappingFunction)

private V
chainedPut(K key, int index, V value)

private void
chainedPutForTrim(K key, int index, V value)

private V
chainedUpdateValue(K key, int index, Function0<? extends V> factory, Function<? super V, ? extends V> function)

private <P> V
chainedUpdateValueWith(K key, int index, Function0<? extends V> factory, Function2<? super V, ? super P, ? extends V> function, P parameter)

public void
clear()

Implements java.util.Map.clear.

Removes all of the mappings from this map (optional operation).

public UnifiedMap<K, V>
clone()

Implements abstract org.eclipse.collections.impl.map.mutable.AbstractMutableMap.clone.

Implements org.eclipse.collections.api.map.MutableMap.clone.

Creates and returns a copy of this object.

public <E> MutableMap<K, V>
collectKeysAndValues(Iterable<E> iterable, Function<? super E, ? extends K> keyFunction, Function<? super E, ? extends V> valueFunction)

Implements org.eclipse.collections.api.map.MutableMap.collectKeysAndValues.

Adds all the entries derived from iterable to this.

public <R> MutableMap<K, R>
protected void
computeMaxSize(int capacity)

public boolean
containsKey(Object key)

Implements org.eclipse.collections.api.map.MapIterable.containsKey, java.util.Map.containsKey.

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

public boolean
containsValue(Object value)

Implements org.eclipse.collections.api.map.MapIterable.containsValue, java.util.Map.containsValue.

Returns true if this map maps one or more keys to the specified value.

private void
copyChain(Object[] chain)

protected void
copyMap(UnifiedMap<K, V> unifiedMap)

public Pair<K, V>
detect(Predicate2<? super K, ? super V> predicate)

Overrides org.eclipse.collections.impl.map.mutable.AbstractMutableMapIterable.detect.

Implements org.eclipse.collections.api.map.MapIterable.detect.

Return the first key and value of the map for which the predicate evaluates to true when they are given as arguments.

public V
detect(Predicate<? super V> predicate)

Overrides org.eclipse.collections.impl.map.AbstractMapIterable.detect.

Implements org.eclipse.collections.api.RichIterable.detect.

Returns the first element of the iterable for which the predicate evaluates to true or null in the case where no element returns true.

public V
detectIfNone(Predicate<? super V> predicate, Function0<? extends V> function)

Overrides org.eclipse.collections.impl.map.AbstractMapIterable.detectIfNone.

Overrides default org.eclipse.collections.api.RichIterable.detectIfNone.

Returns the first element of the iterable for which the predicate evaluates to true.

public Optional<Pair<K, V>>
detectOptional(Predicate2<? super K, ? super V> predicate)

Overrides org.eclipse.collections.impl.map.mutable.AbstractMutableMapIterable.detectOptional.

Implements org.eclipse.collections.api.map.MapIterable.detectOptional.

Return the first key and value of the map as an Optional for which the predicate evaluates to true when they are given as arguments.

public Optional<V>
detectOptional(Predicate<? super V> predicate)

Overrides org.eclipse.collections.impl.map.AbstractMapIterable.detectOptional.

Implements org.eclipse.collections.api.RichIterable.detectOptional.

Returns the first element of the iterable for which the predicate evaluates to true as an Optional.

public <P> V
detectWith(Predicate2<? super V, ? super P> predicate, P parameter)

Overrides org.eclipse.collections.impl.map.AbstractMapIterable.detectWith.

Implements org.eclipse.collections.api.RichIterable.detectWith.

Returns the first element that evaluates to true for the specified predicate2 and parameter, or null if none evaluate to true.

public <P> V
detectWithIfNone(Predicate2<? super V, ? super P> predicate, P parameter, Function0<? extends V> function)

Overrides org.eclipse.collections.impl.map.AbstractMapIterable.detectWithIfNone.

Implements org.eclipse.collections.api.RichIterable.detectWithIfNone.

Returns the first element of the iterable that evaluates to true for the specified predicate2 and parameter, or returns the value of evaluating the specified function.

public <P> Optional<V>
detectWithOptional(Predicate2<? super V, ? super P> predicate, P parameter)

Overrides org.eclipse.collections.impl.map.AbstractMapIterable.detectWithOptional.

Implements org.eclipse.collections.api.RichIterable.detectWithOptional.

Returns the first element that evaluates to true for the specified predicate2 and parameter as an Optional.

public Set<Map.Entry<K, V>>
entrySet()

Implements java.util.Map.entrySet.

Returns a Set view of the mappings contained in this map.

public boolean
private int
fastCeil(float v)

public void
forEachKey(Procedure<? super K> procedure)

Overrides org.eclipse.collections.impl.map.AbstractMapIterable.forEachKey.

Implements org.eclipse.collections.api.map.MapIterable.forEachKey.

Calls the procedure with each key of the map.

public void
forEachKeyValue(Procedure2<? super K, ? super V> procedure)

Implements org.eclipse.collections.api.map.MapIterable.forEachKeyValue.

Calls the procedure with each key-value pair of the map.

public void
forEachValue(Procedure<? super V> procedure)

Overrides org.eclipse.collections.impl.map.AbstractMapIterable.forEachValue.

Implements org.eclipse.collections.api.map.MapIterable.forEachValue.

Calls the procedure with each value of the map.

public <P> void
forEachWith(Procedure2<? super V, ? super P> procedure, P parameter)

Overrides org.eclipse.collections.impl.map.AbstractMapIterable.forEachWith.

Implements org.eclipse.collections.api.InternalIterable.forEachWith.

The procedure2 is evaluated for each element in the iterable with the specified parameter provided as the second argument.

public void
forEachWithIndex(ObjectIntProcedure<? super V> objectIntProcedure)

Overrides org.eclipse.collections.impl.map.AbstractMapIterable.forEachWithIndex.

Implements org.eclipse.collections.api.InternalIterable.forEachWithIndex.

Iterates over the iterable passing each element and the current relative int index to the specified instance of ObjectIntProcedure.

public V
get(Object key)

Implements org.eclipse.collections.api.map.MapIterable.get, 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.

public int
public int
private Set<? extends Map.Entry<? extends K, ? extends V>>
getEntrySetFrom(Map<? extends K, ? extends V> map)

public V
private V
getFromChain(Object[] chain, K key)

public V
public V
public <P> V
getIfAbsentPutWith(K key, Function<? super P, ? extends V> function, P parameter)

Overrides org.eclipse.collections.impl.map.mutable.AbstractMutableMapIterable.getIfAbsentPutWith.

Implements org.eclipse.collections.api.map.MutableMapIterable.getIfAbsentPutWith.

Get and return the value in the Map at the specified key.

public int

Returns:

the number of JVM words that is used by this map.
getMapMemoryUsedInWords
()

Returns the number of JVM words that is used by this map.

public int
protected int
protected int
init(int initialCapacity)

public boolean
public Set<K>
keySet()

Implements java.util.Map.keySet.

Returns a Set view of the keys contained in this map.

public V
merge(K key, V value, BiFunction<? super V, ? super V, ? extends V> remappingFunction)

Overrides default java.util.Map.merge.

If the specified key is not already associated with a value or is associated with null, associates it with the given non-null value (optional operation).

public MutableMap<K, V>
newEmpty()

Implements org.eclipse.collections.api.map.MutableMap.newEmpty, org.eclipse.collections.api.map.MutableMapIterable.newEmpty.

Creates a new instance of the same type, using the default capacity and growth parameters.

public MutableMap<K, V>
newEmpty(int capacity)

Implements abstract org.eclipse.collections.impl.map.mutable.AbstractMutableMap.newEmpty.

Creates a new instance of the same type, using the given capacity and the default growth parameters.

public static <K, V> UnifiedMap<K, V>
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>
newMapWith(Iterable<Pair<K, V>> inputIterable)

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 boolean
noneSatisfy(Predicate<? super V> predicate)

Overrides org.eclipse.collections.impl.map.AbstractMapIterable.noneSatisfy.

Implements org.eclipse.collections.api.RichIterable.noneSatisfy.

Returns true if the predicate evaluates to false for every element of the iterable or if the iterable is empty.

public <P> boolean
noneSatisfyWith(Predicate2<? super V, ? super P> predicate, P parameter)

Overrides org.eclipse.collections.impl.map.AbstractMapIterable.noneSatisfyWith.

Implements org.eclipse.collections.api.RichIterable.noneSatisfyWith.

Returns true if the predicate evaluates to false for every element of the collection, or return false.

private boolean
private K
private static boolean
private void
overwriteWithLastElementFromChain(Object[] chain, int index, int i)

public V
put(K key, V value)

Implements java.util.Map.put.

Associates the specified value with the specified key in this map (optional operation).

public void
putAll(Map<? extends K, ? extends V> map)

Implements java.util.Map.putAll.

Copies all of the mappings from the specified map to this map (optional operation).

private void
putForTrim(K key, V value, int oldIndex, int mask)

public void
readExternal(ObjectInput in)

Implements java.io.Externalizable.readExternal.

The object implements the readExternal method to restore its contents by calling the methods of DataInput for primitive types and readObject for objects, strings and arrays.

protected void
rehash(int newCapacity)

public V
remove(Object key)

Implements java.util.Map.remove.

Removes the mapping for a key from this map if it is present (optional operation).

private V
removeFromChain(Object[] chain, K key, int index)

public boolean
removeIf(Predicate2<? super K, ? super V> predicate)

Overrides default org.eclipse.collections.api.map.MutableMapIterable.removeIf.

Remove an entry from the map if the predicate evaluates to true.

public V
removeKey(K key)

Implements org.eclipse.collections.api.map.MutableMapIterable.removeKey.

Remove an entry from the map at the specified key.

private boolean
shortCircuit(Predicate<? super V> predicate, boolean expected, boolean onShortCircuit, boolean atEnd)

private <P> boolean
shortCircuitWith(Predicate2<? super V, ? super P> predicate, P parameter, boolean expected, boolean onShortCircuit, boolean atEnd)

public int
private static Object
public String
toString()

Overrides org.eclipse.collections.impl.AbstractRichIterable.toString.

Implements org.eclipse.collections.api.map.MapIterable.toString, org.eclipse.collections.api.RichIterable.toString.

Returns a string with the keys and values of this map separated by commas with spaces and enclosed in curly braces.

public boolean
public V
updateValue(K key, Function0<? extends V> factory, Function<? super V, ? extends V> function)

Overrides org.eclipse.collections.impl.map.mutable.AbstractMutableMapIterable.updateValue.

Implements org.eclipse.collections.api.map.MutableMapIterable.updateValue.

Looks up the value associated with key, applies the function to it, and replaces the value.

public <P> V
updateValueWith(K key, Function0<? extends V> factory, Function2<? super V, ? super P, ? extends V> function, P parameter)

Overrides org.eclipse.collections.impl.map.mutable.AbstractMutableMapIterable.updateValueWith.

Implements org.eclipse.collections.api.map.MutableMapIterable.updateValueWith.

Same as updateValue(Object, Function0, Function) with a Function2 and specified parameter which is passed to the function.

public Collection<V>
values()

Implements java.util.Map.values.

Returns a Collection view of the values contained in this map.

public UnifiedMap<K, V>
withKeysValues(K key, V value)

public UnifiedMap<K, V>
withKeysValues(K key1, V value1, K key2, V value2)

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 void
writeExternal(ObjectOutput out)

Implements java.io.Externalizable.writeExternal.

The object implements the writeExternal method to save its contents by calling the methods of DataOutput for its primitive values or calling the writeObject method of ObjectOutput for objects, strings, and arrays.

private void
Inherited from org.eclipse.collections.impl.map.mutable.AbstractMutableMap:
asSynchronizedasUnmodifiablecollectcollectBooleancollectBytecollectCharcollectDoublecollectFloatcollectIfcollectIntcollectKeysUniquecollectLongcollectShortcollectWithflatCollectflipgroupBygroupByEachgroupByUniqueKeypartitionpartitionWithrejectrejectrejectWithreplaceAllselectselectselectInstancesOfselectWithtaptoImmutablewithAllKeyValueArgumentswithAllKeyValueswithKeyValuewithoutAllKeyswithoutKeyzipzipWithIndex