Class ConcurrentHashMapUnsafe<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.ConcurrentHashMapUnsafe<K,V>
-
- All Implemented Interfaces:
java.io.Externalizable,java.io.Serializable,java.lang.Cloneable,java.lang.Iterable<V>,java.util.concurrent.ConcurrentMap<K,V>,java.util.Map<K,V>,InternalIterable<V>,ConcurrentMutableMap<K,V>,MapIterable<K,V>,MutableMap<K,V>,MutableMapIterable<K,V>,UnsortedMapIterable<K,V>,RichIterable<V>
public class ConcurrentHashMapUnsafe<K,V> extends AbstractMutableMap<K,V> implements ConcurrentMutableMap<K,V>, java.io.Externalizable
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classConcurrentHashMapUnsafe.Entry<K,V>private classConcurrentHashMapUnsafe.EntryIteratorprivate classConcurrentHashMapUnsafe.EntrySetprivate classConcurrentHashMapUnsafe.HashIterator<E>private static classConcurrentHashMapUnsafe.IteratorStateprivate classConcurrentHashMapUnsafe.KeyIteratorprivate classConcurrentHashMapUnsafe.KeySetprivate static classConcurrentHashMapUnsafe.ResizeContainerprivate classConcurrentHashMapUnsafe.ValueIteratorprivate classConcurrentHashMapUnsafe.Values-
Nested classes/interfaces inherited from class org.eclipse.collections.impl.map.mutable.AbstractMutableMap
AbstractMutableMap.ValuesCollectionCommon<V>
-
-
Field Summary
Fields Modifier and Type Field Description private static intDEFAULT_INITIAL_CAPACITYprivate static longINT_ARRAY_BASEprivate static intINT_ARRAY_SHIFTprivate static intMAXIMUM_CAPACITYThe maximum capacity, used if a higher value is implicitly specified by either of the constructors with arguments.private static longOBJECT_ARRAY_BASEprivate static intOBJECT_ARRAY_SHIFTprivate static intPARTITIONED_SIZE_THRESHOLDprivate int[]partitionedSizeprivate static java.lang.ObjectRESIZE_SENTINELprivate static java.lang.ObjectRESIZEDprivate static java.lang.ObjectRESIZINGprivate static longserialVersionUIDprivate intsizeprivate static intSIZE_BUCKETSprivate static longSIZE_OFFSETprivate java.lang.Object[]tableThe table, resized as necessary.private static java.util.concurrent.atomic.AtomicReferenceFieldUpdater<ConcurrentHashMapUnsafe,java.lang.Object[]>TABLE_UPDATERprivate static sun.misc.UnsafeUNSAFE
-
Constructor Summary
Constructors Constructor Description ConcurrentHashMapUnsafe()ConcurrentHashMapUnsafe(int initialCapacity)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddToSize(int value)private static java.lang.ObjectarrayAt(java.lang.Object[] array, int index)private static booleancasArrayAt(java.lang.Object[] array, int index, java.lang.Object expected, java.lang.Object newValue)voidclear()MutableMap<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.booleancontainsKey(java.lang.Object key)booleancontainsValue(java.lang.Object value)intcountEntries()private ConcurrentHashMapUnsafe.Entry<K,V>createReplacementChainForRemoval(ConcurrentHashMapUnsafe.Entry<K,V> original, ConcurrentHashMapUnsafe.Entry<K,V> toRemove)java.util.Set<java.util.Map.Entry<K,V>>entrySet()booleanequals(java.lang.Object o)Follows the same general contract asMap.equals(Object).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)private ConcurrentHashMapUnsafe.Entry<K,V>getEntry(java.lang.Object key)VgetIfAbsent(K key, Function0<? extends V> function)Return the value in the Map that corresponds to the specified key, or if there is no value at the key, return the result of evaluating the specified Function0.VgetIfAbsentPut(K key, Function<? super K,? extends V> factory)VgetIfAbsentPut(K key, Function0<? extends V> factory)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.<P> VgetIfAbsentWith(K key, Function<? super P,? extends V> function, P parameter)Return the value in the Map that corresponds to the specified key, or if there is no value at the key, return the result of evaluating the specified function and parameter.private static sun.misc.UnsafegetUnsafe()private inthash(java.lang.Object key)inthashCode()Follows the same general contract asMap.hashCode().private java.lang.Object[]helpWithResize(java.lang.Object[] currentArray)private java.lang.Object[]helpWithResizeWhileCurrentIndex(java.lang.Object[] currentArray, int index)<A> AifPresentApply(K key, Function<? super V,? extends A> function)If there is a value in the Map that corresponds to the specified key return the result of applying the specified Function on the value, otherwise return null.private voidincrementLocalSize(int value)private booleanincrementPartitionedSize(int value)private voidincrementSizeAndPossiblyResize(java.lang.Object[] currentArray, int length, java.lang.Object prev)private static intindexFor(int h, int length)booleanisEmpty()Returns true if this iterable has zero items.java.util.Iterator<V>iterator()java.util.Set<K>keySet()Vmerge(K key, V value, java.util.function.BiFunction<? super V,? super V,? extends V> remappingFunction)A concurrent implementation ofConcurrentMap.merge(Object, Object, BiFunction)andMap.merge(Object, Object, BiFunction).MutableMap<K,V>newEmpty()Creates a new instance of the same type, using the default capacity and growth parameters.<K,V>
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>
ConcurrentHashMapUnsafe<K,V>newMap()static <K,V>
ConcurrentHashMapUnsafe<K,V>newMap(int newSize)static <NK,NV>
ConcurrentHashMapUnsafe<NK,NV>newMap(java.util.Map<NK,NV> map)booleannotEmpty()The English equivalent of !this.isEmpty()private booleannullSafeEquals(java.lang.Object v, java.lang.Object value)voidparallelForEachKeyValue(java.util.List<Procedure2<K,V>> blocks, java.util.concurrent.Executor executor)voidparallelForEachValue(java.util.List<Procedure<V>> blocks, java.util.concurrent.Executor executor)Vput(K key, V value)voidputAll(java.util.Map<? extends K,? extends V> map)voidputAllInParallel(java.util.Map<? extends K,? extends V> map, int chunks, java.util.concurrent.Executor executor)VputIfAbsent(K key, V value)<P1,P2>
VputIfAbsentGetIfPresent(K key, Function2<? super K,? super V,? extends K> keyTransformer, Function3<P1,P2,? super K,? extends V> factory, P1 param1, P2 param2)It puts an object into the map based on the key.voidreadExternal(java.io.ObjectInput in)Vremove(java.lang.Object key)booleanremove(java.lang.Object key, java.lang.Object value)VremoveKey(K key)Remove an entry from the map at the specifiedkey.Vreplace(K key, V value)booleanreplace(K key, V oldValue, V newValue)private voidresize(java.lang.Object[] oldTable)private voidresize(java.lang.Object[] oldTable, int newSize)private voidreverseTransfer(java.lang.Object[] src, ConcurrentHashMapUnsafe.ResizeContainer resizeContainer)private voidsequentialForEachKeyValue(Procedure2<? super K,? super V> block, java.lang.Object[] currentArray, int start, int end)private voidsequentialForEachValue(Procedure<? super V> block, java.lang.Object[] currentArray, int start, int end)private voidsequentialPutAll(java.lang.Object[] currentArray, int start, int end)private static voidsetArrayAt(java.lang.Object[] array, int index, java.lang.Object newValue)intsize()Returns the number of items in this iterable.private VslowGet(java.lang.Object key, int hash, int index, java.lang.Object[] currentArray)private VslowMerge(K key, V value, java.util.function.BiFunction<? super V,? super V,? extends V> remappingFunction, int hash, java.lang.Object[] currentArray)private VslowPut(K key, V value, int hash, java.lang.Object[] currentArray)private VslowRemove(java.lang.Object key, int hash, java.lang.Object[] currentArray)private VslowReplace(K key, V value, int hash, java.lang.Object[] currentArray)private booleanslowReplace(K key, V oldValue, V newValue, int hash, java.lang.Object[] currentArray)private VslowUpdateValue(K key, Function0<? extends V> factory, Function<? super V,? extends V> function, int hash, java.lang.Object[] currentArray)private <P> VslowUpdateValueWith(K key, Function0<? extends V> factory, Function2<? super V,? super P,? extends V> function, P parameter, int hash, java.lang.Object[] currentArray)ConcurrentMutableMap<K,V>tap(Procedure<? super V> procedure)Executes the Procedure for each value of the map and returnsthis.ImmutableMap<K,V>toImmutable()Returns an immutable copy of this map.java.lang.StringtoString()Returns a string with the elements of the iterable separated by commas with spaces and enclosed in square brackets.private voidtransfer(java.lang.Object[] src, ConcurrentHashMapUnsafe.ResizeContainer resizeContainer)private voidunconditionalCopy(java.lang.Object[] dest, ConcurrentHashMapUnsafe.Entry<K,V> toCopyEntry)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()ConcurrentHashMapUnsafe<K,V>withAllKeyValueArguments(Pair<? extends K,? extends V>... keyValues)Convenience var-args version of withAllKeyValuesConcurrentHashMapUnsafe<K,V>withAllKeyValues(java.lang.Iterable<? extends Pair<? extends K,? extends V>> keyValues)This method allows mutable, fixed size, and immutable maps the ability to add elements to their existing elements.ConcurrentHashMapUnsafe<K,V>withKeyValue(K key, V value)This method allows mutable, fixed size, and immutable maps the ability to add elements to their existing elements.ConcurrentHashMapUnsafe<K,V>withoutAllKeys(java.lang.Iterable<? extends K> keys)This method allows mutable, fixed size, and immutable maps the ability to remove elements from their existing elements.ConcurrentHashMapUnsafe<K,V>withoutKey(K key)This method allows mutable, fixed size, and immutable maps the ability to remove elements from their existing elements.voidwriteExternal(java.io.ObjectOutput out)-
Methods inherited from class org.eclipse.collections.impl.map.mutable.AbstractMutableMap
asSynchronized, asUnmodifiable, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectKeysUnique, collectLong, collectShort, collectValues, collectWith, flatCollect, flip, groupBy, groupByEach, groupByUniqueKey, partition, partitionWith, reject, reject, rejectWith, replaceAll, select, select, selectInstancesOf, selectWith, zip, zipWithIndex
-
Methods inherited from class org.eclipse.collections.impl.map.mutable.AbstractMutableMapIterable
aggregateBy, collect, countBy, countByEach, countByWith, detect, detectOptional, flipUniqueValues, getIfAbsentPutWithKey, keysView, keyValuesView, reduceBy, sumByDouble, sumByFloat, sumByInt, sumByLong, valuesView
-
Methods inherited from class org.eclipse.collections.impl.map.AbstractMapIterable
allSatisfy, allSatisfyWith, anySatisfy, anySatisfyWith, asLazy, chunk, contains, detect, detectIfNone, detectOptional, detectWith, detectWithIfNone, detectWithOptional, each, getFirst, getIfAbsentValue, getLast, getOnly, getOrDefault, isAbsent, keyAndValueEquals, keyAndValueHashCode, noneSatisfy, noneSatisfyWith, 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 java.util.concurrent.ConcurrentMap
compute, computeIfAbsent, computeIfPresent, replaceAll
-
Methods inherited from interface org.eclipse.collections.api.map.ConcurrentMutableMap
forEach, getOrDefault, withMap, withMapIterable
-
Methods inherited from interface org.eclipse.collections.api.InternalIterable
forEach
-
Methods inherited from interface org.eclipse.collections.api.map.MapIterable
detect, detectOptional, getIfAbsentValue, injectIntoKeyValue, keysView, keyValuesView, parallelStream, spliterator, stream, valuesView
-
Methods inherited from interface org.eclipse.collections.api.map.MutableMap
aggregateBy, aggregateBy, aggregateInPlaceBy, asSynchronized, asUnmodifiable, collect, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectKeysUnique, collectLong, collectShort, collectValues, collectWith, flatCollect, flatCollectWith, flip, flipUniqueValues, groupBy, groupByEach, groupByUniqueKey, partition, partitionWith, reduceBy, reject, reject, rejectWith, select, select, selectInstancesOf, selectWith, zip, zipWithIndex
-
Methods inherited from interface org.eclipse.collections.api.map.MutableMapIterable
add, countBy, countByEach, countByWith, getIfAbsentPutWithKey, putAllMapIterable, putPair, removeAllKeys, removeIf, sumByDouble, sumByFloat, sumByInt, sumByLong
-
Methods inherited from interface org.eclipse.collections.api.RichIterable
aggregateBy, allSatisfy, allSatisfyWith, anySatisfy, anySatisfyWith, 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, detect, detectIfNone, detectOptional, detectWith, detectWithIfNone, detectWithOptional, each, flatCollect, flatCollectBoolean, flatCollectByte, flatCollectChar, flatCollectDouble, flatCollectFloat, flatCollectInt, flatCollectLong, flatCollectShort, flatCollectWith, forEach, getAny, getFirst, 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, noneSatisfy, noneSatisfyWith, 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
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
RESIZE_SENTINEL
private static final java.lang.Object RESIZE_SENTINEL
-
DEFAULT_INITIAL_CAPACITY
private static final int DEFAULT_INITIAL_CAPACITY
- See Also:
- Constant Field Values
-
MAXIMUM_CAPACITY
private static final int MAXIMUM_CAPACITY
The maximum capacity, used if a higher value is implicitly specified by either of the constructors with arguments. MUST be a power of two <= 1<<30.- See Also:
- Constant Field Values
-
TABLE_UPDATER
private static final java.util.concurrent.atomic.AtomicReferenceFieldUpdater<ConcurrentHashMapUnsafe,java.lang.Object[]> TABLE_UPDATER
-
RESIZED
private static final java.lang.Object RESIZED
-
RESIZING
private static final java.lang.Object RESIZING
-
PARTITIONED_SIZE_THRESHOLD
private static final int PARTITIONED_SIZE_THRESHOLD
- See Also:
- Constant Field Values
-
UNSAFE
private static final sun.misc.Unsafe UNSAFE
-
OBJECT_ARRAY_BASE
private static final long OBJECT_ARRAY_BASE
-
OBJECT_ARRAY_SHIFT
private static final int OBJECT_ARRAY_SHIFT
-
INT_ARRAY_BASE
private static final long INT_ARRAY_BASE
-
INT_ARRAY_SHIFT
private static final int INT_ARRAY_SHIFT
-
SIZE_OFFSET
private static final long SIZE_OFFSET
-
SIZE_BUCKETS
private static final int SIZE_BUCKETS
- See Also:
- Constant Field Values
-
table
private volatile java.lang.Object[] table
The table, resized as necessary. Length MUST Always be a power of two + 1.
-
partitionedSize
private int[] partitionedSize
-
size
private volatile int size
-
-
Method Detail
-
newMap
public static <K,V> ConcurrentHashMapUnsafe<K,V> newMap()
-
newMap
public static <K,V> ConcurrentHashMapUnsafe<K,V> newMap(int newSize)
-
arrayAt
private static java.lang.Object arrayAt(java.lang.Object[] array, int index)
-
casArrayAt
private static boolean casArrayAt(java.lang.Object[] array, int index, java.lang.Object expected, java.lang.Object newValue)
-
setArrayAt
private static void setArrayAt(java.lang.Object[] array, int index, java.lang.Object newValue)
-
indexFor
private static int indexFor(int h, int length)
-
incrementSizeAndPossiblyResize
private void incrementSizeAndPossiblyResize(java.lang.Object[] currentArray, int length, java.lang.Object prev)
-
hash
private int hash(java.lang.Object key)
-
helpWithResizeWhileCurrentIndex
private java.lang.Object[] helpWithResizeWhileCurrentIndex(java.lang.Object[] currentArray, int index)
-
helpWithResize
private java.lang.Object[] helpWithResize(java.lang.Object[] currentArray)
-
resize
private void resize(java.lang.Object[] oldTable)
-
resize
private void resize(java.lang.Object[] oldTable, int newSize)
-
transfer
private void transfer(java.lang.Object[] src, ConcurrentHashMapUnsafe.ResizeContainer resizeContainer)
-
reverseTransfer
private void reverseTransfer(java.lang.Object[] src, ConcurrentHashMapUnsafe.ResizeContainer resizeContainer)
-
unconditionalCopy
private void unconditionalCopy(java.lang.Object[] dest, ConcurrentHashMapUnsafe.Entry<K,V> toCopyEntry)
-
countEntries
public int countEntries()
-
getIfAbsentPut
public V getIfAbsentPut(K key, Function0<? extends V> factory)
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>
-
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>
-
putIfAbsentGetIfPresent
public <P1,P2> V putIfAbsentGetIfPresent(K key, Function2<? super K,? super V,? extends K> keyTransformer, Function3<P1,P2,? super K,? extends V> factory, P1 param1, P2 param2)
It puts an object into the map based on the key. It uses a copy of the key converted by transformer.- Parameters:
key- The "mutable" key, which has the same identity/hashcode as the inserted key, only during this callkeyTransformer- If the record is absent, the transformer will transform the "mutable" key into an immutable copy of the key. Note that the transformed key must have the same identity/hashcode as the original "mutable" key.factory- It creates an object, if it is not present in the map already.
-
remove
public boolean remove(java.lang.Object key, java.lang.Object value)
-
addToSize
private void addToSize(int value)
-
incrementPartitionedSize
private boolean incrementPartitionedSize(int value)
-
incrementLocalSize
private void incrementLocalSize(int value)
-
size
public int size()
Description copied from interface:RichIterableReturns the number of items in this iterable.- Specified by:
sizein interfacejava.util.Map<K,V>- Specified by:
sizein interfaceRichIterable<K>
-
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>
-
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)
-
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)
-
nullSafeEquals
private boolean nullSafeEquals(java.lang.Object v, java.lang.Object value)
-
get
public V get(java.lang.Object key)
-
slowGet
private V slowGet(java.lang.Object key, int hash, int index, java.lang.Object[] currentArray)
-
getEntry
private ConcurrentHashMapUnsafe.Entry<K,V> getEntry(java.lang.Object key)
-
putAllInParallel
public void putAllInParallel(java.util.Map<? extends K,? extends V> map, int chunks, java.util.concurrent.Executor executor)
-
sequentialPutAll
private void sequentialPutAll(java.lang.Object[] currentArray, int start, int end)
-
values
public java.util.Collection<V> values()
-
slowReplace
private boolean slowReplace(K key, V oldValue, V newValue, int hash, java.lang.Object[] currentArray)
-
slowRemove
private V slowRemove(java.lang.Object key, int hash, java.lang.Object[] currentArray)
-
createReplacementChainForRemoval
private ConcurrentHashMapUnsafe.Entry<K,V> createReplacementChainForRemoval(ConcurrentHashMapUnsafe.Entry<K,V> original, ConcurrentHashMapUnsafe.Entry<K,V> toRemove)
-
parallelForEachKeyValue
public void parallelForEachKeyValue(java.util.List<Procedure2<K,V>> blocks, java.util.concurrent.Executor executor)
-
sequentialForEachKeyValue
private void sequentialForEachKeyValue(Procedure2<? super K,? super V> block, java.lang.Object[] currentArray, int start, int end)
-
parallelForEachValue
public void parallelForEachValue(java.util.List<Procedure<V>> blocks, java.util.concurrent.Executor executor)
-
sequentialForEachValue
private void sequentialForEachValue(Procedure<? super V> block, java.lang.Object[] currentArray, int start, int end)
-
hashCode
public int hashCode()
Description copied from interface:MapIterableFollows the same general contract asMap.hashCode().
-
equals
public boolean equals(java.lang.Object o)
Description copied from interface:MapIterableFollows the same general contract asMap.equals(Object).
-
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()
-
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
-
newMap
public static <NK,NV> ConcurrentHashMapUnsafe<NK,NV> newMap(java.util.Map<NK,NV> map)
-
withKeyValue
public ConcurrentHashMapUnsafe<K,V> withKeyValue(K key, V value)
Description copied from interface:MutableMapIterableThis method allows mutable, fixed size, and immutable maps the ability to add elements to their existing elements. In order to support fixed size maps, a new instance of a map would have to be returned including the keys and values of the original plus the additional key and value. In the case of mutable maps, the original map is modified and then returned. In order to use this method properly with mutable and fixed size maps the following approach must be taken:map = map.withKeyValue("new key", "new value");In the case of FixedSizeMap, a new instance will be returned by withKeyValue, and any variables that previously referenced the original map will need to be redirected to reference the new instance. In the case of a FastMap or UnifiedMap, you will be replacing the reference to map with map, since FastMap and UnifiedMap will both return "this" after calling put on themselves.- Specified by:
withKeyValuein interfaceMutableMap<K,V>- Specified by:
withKeyValuein interfaceMutableMapIterable<K,V>- Overrides:
withKeyValuein classAbstractMutableMap<K,V>- See Also:
Map.put(Object, Object)
-
withAllKeyValues
public ConcurrentHashMapUnsafe<K,V> withAllKeyValues(java.lang.Iterable<? extends Pair<? extends K,? extends V>> keyValues)
Description copied from interface:MutableMapIterableThis method allows mutable, fixed size, and immutable maps the ability to add elements to their existing elements. In order to support fixed size maps, a new instance of a map would have to be returned including the keys and values of the original plus all the additional keys and values. In the case of mutable maps, the original map is modified and then returned. In order to use this method properly with mutable and fixed size maps the following approach must be taken:map = map.withAllKeyValues(FastList.newListWith(PairImpl.of("new key", "new value")));In the case of FixedSizeMap, a new instance will be returned by withAllKeyValues, and any variables that previously referenced the original map will need to be redirected to reference the new instance. In the case of a FastMap or UnifiedMap, you will be replacing the reference to map with map, since FastMap and UnifiedMap will both return "this" after calling put on themselves.- Specified by:
withAllKeyValuesin interfaceMutableMap<K,V>- Specified by:
withAllKeyValuesin interfaceMutableMapIterable<K,V>- Overrides:
withAllKeyValuesin classAbstractMutableMap<K,V>- See Also:
Map.put(Object, Object)
-
withAllKeyValueArguments
public ConcurrentHashMapUnsafe<K,V> withAllKeyValueArguments(Pair<? extends K,? extends V>... keyValues)
Description copied from interface:MutableMapIterableConvenience var-args version of withAllKeyValues- Specified by:
withAllKeyValueArgumentsin interfaceMutableMap<K,V>- Specified by:
withAllKeyValueArgumentsin interfaceMutableMapIterable<K,V>- Overrides:
withAllKeyValueArgumentsin classAbstractMutableMap<K,V>- See Also:
MutableMapIterable.withAllKeyValues(Iterable)
-
withoutKey
public ConcurrentHashMapUnsafe<K,V> withoutKey(K key)
Description copied from interface:MutableMapIterableThis method allows mutable, fixed size, and immutable maps the ability to remove elements from their existing elements. In order to support fixed size maps, a new instance of a map would have to be returned including the keys and values of the original minus the key and value to be removed. In the case of mutable maps, the original map is modified and then returned. In order to use this method properly with mutable and fixed size maps the following approach must be taken:map = map.withoutKey("key");In the case of FixedSizeMap, a new instance will be returned by withoutKey, and any variables that previously referenced the original map will need to be redirected to reference the new instance. In the case of a FastMap or UnifiedMap, you will be replacing the reference to map with map, since FastMap and UnifiedMap will both return "this" after calling remove on themselves.- Specified by:
withoutKeyin interfaceMutableMap<K,V>- Specified by:
withoutKeyin interfaceMutableMapIterable<K,V>- Overrides:
withoutKeyin classAbstractMutableMap<K,V>- See Also:
Map.remove(Object)
-
withoutAllKeys
public ConcurrentHashMapUnsafe<K,V> withoutAllKeys(java.lang.Iterable<? extends K> keys)
Description copied from interface:MutableMapIterableThis method allows mutable, fixed size, and immutable maps the ability to remove elements from their existing elements. In order to support fixed size maps, a new instance of a map would have to be returned including the keys and values of the original minus all the keys and values to be removed. In the case of mutable maps, the original map is modified and then returned. In order to use this method properly with mutable and fixed size maps the following approach must be taken:map = map.withoutAllKeys(FastList.newListWith("key1", "key2"));In the case of FixedSizeMap, a new instance will be returned by withoutAllKeys, and any variables that previously referenced the original map will need to be redirected to reference the new instance. In the case of a FastMap or UnifiedMap, you will be replacing the reference to map with map, since FastMap and UnifiedMap will both return "this" after calling remove on themselves.- Specified by:
withoutAllKeysin interfaceMutableMap<K,V>- Specified by:
withoutAllKeysin interfaceMutableMapIterable<K,V>- Overrides:
withoutAllKeysin classAbstractMutableMap<K,V>- See Also:
Map.remove(Object)
-
clone
public MutableMap<K,V> clone()
- Specified by:
clonein interfaceMutableMap<K,V>- Specified by:
clonein classAbstractMutableMap<K,V>
-
newEmpty
public <K,V> 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>
-
notEmpty
public boolean notEmpty()
Description copied from interface:RichIterableThe English equivalent of !this.isEmpty()- Specified by:
notEmptyin interfaceRichIterable<K>
-
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>
-
iterator
public java.util.Iterator<V> iterator()
- Specified by:
iteratorin interfacejava.lang.Iterable<K>- Overrides:
iteratorin classAbstractMutableMapIterable<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>
-
tap
public ConcurrentMutableMap<K,V> tap(Procedure<? super V> procedure)
Description copied from interface:MapIterableExecutes the Procedure for each value of the map and returnsthis.return peopleByCity.tap(person -> LOGGER.info(person.getName()));
- Specified by:
tapin interfaceConcurrentMutableMap<K,V>- Specified by:
tapin interfaceMapIterable<K,V>- Specified by:
tapin interfaceMutableMap<K,V>- Specified by:
tapin interfaceMutableMapIterable<K,V>- Specified by:
tapin interfaceRichIterable<K>- Specified by:
tapin interfaceUnsortedMapIterable<K,V>- Overrides:
tapin classAbstractMutableMap<K,V>- See Also:
RichIterable.forEach(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>
-
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>
-
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>
-
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)
-
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>
-
getIfAbsent
public V getIfAbsent(K key, Function0<? extends V> function)
Description copied from interface:MapIterableReturn the value in the Map that corresponds to the specified key, or if there is no value at the key, return the result of evaluating the specified Function0.- Specified by:
getIfAbsentin interfaceMapIterable<K,V>- Overrides:
getIfAbsentin classAbstractMapIterable<K,V>
-
getIfAbsentWith
public <P> V getIfAbsentWith(K key, Function<? super P,? extends V> function, P parameter)
Description copied from interface:MapIterableReturn the value in the Map that corresponds to the specified key, or if there is no value at the key, return the result of evaluating the specified function and parameter.- Specified by:
getIfAbsentWithin interfaceMapIterable<K,V>- Overrides:
getIfAbsentWithin classAbstractMapIterable<K,V>
-
ifPresentApply
public <A> A ifPresentApply(K key, Function<? super V,? extends A> function)
Description copied from interface:MapIterableIf there is a value in the Map that corresponds to the specified key return the result of applying the specified Function on the value, otherwise return null.- Specified by:
ifPresentApplyin interfaceMapIterable<K,V>- Overrides:
ifPresentApplyin classAbstractMapIterable<K,V>
-
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>
-
getUnsafe
private static sun.misc.Unsafe getUnsafe()
-
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>
-
slowUpdateValue
private V slowUpdateValue(K key, Function0<? extends V> factory, Function<? super V,? extends V> function, int hash, java.lang.Object[] currentArray)
-
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>
-
slowUpdateValueWith
private <P> V slowUpdateValueWith(K key, Function0<? extends V> factory, Function2<? super V,? super P,? extends V> function, P parameter, int hash, java.lang.Object[] currentArray)
-
merge
public V merge(K key, V value, java.util.function.BiFunction<? super V,? super V,? extends V> remappingFunction)
Description copied from interface:ConcurrentMutableMapA concurrent implementation ofConcurrentMap.merge(Object, Object, BiFunction)andMap.merge(Object, Object, BiFunction). In the implementing classes, it is possible for theremappingFunctionto be called multiple times. It is also possible for theremappingFunctionto be called one or more times, but the result is not used (because the old entry was concurrently removed).
-
slowMerge
private V slowMerge(K key, V value, java.util.function.BiFunction<? super V,? super V,? extends V> remappingFunction, int hash, java.lang.Object[] currentArray)
-
toImmutable
public ImmutableMap<K,V> toImmutable()
Description copied from interface:MutableMapIterableReturns an immutable copy of this map. If the map is immutable, it returns itself.- Specified by:
toImmutablein interfaceMapIterable<K,V>- Specified by:
toImmutablein interfaceMutableMapIterable<K,V>- Specified by:
toImmutablein interfaceUnsortedMapIterable<K,V>- Overrides:
toImmutablein classAbstractMutableMap<K,V>
-
-