Class UnifiedMap<K,V>
- java.lang.Object
-
- org.eclipse.collections.impl.AbstractRichIterable<V>
-
- org.eclipse.collections.impl.map.AbstractMapIterable<K,V>
-
- org.eclipse.collections.impl.map.mutable.AbstractMutableMapIterable<K,V>
-
- org.eclipse.collections.impl.map.mutable.AbstractMutableMap<K,V>
-
- org.eclipse.collections.impl.map.mutable.UnifiedMap<K,V>
-
- All Implemented Interfaces:
java.io.Externalizable,java.io.Serializable,java.lang.Cloneable,java.lang.Iterable<V>,java.util.Map<K,V>,InternalIterable<V>,MapIterable<K,V>,MutableMap<K,V>,MutableMapIterable<K,V>,UnsortedMapIterable<K,V>,RichIterable<V>,BatchIterable<V>
public class UnifiedMap<K,V> extends AbstractMutableMap<K,V> implements java.io.Externalizable, BatchIterable<V>
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.
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classUnifiedMap.EntrySetprotected classUnifiedMap.EntrySetIteratorprotected classUnifiedMap.KeySetprotected classUnifiedMap.KeySetIteratorprotected classUnifiedMap.PositionalIterator<T>protected classUnifiedMap.ValuesCollectionprotected classUnifiedMap.ValuesIteratorprotected static classUnifiedMap.WeakBoundEntry<K,V>-
Nested classes/interfaces inherited from class org.eclipse.collections.impl.map.mutable.AbstractMutableMap
AbstractMutableMap.ValuesCollectionCommon<V>
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.ObjectCHAINED_KEYprotected static intDEFAULT_INITIAL_CAPACITYprotected static floatDEFAULT_LOAD_FACTORprotected floatloadFactorprotected intmaxSizeprotected static java.lang.ObjectNULL_KEYprotected intoccupiedprivate static longserialVersionUIDprotected java.lang.Object[]table
-
Constructor Summary
Constructors Constructor Description UnifiedMap()UnifiedMap(int initialCapacity)UnifiedMap(int initialCapacity, float loadFactor)UnifiedMap(java.util.Map<? extends K,? extends V> map)UnifiedMap(Pair<K,V>... pairs)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected intallocate(int capacity)protected voidallocateTable(int sizeToAllocate)booleanallSatisfy(Predicate<? super V> predicate)Returns true if the predicate evaluates to true for every element of the iterable or if the iterable is empty.<P> booleanallSatisfyWith(Predicate2<? super V,? super P> predicate, P parameter)Returns true if the predicate evaluates to true for every element of the collection, or returns false.booleananySatisfy(Predicate<? super V> predicate)Returns true if the predicate evaluates to true for any element of the iterable.<P> booleananySatisfyWith(Predicate2<? super V,? super P> predicate, P parameter)Returns true if the predicate evaluates to true for any element of the collection, or return false.voidbatchForEach(Procedure<? super V> procedure, int sectionIndex, int sectionCount)private booleanchainContainsKey(java.lang.Object[] chain, K key)private booleanchainedContainsValue(java.lang.Object[] chain, V value)private booleanchainedEquals(java.lang.Object[] chain, java.util.Map<?,?> other)private voidchainedForEachEntry(java.lang.Object[] chain, Procedure2<? super K,? super V> procedure)private voidchainedForEachKey(java.lang.Object[] chain, Procedure<? super K> procedure)private voidchainedForEachValue(java.lang.Object[] chain, Procedure<? super V> procedure)private <P> voidchainedForEachValueWith(java.lang.Object[] chain, Procedure2<? super V,? super P> procedure, P parameter)private intchainedForEachValueWithIndex(java.lang.Object[] chain, ObjectIntProcedure<? super V> objectIntProcedure, int index)private VchainedGetIfAbsentPut(K key, int index, Function0<? extends V> function)private VchainedGetIfAbsentPut(K key, int index, V value)private <P> VchainedGetIfAbsentPutWith(K key, int index, Function<? super P,? extends V> function, P parameter)private intchainedHashCode(java.lang.Object[] chain)private VchainedMerge(K key, int index, V value, java.util.function.BiFunction<? super V,? super V,? extends V> remappingFunction)private VchainedPut(K key, int index, V value)private voidchainedPutForTrim(K key, int index, V value)private VchainedUpdateValue(K key, int index, Function0<? extends V> factory, Function<? super V,? extends V> function)private <P> VchainedUpdateValueWith(K key, int index, Function0<? extends V> factory, Function2<? super V,? super P,? extends V> function, P parameter)voidclear()UnifiedMap<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 fromiterabletothis.<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.protected voidcomputeMaxSize(int capacity)booleancontainsKey(java.lang.Object key)booleancontainsValue(java.lang.Object value)private voidcopyChain(java.lang.Object[] chain)protected voidcopyMap(UnifiedMap<K,V> unifiedMap)Vdetect(Predicate<? super V> predicate)Returns the first element of the iterable for which the predicate evaluates to true or null in the case where no element returns true.Pair<K,V>detect(Predicate2<? super K,? super V> predicate)Return the first key and value of the map for which the predicate evaluates to true when they are given as arguments.VdetectIfNone(Predicate<? super V> predicate, Function0<? extends V> function)Returns the first element of the iterable for which the predicate evaluates to true.java.util.Optional<V>detectOptional(Predicate<? super V> predicate)Returns the first element of the iterable for which the predicate evaluates to true as an Optional.java.util.Optional<Pair<K,V>>detectOptional(Predicate2<? super K,? super V> predicate)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.<P> VdetectWith(Predicate2<? super V,? super P> predicate, P parameter)Returns the first element that evaluates to true for the specified predicate2 and parameter, or null if none evaluate to true.<P> VdetectWithIfNone(Predicate2<? super V,? super P> predicate, P parameter, Function0<? extends V> function)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.<P> java.util.Optional<V>detectWithOptional(Predicate2<? super V,? super P> predicate, P parameter)Returns the first element that evaluates to true for the specified predicate2 and parameter as an Optional.java.util.Set<java.util.Map.Entry<K,V>>entrySet()booleanequals(java.lang.Object object)Follows the same general contract asMap.equals(Object).private intfastCeil(float v)voidforEachKey(Procedure<? super K> procedure)Calls theprocedurewith each key of the map.voidforEachKeyValue(Procedure2<? super K,? super V> procedure)Calls theprocedurewith each key-value pair of the map.voidforEachValue(Procedure<? super V> procedure)Calls the procedure with each value of the map.<P> voidforEachWith(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.voidforEachWithIndex(ObjectIntProcedure<? super V> objectIntProcedure)Iterates over the iterable passing each element and the current relative int index to the specified instance of ObjectIntProcedure.Vget(java.lang.Object key)intgetBatchCount(int batchSize)intgetCollidingBuckets()private java.util.Set<? extends java.util.Map.Entry<? extends K,? extends V>>getEntrySetFrom(java.util.Map<? extends K,? extends V> map)VgetFirst()Returns the first element of an iterable.private VgetFromChain(java.lang.Object[] chain, K key)VgetIfAbsentPut(K key, Function0<? extends V> function)Get and return the value in the Map at the specified key.VgetIfAbsentPut(K key, V value)Get and return the value in the Map at the specified key.<P> VgetIfAbsentPutWith(K key, Function<? super P,? extends V> function, P parameter)Get and return the value in the Map at the specified key.intgetMapMemoryUsedInWords()Returns the number of JVM words that is used by this map.inthashCode()Follows the same general contract asMap.hashCode().protected intindex(java.lang.Object key)protected intinit(int initialCapacity)booleanisEmpty()Returns true if this iterable has zero items.java.util.Set<K>keySet()Vmerge(K key, V value, java.util.function.BiFunction<? super V,? super V,? extends V> remappingFunction)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(java.util.Map<? extends K,? extends V> map)static <K,V>
UnifiedMap<K,V>newMapWith(java.lang.Iterable<Pair<K,V>> inputIterable)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)booleannoneSatisfy(Predicate<? super V> predicate)Returns true if the predicate evaluates to false for every element of the iterable or if the iterable is empty.<P> booleannoneSatisfyWith(Predicate2<? super V,? super P> predicate, P parameter)Returns true if the predicate evaluates to false for every element of the collection, or return false.private booleannonNullTableObjectEquals(java.lang.Object cur, K key)private KnonSentinel(java.lang.Object key)private static booleannullSafeEquals(java.lang.Object value, java.lang.Object other)private voidoverwriteWithLastElementFromChain(java.lang.Object[] chain, int index, int i)Vput(K key, V value)voidputAll(java.util.Map<? extends K,? extends V> map)private voidputForTrim(K key, V value, int oldIndex, int mask)voidreadExternal(java.io.ObjectInput in)protected voidrehash(int newCapacity)Vremove(java.lang.Object key)private VremoveFromChain(java.lang.Object[] chain, K key, int index)booleanremoveIf(Predicate2<? super K,? super V> predicate)Remove an entry from the map if thepredicateevaluates to true.VremoveKey(K key)Remove an entry from the map at the specifiedkey.private booleanshortCircuit(Predicate<? super V> predicate, boolean expected, boolean onShortCircuit, boolean atEnd)private <P> booleanshortCircuitWith(Predicate2<? super V,? super P> predicate, P parameter, boolean expected, boolean onShortCircuit, boolean atEnd)intsize()Returns the number of items in this iterable.private static java.lang.ObjecttoSentinelIfNull(java.lang.Object key)java.lang.StringtoString()Returns a string with the elements of the iterable separated by commas with spaces and enclosed in square brackets.booleantrimToSize()VupdateValue(K key, Function0<? extends V> factory, Function<? super V,? extends V> function)Looks up the value associated withkey, applies thefunctionto it, and replaces the value.<P> VupdateValueWith(K key, Function0<? extends V> factory, Function2<? super V,? super P,? extends V> function, P parameter)Same asMutableMapIterable.updateValue(Object, Function0, Function)with a Function2 and specified parameter which is passed to the function.java.util.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)voidwriteExternal(java.io.ObjectOutput out)private voidwriteExternalChain(java.io.ObjectOutput out, java.lang.Object[] chain)-
Methods inherited from class org.eclipse.collections.impl.map.mutable.AbstractMutableMap
asSynchronized, asUnmodifiable, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectKeysUnique, collectLong, collectShort, collectWith, flatCollect, flip, groupBy, groupByEach, groupByUniqueKey, partition, partitionWith, reject, reject, rejectWith, replaceAll, select, select, selectInstancesOf, selectWith, tap, toImmutable, withAllKeyValueArguments, withAllKeyValues, withKeyValue, withoutAllKeys, withoutKey, zip, zipWithIndex
-
Methods inherited from class org.eclipse.collections.impl.map.mutable.AbstractMutableMapIterable
aggregateBy, collect, countBy, countByEach, countByWith, flipUniqueValues, getIfAbsentPutWithKey, iterator, keysView, keyValuesView, reduceBy, sumByDouble, sumByFloat, sumByInt, sumByLong, valuesView
-
Methods inherited from class org.eclipse.collections.impl.map.AbstractMapIterable
asLazy, chunk, contains, each, getIfAbsent, getIfAbsentValue, getIfAbsentWith, getLast, getOnly, getOrDefault, ifPresentApply, isAbsent, keyAndValueEquals, keyAndValueHashCode, toArray, toArray
-
Methods inherited from class org.eclipse.collections.impl.AbstractRichIterable
appendString, appendString, collect, collectIf, 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, toBiMap, toList, toMap, toSet, toSortedBag, toSortedBag, toSortedBagBy, toSortedListBy, toSortedMap, toSortedMap, toSortedMapBy, toSortedSet, toSortedSet, toSortedSetBy, zip, zipWithIndex
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.eclipse.collections.impl.parallel.BatchIterable
forEach
-
Methods inherited from interface org.eclipse.collections.api.InternalIterable
forEach
-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, putIfAbsent, remove, replace, replace
-
Methods inherited from interface org.eclipse.collections.api.map.MapIterable
getIfAbsent, getIfAbsentValue, getIfAbsentWith, ifPresentApply, injectIntoKeyValue, keysView, keyValuesView, parallelStream, spliterator, stream, valuesView
-
Methods inherited from interface org.eclipse.collections.api.map.MutableMap
aggregateBy, aggregateBy, aggregateInPlaceBy, collect, flatCollectWith, flipUniqueValues, reduceBy, withMap, withMapIterable
-
Methods inherited from interface org.eclipse.collections.api.map.MutableMapIterable
add, countBy, countByEach, countByWith, forEach, getIfAbsentPutWithKey, getOrDefault, putAllMapIterable, putPair, removeAllKeys, sumByDouble, sumByFloat, sumByInt, sumByLong
-
Methods inherited from interface org.eclipse.collections.api.RichIterable
aggregateBy, appendString, appendString, appendString, asLazy, chunk, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, contains, containsAll, containsAllArguments, containsAllIterable, containsAny, containsAnyIterable, containsBy, containsNone, containsNoneIterable, count, countBy, countByEach, countByWith, countWith, each, flatCollect, flatCollectBoolean, flatCollectByte, flatCollectChar, flatCollectDouble, flatCollectFloat, flatCollectInt, flatCollectLong, flatCollectShort, flatCollectWith, forEach, getAny, getLast, getOnly, groupBy, groupByAndCollect, groupByEach, groupByUniqueKey, injectInto, injectInto, injectInto, injectInto, injectInto, injectIntoDouble, injectIntoFloat, injectIntoInt, injectIntoLong, into, makeString, makeString, makeString, makeString, max, max, maxBy, maxByOptional, maxOptional, maxOptional, min, min, minBy, minByOptional, minOptional, minOptional, notEmpty, reduce, reduceBy, reduceInPlace, reduceInPlace, reject, rejectWith, select, selectWith, summarizeDouble, summarizeFloat, summarizeInt, summarizeLong, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toArray, toArray, toBag, toBiMap, toImmutableBag, toImmutableBiMap, toImmutableList, toImmutableMap, toImmutableSet, toImmutableSortedBag, toImmutableSortedBag, toImmutableSortedBagBy, toImmutableSortedList, toImmutableSortedList, toImmutableSortedListBy, toImmutableSortedSet, toImmutableSortedSet, toImmutableSortedSetBy, toList, toMap, toMap, toSet, toSortedBag, toSortedBag, toSortedBagBy, toSortedList, toSortedList, toSortedListBy, toSortedMap, toSortedMap, toSortedMapBy, toSortedSet, toSortedSet, toSortedSetBy, zip, zipWithIndex
-
-
-
-
Field Detail
-
NULL_KEY
protected static final java.lang.Object NULL_KEY
-
CHAINED_KEY
protected static final java.lang.Object CHAINED_KEY
-
DEFAULT_LOAD_FACTOR
protected static final float DEFAULT_LOAD_FACTOR
- See Also:
- Constant Field Values
-
DEFAULT_INITIAL_CAPACITY
protected static final int DEFAULT_INITIAL_CAPACITY
- See Also:
- Constant Field Values
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
table
protected transient java.lang.Object[] table
-
occupied
protected transient int occupied
-
loadFactor
protected float loadFactor
-
maxSize
protected int maxSize
-
-
Method Detail
-
newMap
public static <K,V> UnifiedMap<K,V> newMap()
-
newMap
public static <K,V> UnifiedMap<K,V> newMap(int size)
-
newMap
public static <K,V> UnifiedMap<K,V> newMap(int size, float loadFactor)
-
newMap
public static <K,V> UnifiedMap<K,V> newMap(java.util.Map<? extends K,? extends V> map)
-
newMapWith
public static <K,V> UnifiedMap<K,V> newMapWith(Pair<K,V>... pairs)
-
newMapWith
public static <K,V> UnifiedMap<K,V> newMapWith(java.lang.Iterable<Pair<K,V>> inputIterable)
-
newWithKeysValues
public static <K,V> UnifiedMap<K,V> newWithKeysValues(K key, V value)
-
newWithKeysValues
public static <K,V> UnifiedMap<K,V> newWithKeysValues(K key1, V value1, K key2, V value2)
-
newWithKeysValues
public static <K,V> UnifiedMap<K,V> newWithKeysValues(K key1, V value1, K key2, V value2, K key3, V value3)
-
newWithKeysValues
public static <K,V> UnifiedMap<K,V> newWithKeysValues(K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4)
-
withKeysValues
public UnifiedMap<K,V> withKeysValues(K key, V value)
-
withKeysValues
public UnifiedMap<K,V> withKeysValues(K key1, V value1, K key2, V value2, K key3, V value3)
-
withKeysValues
public UnifiedMap<K,V> withKeysValues(K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4)
-
clone
public UnifiedMap<K,V> clone()
- Specified by:
clonein interfaceMutableMap<K,V>- Specified by:
clonein classAbstractMutableMap<K,V>
-
newEmpty
public MutableMap<K,V> newEmpty()
Description copied from interface:MutableMapIterableCreates a new instance of the same type, using the default capacity and growth parameters.- Specified by:
newEmptyin interfaceMutableMap<K,V>- Specified by:
newEmptyin interfaceMutableMapIterable<K,V>
-
newEmpty
public MutableMap<K,V> newEmpty(int capacity)
Description copied from class:AbstractMutableMapCreates a new instance of the same type, using the given capacity and the default growth parameters.- Specified by:
newEmptyin classAbstractMutableMap<K,V>
-
fastCeil
private int fastCeil(float v)
-
init
protected int init(int initialCapacity)
-
allocate
protected int allocate(int capacity)
-
allocateTable
protected void allocateTable(int sizeToAllocate)
-
computeMaxSize
protected void computeMaxSize(int capacity)
-
index
protected int index(java.lang.Object key)
-
updateValue
public V updateValue(K key, Function0<? extends V> factory, Function<? super V,? extends V> function)
Description copied from interface:MutableMapIterableLooks up the value associated withkey, applies thefunctionto it, and replaces the value. If there is no value associated withkey, starts it off with a value supplied byfactory.- Specified by:
updateValuein interfaceMutableMapIterable<K,V>- Overrides:
updateValuein classAbstractMutableMapIterable<K,V>
-
chainedUpdateValue
private V chainedUpdateValue(K key, int index, Function0<? extends V> factory, Function<? super V,? extends V> function)
-
updateValueWith
public <P> V updateValueWith(K key, Function0<? extends V> factory, Function2<? super V,? super P,? extends V> function, P parameter)
Description copied from interface:MutableMapIterableSame asMutableMapIterable.updateValue(Object, Function0, Function)with a Function2 and specified parameter which is passed to the function.- Specified by:
updateValueWithin interfaceMutableMapIterable<K,V>- Overrides:
updateValueWithin classAbstractMutableMapIterable<K,V>
-
chainedUpdateValueWith
private <P> V chainedUpdateValueWith(K key, int index, Function0<? extends V> factory, Function2<? super V,? super P,? extends V> function, P parameter)
-
merge
public V merge(K key, V value, java.util.function.BiFunction<? super V,? super V,? extends V> remappingFunction)
-
chainedMerge
private V chainedMerge(K key, int index, V value, java.util.function.BiFunction<? super V,? super V,? extends V> remappingFunction)
-
getIfAbsentPut
public V getIfAbsentPut(K key, Function0<? extends V> function)
Description copied from interface:MutableMapIterableGet and return the value in the Map at the specified key. Alternatively, if there is no value in the map at the key, return the result of evaluating the specified Function0, and put that value in the map at the specified key.- Specified by:
getIfAbsentPutin interfaceMutableMapIterable<K,V>- Overrides:
getIfAbsentPutin classAbstractMutableMapIterable<K,V>
-
chainedGetIfAbsentPut
private V chainedGetIfAbsentPut(K key, int index, Function0<? extends V> function)
-
getIfAbsentPut
public V getIfAbsentPut(K key, V value)
Description copied from interface:MutableMapIterableGet and return the value in the Map at the specified key. Alternatively, if there is no value in the map at the key, return the specified value, and put that value in the map at the specified key.- Specified by:
getIfAbsentPutin interfaceMutableMapIterable<K,V>- Overrides:
getIfAbsentPutin classAbstractMutableMapIterable<K,V>
-
getIfAbsentPutWith
public <P> V getIfAbsentPutWith(K key, Function<? super P,? extends V> function, P parameter)
Description copied from interface:MutableMapIterableGet and return the value in the Map at the specified key. Alternatively, if there is no value in the map for that key return the result of evaluating the specified Function using the specified parameter, and put that value in the map at the specified key.- Specified by:
getIfAbsentPutWithin interfaceMutableMapIterable<K,V>- Overrides:
getIfAbsentPutWithin classAbstractMutableMapIterable<K,V>
-
chainedGetIfAbsentPutWith
private <P> V chainedGetIfAbsentPutWith(K key, int index, Function<? super P,? extends V> function, P parameter)
-
getCollidingBuckets
public int getCollidingBuckets()
-
getMapMemoryUsedInWords
public int getMapMemoryUsedInWords()
Returns the number of JVM words that is used by this map. A word is 4 bytes in a 32bit VM and 8 bytes in a 64bit VM. Each array has a 2 word header, thus the formula is: words = (internal table length + 2) + sum (for all chains (chain length + 2))- Returns:
- the number of JVM words that is used by this map.
-
rehash
protected void rehash(int newCapacity)
-
get
public V get(java.lang.Object key)
-
containsKey
public boolean containsKey(java.lang.Object key)
- Specified by:
containsKeyin interfacejava.util.Map<K,V>- Specified by:
containsKeyin interfaceMapIterable<K,V>- See Also:
Map.containsKey(Object)
-
chainContainsKey
private boolean chainContainsKey(java.lang.Object[] chain, K key)
-
containsValue
public boolean containsValue(java.lang.Object value)
- Specified by:
containsValuein interfacejava.util.Map<K,V>- Specified by:
containsValuein interfaceMapIterable<K,V>- See Also:
Map.containsValue(Object)
-
chainedContainsValue
private boolean chainedContainsValue(java.lang.Object[] chain, V value)
-
forEachKeyValue
public void forEachKeyValue(Procedure2<? super K,? super V> procedure)
Description copied from interface:MapIterableCalls theprocedurewith 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");- Specified by:
forEachKeyValuein interfaceMapIterable<K,V>
-
getFirst
public V getFirst()
Description copied from interface:RichIterableReturns the first element of an iterable. In the case of a List it is the element at the first index. In the case of any other Collection, it is the first element that would be returned during an iteration. If the iterable is empty, null is returned. If null is a valid element of the container, then a developer would need to check to see if the iterable is empty to validate that a null result was not due to the container being empty.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.
- Specified by:
getFirstin interfaceRichIterable<K>- Overrides:
getFirstin classAbstractMapIterable<K,V>
-
collectKeysAndValues
public <E> MutableMap<K,V> collectKeysAndValues(java.lang.Iterable<E> iterable, Function<? super E,? extends K> keyFunction, Function<? super E,? extends V> valueFunction)
Description copied from interface:MutableMapAdds all the entries derived fromiterabletothis. The key and value for each entry is determined by applying thekeyFunctionandvalueFunctionto each item incollection. Any entry inmapthat has the same key as an entry inthiswill have its value replaced by that inmap.- Specified by:
collectKeysAndValuesin interfaceMutableMap<K,V>
-
removeKey
public V removeKey(K key)
Description copied from interface:MutableMapIterableRemove an entry from the map at the specifiedkey.- Specified by:
removeKeyin interfaceMutableMapIterable<K,V>- Returns:
- The value removed from entry at key, or null if not found.
- See Also:
Map.remove(Object)
-
removeIf
public boolean removeIf(Predicate2<? super K,? super V> predicate)
Description copied from interface:MutableMapIterableRemove an entry from the map if thepredicateevaluates to true.- Specified by:
removeIfin interfaceMutableMapIterable<K,V>- Returns:
- true if any entry is removed.
-
chainedForEachEntry
private void chainedForEachEntry(java.lang.Object[] chain, Procedure2<? super K,? super V> procedure)
-
getBatchCount
public int getBatchCount(int batchSize)
- Specified by:
getBatchCountin interfaceBatchIterable<K>
-
batchForEach
public void batchForEach(Procedure<? super V> procedure, int sectionIndex, int sectionCount)
- Specified by:
batchForEachin interfaceBatchIterable<K>
-
forEachKey
public void forEachKey(Procedure<? super K> procedure)
Description copied from interface:MapIterableCalls theprocedurewith 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);- Specified by:
forEachKeyin interfaceMapIterable<K,V>- Overrides:
forEachKeyin classAbstractMapIterable<K,V>
-
chainedForEachKey
private void chainedForEachKey(java.lang.Object[] chain, Procedure<? super K> procedure)
-
forEachValue
public void forEachValue(Procedure<? super V> procedure)
Description copied from interface:MapIterableCalls the procedure with each value of the map.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);- Specified by:
forEachValuein interfaceMapIterable<K,V>- Overrides:
forEachValuein classAbstractMapIterable<K,V>
-
chainedForEachValue
private void chainedForEachValue(java.lang.Object[] chain, Procedure<? super V> procedure)
-
isEmpty
public boolean isEmpty()
Description copied from interface:RichIterableReturns true if this iterable has zero items.- Specified by:
isEmptyin interfacejava.util.Map<K,V>- Specified by:
isEmptyin interfaceRichIterable<K>- Overrides:
isEmptyin classAbstractRichIterable<V>
-
getEntrySetFrom
private java.util.Set<? extends java.util.Map.Entry<? extends K,? extends V>> getEntrySetFrom(java.util.Map<? extends K,? extends V> map)
-
copyMap
protected void copyMap(UnifiedMap<K,V> unifiedMap)
-
copyChain
private void copyChain(java.lang.Object[] chain)
-
overwriteWithLastElementFromChain
private void overwriteWithLastElementFromChain(java.lang.Object[] chain, int index, int i)
-
size
public int size()
Description copied from interface:RichIterableReturns the number of items in this iterable.- Specified by:
sizein interfaceBatchIterable<K>- Specified by:
sizein interfacejava.util.Map<K,V>- Specified by:
sizein interfaceRichIterable<K>
-
values
public java.util.Collection<V> values()
-
equals
public boolean equals(java.lang.Object object)
Description copied from interface:MapIterableFollows the same general contract asMap.equals(Object).
-
chainedEquals
private boolean chainedEquals(java.lang.Object[] chain, java.util.Map<?,?> other)
-
hashCode
public int hashCode()
Description copied from interface:MapIterableFollows the same general contract asMap.hashCode().
-
chainedHashCode
private int chainedHashCode(java.lang.Object[] chain)
-
toString
public java.lang.String toString()
Description copied from class:AbstractRichIterableReturns a string with the elements of the iterable separated by commas with spaces and enclosed in square brackets.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());- Specified by:
toStringin interfaceMapIterable<K,V>- Specified by:
toStringin interfaceRichIterable<K>- Overrides:
toStringin classAbstractRichIterable<V>- Returns:
- a string representation of this collection.
- See Also:
AbstractCollection.toString()
-
trimToSize
public boolean trimToSize()
-
readExternal
public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException- Specified by:
readExternalin interfacejava.io.Externalizable- Throws:
java.io.IOExceptionjava.lang.ClassNotFoundException
-
writeExternal
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException- Specified by:
writeExternalin interfacejava.io.Externalizable- Throws:
java.io.IOException
-
writeExternalChain
private void writeExternalChain(java.io.ObjectOutput out, java.lang.Object[] chain) throws java.io.IOException- Throws:
java.io.IOException
-
forEachWithIndex
public void forEachWithIndex(ObjectIntProcedure<? super V> objectIntProcedure)
Description copied from interface:InternalIterableIterates over the iterable passing each element and the current relative int index to the specified instance of ObjectIntProcedure.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()); } });- Specified by:
forEachWithIndexin interfaceInternalIterable<K>- Overrides:
forEachWithIndexin classAbstractMapIterable<K,V>
-
chainedForEachValueWithIndex
private int chainedForEachValueWithIndex(java.lang.Object[] chain, ObjectIntProcedure<? super V> objectIntProcedure, int index)
-
forEachWith
public <P> void forEachWith(Procedure2<? super V,? super P> procedure, P parameter)
Description copied from interface:InternalIterableThe procedure2 is evaluated for each element in the iterable with the specified parameter provided as the second argument.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);- Specified by:
forEachWithin interfaceInternalIterable<K>- Overrides:
forEachWithin classAbstractMapIterable<K,V>
-
chainedForEachValueWith
private <P> void chainedForEachValueWith(java.lang.Object[] chain, Procedure2<? super V,? super P> procedure, P parameter)
-
collectValues
public <R> MutableMap<K,R> collectValues(Function2<? super K,? super V,? extends R> function)
Description copied from interface:MapIterableFor each key and value of the map the function is evaluated. The results of these evaluations are returned in a new map. The map returned will use the values projected from the function rather than the original values.MapIterable<City, String> collected = peopleByCity.collectValues((City city, Person person) -> person.getFirstName() + " " + person.getLastName());- Specified by:
collectValuesin interfaceMapIterable<K,V>- Specified by:
collectValuesin interfaceMutableMap<K,V>- Specified by:
collectValuesin interfaceMutableMapIterable<K,V>- Specified by:
collectValuesin interfaceUnsortedMapIterable<K,V>- Overrides:
collectValuesin classAbstractMutableMap<K,V>
-
detect
public Pair<K,V> detect(Predicate2<? super K,? super V> predicate)
Description copied from interface:MapIterableReturn the first key and value of the map for which the predicate evaluates to true when they are given as arguments. The predicate will only be evaluated until such pair is found or until all the keys and values of the map have been used as arguments. That is, there may be keys and values of the map that are never used as arguments to the predicate. The result is null if predicate does not evaluate to true for any key/value combination.Pair<City, Person> detected = peopleByCity.detect((City city, Person person) -> city.getName().equals("Anytown") && person.getLastName().equals("Smith"));- Specified by:
detectin interfaceMapIterable<K,V>- Overrides:
detectin classAbstractMutableMapIterable<K,V>
-
detect
public V detect(Predicate<? super V> predicate)
Description copied from interface:RichIterableReturns the first element of the iterable for which the predicate evaluates to true or null in the case where no element returns true. This method is commonly called find.Example using a Java 8 lambda expression:
Person person = people.detect(person -> person.getFirstName().equals("John") && person.getLastName().equals("Smith"));- Specified by:
detectin interfaceRichIterable<K>- Overrides:
detectin classAbstractMapIterable<K,V>
-
detectWith
public <P> V detectWith(Predicate2<? super V,? super P> predicate, P parameter)
Description copied from interface:RichIterableReturns the first element that evaluates to true for the specified predicate2 and parameter, or null if none evaluate to true.Example using a Java 8 lambda expression:
Person person = people.detectWith((person, fullName) -> person.getFullName().equals(fullName), "John Smith");- Specified by:
detectWithin interfaceRichIterable<K>- Overrides:
detectWithin classAbstractMapIterable<K,V>
-
detectOptional
public java.util.Optional<Pair<K,V>> detectOptional(Predicate2<? super K,? super V> predicate)
Description copied from interface:MapIterableReturn the first key and value of the map as an Optional for which the predicate evaluates to true when they are given as arguments. The predicate will only be evaluated until such pair is found or until all the keys and values of the map have been used as arguments. That is, there may be keys and values of the map that are never used as arguments to the predicate.Optional<Pair<City, Person>> detected = peopleByCity.detectOptional((city, person) -> city.getName().equals("Anytown") && person.getLastName().equals("Smith"));- Specified by:
detectOptionalin interfaceMapIterable<K,V>- Overrides:
detectOptionalin classAbstractMutableMapIterable<K,V>
-
detectOptional
public java.util.Optional<V> detectOptional(Predicate<? super V> predicate)
Description copied from interface:RichIterableReturns the first element of the iterable for which the predicate evaluates to true as an Optional. This method is commonly called find.Example using a Java 8 lambda expression:
Person person = people.detectOptional(person -> person.getFirstName().equals("John") && person.getLastName().equals("Smith"));- Specified by:
detectOptionalin interfaceRichIterable<K>- Overrides:
detectOptionalin classAbstractMapIterable<K,V>
-
detectWithOptional
public <P> java.util.Optional<V> detectWithOptional(Predicate2<? super V,? super P> predicate, P parameter)
Description copied from interface:RichIterableReturns the first element that evaluates to true for the specified predicate2 and parameter as an Optional.Example using a Java 8 lambda expression:
Optional<Person> person = people.detectWithOptional((person, fullName) -> person.getFullName().equals(fullName), "John Smith");- Specified by:
detectWithOptionalin interfaceRichIterable<K>- Overrides:
detectWithOptionalin classAbstractMapIterable<K,V>
-
detectIfNone
public V detectIfNone(Predicate<? super V> predicate, Function0<? extends V> function)
Description copied from interface:RichIterableReturns the first element of the iterable for which the predicate evaluates to true. If no element matches the predicate, then returns the value of applying the specified function.- Specified by:
detectIfNonein interfaceRichIterable<K>- Overrides:
detectIfNonein classAbstractMapIterable<K,V>
-
detectWithIfNone
public <P> V detectWithIfNone(Predicate2<? super V,? super P> predicate, P parameter, Function0<? extends V> function)
Description copied from interface:RichIterableReturns 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.- Specified by:
detectWithIfNonein interfaceRichIterable<K>- Overrides:
detectWithIfNonein classAbstractMapIterable<K,V>
-
shortCircuit
private boolean shortCircuit(Predicate<? super V> predicate, boolean expected, boolean onShortCircuit, boolean atEnd)
-
shortCircuitWith
private <P> boolean shortCircuitWith(Predicate2<? super V,? super P> predicate, P parameter, boolean expected, boolean onShortCircuit, boolean atEnd)
-
anySatisfy
public boolean anySatisfy(Predicate<? super V> predicate)
Description copied from interface:RichIterableReturns true if the predicate evaluates to true for any element of the iterable. Returns false if the iterable is empty, or if no element returned true when evaluating the predicate.- Specified by:
anySatisfyin interfaceRichIterable<K>- Overrides:
anySatisfyin classAbstractMapIterable<K,V>
-
anySatisfyWith
public <P> boolean anySatisfyWith(Predicate2<? super V,? super P> predicate, P parameter)
Description copied from interface:RichIterableReturns true if the predicate evaluates to true for any element of the collection, or return false. Returns false if the collection is empty.- Specified by:
anySatisfyWithin interfaceRichIterable<K>- Overrides:
anySatisfyWithin classAbstractMapIterable<K,V>
-
allSatisfy
public boolean allSatisfy(Predicate<? super V> predicate)
Description copied from interface:RichIterableReturns true if the predicate evaluates to true for every element of the iterable or if the iterable is empty. Otherwise, returns false.- Specified by:
allSatisfyin interfaceRichIterable<K>- Overrides:
allSatisfyin classAbstractMapIterable<K,V>
-
allSatisfyWith
public <P> boolean allSatisfyWith(Predicate2<? super V,? super P> predicate, P parameter)
Description copied from interface:RichIterableReturns true if the predicate evaluates to true for every element of the collection, or returns false.- Specified by:
allSatisfyWithin interfaceRichIterable<K>- Overrides:
allSatisfyWithin classAbstractMapIterable<K,V>
-
noneSatisfy
public boolean noneSatisfy(Predicate<? super V> predicate)
Description copied from interface:RichIterableReturns true if the predicate evaluates to false for every element of the iterable or if the iterable is empty. Otherwise, returns false.- Specified by:
noneSatisfyin interfaceRichIterable<K>- Overrides:
noneSatisfyin classAbstractMapIterable<K,V>
-
noneSatisfyWith
public <P> boolean noneSatisfyWith(Predicate2<? super V,? super P> predicate, P parameter)
Description copied from interface:RichIterableReturns true if the predicate evaluates to false for every element of the collection, or return false. Returns true if the collection is empty.- Specified by:
noneSatisfyWithin interfaceRichIterable<K>- Overrides:
noneSatisfyWithin classAbstractMapIterable<K,V>
-
nullSafeEquals
private static boolean nullSafeEquals(java.lang.Object value, java.lang.Object other)
-
nonSentinel
private K nonSentinel(java.lang.Object key)
-
toSentinelIfNull
private static java.lang.Object toSentinelIfNull(java.lang.Object key)
-
nonNullTableObjectEquals
private boolean nonNullTableObjectEquals(java.lang.Object cur, K key)
-
-