org.codehaus.gpars

groovyx.gpars.extra166y
[Java] Class CustomConcurrentHashMap

java.lang.Object
  java.util.AbstractMap
      groovyx.gpars.extra166y.CustomConcurrentHashMap
All Implemented Interfaces:
java.util.concurrent.ConcurrentMap, java.io.Serializable

public class CustomConcurrentHashMap
extends java.util.AbstractMap

A java.util.ConcurrentMap supporting user-defined equivalence comparisons, soft, weak, or strong keys and values, and user-supplied computational methods for setting and updating values. In particular:

Per-map settings are established in constructors, as in the following usages (that assume static imports to simplify expression of configuration parameters):
 identityMap = new CustomConcurrentHashMap<Person,Salary>
     (STRONG, IDENTITY, STRONG, EQUALS, 0);
 weakKeyMap = new CustomConcurrentHashMap<Person,Salary>
     (WEAK, IDENTITY, STRONG, EQUALS, 0);
     .weakKeys());
 byNameMap = new CustomConcurrentHashMap<Person,Salary>
     (STRONG,
      new Equivalence<Person>() {
          public boolean equal(Person k, Object x) {
            return x instanceof Person && k.name.equals(((Person)x).name);
          
          public int hash(Object x) {
             return (x instanceof Person) ? ((Person)x).name.hashCode() : 0;
          }
        },
      STRONG, EQUALS, 0);
 }
 
The first usage above provides a replacement for java.util.IdentityHashMap, and the second a replacement for java.util.WeakHashMap, adding concurrency, asynchronous cleanup, and identity-based equality for keys. The third usage illustrates a map with a custom Equivalence that looks only at the name field of a (fictional) Person class.

This class also includes nested class KeySet that provides space-efficient Set views of maps, also supporting method intern, which may be of use in canonicalizing elements.

When used with (Weak or Soft) Reference keys and/or values, elements that have asynchronously become null are treated as absent from the map and (eventually) removed from maps via a background thread common across all maps. Because of the potential for asynchronous clearing of References, methods such as containsValue have weaker guarantees than you might expect even in the absence of other explicitly concurrent operations. For example containsValue(value) may return true even if value is no longer available upon return from the method.

When Equivalences other than equality are used, the returned collections may violate the specifications of Map and/or Set interfaces, which mandate the use of the equals method when comparing objects. The methods of this class otherwise have properties similar to those of java.util.ConcurrentHashMap under its default settings. To adaptively maintain semantics and performance under varying conditions, this class does not support load factor or concurrency level parameters. This class does not permit null keys or values. This class is serializable; however, serializing a map that uses soft or weak references can give unpredictable results. This class supports all optional operations of the ConcurrentMap interface. It supports have weakly consistent iteration: an iterator over one of the map's view collections may reflect some, all or none of the changes made to the collection after the iterator was created.

This class is a member of the Java Collections Framework.

Parameters:
- the type of keys maintained by this map
- the type of mapped values


Nested Class Summary
static class CustomConcurrentHashMap.EmbeddedSoftReference

static class CustomConcurrentHashMap.EmbeddedWeakReference

class CustomConcurrentHashMap.EntryIterator

class CustomConcurrentHashMap.EntrySet

static interface CustomConcurrentHashMap.Equivalence

An object performing equality comparisons, along with a hash function consistent with this comparison.

static class CustomConcurrentHashMap.EquivalenceUsingEquals

static class CustomConcurrentHashMap.EquivalenceUsingIdentity

class CustomConcurrentHashMap.HashIterator

static class CustomConcurrentHashMap.IntKeyIntValueNode

static class CustomConcurrentHashMap.IntKeyIntValueNodeFactory

static class CustomConcurrentHashMap.IntKeyNode

static class CustomConcurrentHashMap.IntKeySelfValueNode

static class CustomConcurrentHashMap.IntKeySelfValueNodeFactory

static class CustomConcurrentHashMap.IntKeySoftValueNode

static class CustomConcurrentHashMap.IntKeySoftValueNodeFactory

static class CustomConcurrentHashMap.IntKeyStrongValueNode

static class CustomConcurrentHashMap.IntKeyStrongValueNodeFactory

static class CustomConcurrentHashMap.IntKeyWeakValueNode

static class CustomConcurrentHashMap.IntKeyWeakValueNodeFactory

class CustomConcurrentHashMap.KeyIterator

static class CustomConcurrentHashMap.KeySet

Creates a set with the given parameters.

class CustomConcurrentHashMap.KeySetView

static class CustomConcurrentHashMap.LinkedIntKeyIntValueNode

static class CustomConcurrentHashMap.LinkedIntKeySelfValueNode

static class CustomConcurrentHashMap.LinkedIntKeySoftValueNode

static class CustomConcurrentHashMap.LinkedIntKeyStrongValueNode

static class CustomConcurrentHashMap.LinkedIntKeyWeakValueNode

static class CustomConcurrentHashMap.LinkedSoftKeyIntValueNode

static class CustomConcurrentHashMap.LinkedSoftKeySelfValueNode

static class CustomConcurrentHashMap.LinkedSoftKeySoftValueNode

static class CustomConcurrentHashMap.LinkedSoftKeyStrongValueNode

static class CustomConcurrentHashMap.LinkedSoftKeyWeakValueNode

static class CustomConcurrentHashMap.LinkedStrongKeyIntValueNode

static class CustomConcurrentHashMap.LinkedStrongKeySelfValueNode

static class CustomConcurrentHashMap.LinkedStrongKeySoftValueNode

static class CustomConcurrentHashMap.LinkedStrongKeyStrongValueNode

static class CustomConcurrentHashMap.LinkedStrongKeyWeakValueNode

static class CustomConcurrentHashMap.LinkedWeakKeyIntValueNode

static class CustomConcurrentHashMap.LinkedWeakKeySelfValueNode

static class CustomConcurrentHashMap.LinkedWeakKeySoftValueNode

static class CustomConcurrentHashMap.LinkedWeakKeyStrongValueNode

static class CustomConcurrentHashMap.LinkedWeakKeyWeakValueNode

static interface CustomConcurrentHashMap.MappingFunction

A function computing a mapping from the given key to a value, or null if there is no mapping.

static interface CustomConcurrentHashMap.Node

An object maintaining a key-value mapping.

static interface CustomConcurrentHashMap.NodeFactory

A factory for Nodes.

static interface CustomConcurrentHashMap.Reclaimable

An object that may be subject to cleanup operations when removed from a java.lang.ref.ReferenceQueue

static class CustomConcurrentHashMap.ReclamationThread

static interface CustomConcurrentHashMap.RemappingFunction

A function computing a new mapping from the given key and its current value to a new value, or null if there is no mapping.

static class CustomConcurrentHashMap.Segment

Each Segment holds a count and table corresponding to a segment of the table.

static class CustomConcurrentHashMap.SoftKeyIntValueNode

static class CustomConcurrentHashMap.SoftKeyIntValueNodeFactory

static class CustomConcurrentHashMap.SoftKeyNode

static class CustomConcurrentHashMap.SoftKeySelfValueNode

static class CustomConcurrentHashMap.SoftKeySelfValueNodeFactory

static class CustomConcurrentHashMap.SoftKeySoftValueNode

static class CustomConcurrentHashMap.SoftKeySoftValueNodeFactory

static class CustomConcurrentHashMap.SoftKeyStrongValueNode

static class CustomConcurrentHashMap.SoftKeyStrongValueNodeFactory

static class CustomConcurrentHashMap.SoftKeyWeakValueNode

static class CustomConcurrentHashMap.SoftKeyWeakValueNodeFactory

enum CustomConcurrentHashMap.Strength

The strength of keys and values that may be held by maps. strong denotes ordinary objects. weak and soft denote the corresponding java.lang.ref.Reference types.

static class CustomConcurrentHashMap.StrongKeyIntValueNode

static class CustomConcurrentHashMap.StrongKeyIntValueNodeFactory

static class CustomConcurrentHashMap.StrongKeyNode

static class CustomConcurrentHashMap.StrongKeySelfValueNode

static class CustomConcurrentHashMap.StrongKeySelfValueNodeFactory

static class CustomConcurrentHashMap.StrongKeySoftValueNode

static class CustomConcurrentHashMap.StrongKeySoftValueNodeFactory

static class CustomConcurrentHashMap.StrongKeyStrongValueNode

static class CustomConcurrentHashMap.StrongKeyStrongValueNodeFactory

static class CustomConcurrentHashMap.StrongKeyWeakValueNode

static class CustomConcurrentHashMap.StrongKeyWeakValueNodeFactory

static class CustomConcurrentHashMap.TerminalIntKeyIntValueNode

static class CustomConcurrentHashMap.TerminalIntKeySelfValueNode

static class CustomConcurrentHashMap.TerminalIntKeySoftValueNode

static class CustomConcurrentHashMap.TerminalIntKeyStrongValueNode

static class CustomConcurrentHashMap.TerminalIntKeyWeakValueNode

static class CustomConcurrentHashMap.TerminalSoftKeyIntValueNode

static class CustomConcurrentHashMap.TerminalSoftKeySelfValueNode

static class CustomConcurrentHashMap.TerminalSoftKeySoftValueNode

static class CustomConcurrentHashMap.TerminalSoftKeyStrongValueNode

static class CustomConcurrentHashMap.TerminalSoftKeyWeakValueNode

static class CustomConcurrentHashMap.TerminalStrongKeyIntValueNode

static class CustomConcurrentHashMap.TerminalStrongKeySelfValueNode

static class CustomConcurrentHashMap.TerminalStrongKeySoftValueNode

static class CustomConcurrentHashMap.TerminalStrongKeyStrongValueNode

static class CustomConcurrentHashMap.TerminalStrongKeyWeakValueNode

static class CustomConcurrentHashMap.TerminalWeakKeyIntValueNode

static class CustomConcurrentHashMap.TerminalWeakKeySelfValueNode

static class CustomConcurrentHashMap.TerminalWeakKeySoftValueNode

static class CustomConcurrentHashMap.TerminalWeakKeyStrongValueNode

static class CustomConcurrentHashMap.TerminalWeakKeyWeakValueNode

class CustomConcurrentHashMap.ValueIterator

class CustomConcurrentHashMap.Values

static class CustomConcurrentHashMap.WeakKeyIntValueNode

static class CustomConcurrentHashMap.WeakKeyIntValueNodeFactory

static class CustomConcurrentHashMap.WeakKeyNode

static class CustomConcurrentHashMap.WeakKeySelfValueNode

static class CustomConcurrentHashMap.WeakKeySelfValueNodeFactory

static class CustomConcurrentHashMap.WeakKeySoftValueNode

static class CustomConcurrentHashMap.WeakKeySoftValueNodeFactory

static class CustomConcurrentHashMap.WeakKeyStrongValueNode

static class CustomConcurrentHashMap.WeakKeyStrongValueNodeFactory

static class CustomConcurrentHashMap.WeakKeyWeakValueNode

static class CustomConcurrentHashMap.WeakKeyWeakValueNodeFactory

class CustomConcurrentHashMap.WriteThroughEntry

 
Field Summary
static CustomConcurrentHashMap.Equivalence EQUALS

An Equivalence object performing java.lang.Object#equals based comparisons and using java.lang.Object#hashCode hashing

static CustomConcurrentHashMap.Equivalence IDENTITY

An Equivalence object performing identity-based comparisons and using java.lang.System#identityHashCode for hashing

private static java.lang.String INT_STRING

Config string for int maps

static int MAX_SEGMENT_CAPACITY

static int MIN_SEGMENT_CAPACITY

static int NSEGMENTS

static int SEGMENT_BITS

static int SEGMENT_MASK

static int SEGMENT_SHIFT

private static java.lang.String SELF_STRING

Config string for self-map (Set view) refs

static CustomConcurrentHashMap.Strength SOFT

The strength of soft references

static CustomConcurrentHashMap.Strength STRONG

The strength of ordinary references

static sun.misc.Unsafe UNSAFE

static CustomConcurrentHashMap.Strength WEAK

The strength of weak references

java.util.Set entrySet

CustomConcurrentHashMap.NodeFactory factory

int initialSegmentCapacity

CustomConcurrentHashMap.Equivalence keyEquivalence

java.util.Set keySet

static java.lang.ref.ReferenceQueue refQueue

CustomConcurrentHashMap.Segment[] segments

The segments, each of which acts as a hash table

static long segmentsBase

static int segmentsShift

private static long serialVersionUID

static long tableBase

static int tableShift

CustomConcurrentHashMap.Equivalence valueEquivalence

java.util.Collection values

 
Constructor Summary
CustomConcurrentHashMap()

 
Method Summary
java.lang.Object CustomConcurrentHashMap(java.lang.String ks, CustomConcurrentHashMap.Equivalence keq, java.lang.String vs, CustomConcurrentHashMap.Equivalence veq, int expectedSize)

java.lang.Object CustomConcurrentHashMap(CustomConcurrentHashMap.Strength keyStrength, CustomConcurrentHashMap.Equivalence keyEquivalence, CustomConcurrentHashMap.Strength valueStrength, CustomConcurrentHashMap.Equivalence valueEquivalence, int expectedSize)

Creates a new CustomConcurrentHashMap with the given parameters.

java.lang.Object CustomConcurrentHashMap()

void clear()

Removes all of the mappings from this map.

java.lang.Object compute(java.lang.Object key, CustomConcurrentHashMap.RemappingFunction remappingFunction)

Updates the mapping for the given key with the result of the given remappingFunction.

java.lang.Object computeIfAbsent(java.lang.Object key, CustomConcurrentHashMap.MappingFunction mappingFunction)

boolean containsKey(java.lang.Object key)

Returns true if this map contains a key equivalent to the given key with respect to this map's key Equivalence.

boolean containsValue(java.lang.Object value)

java.lang.Object doPut(java.lang.Object key, java.lang.Object value, boolean onlyIfNull)

java.util.Set entrySet()

Compares the specified object with this map for equality.

boolean equals(java.lang.Object o)

CustomConcurrentHashMap.Node findNode(java.lang.Object key, int hash, CustomConcurrentHashMap.Segment seg)

Returns node for key, or null if none.

java.lang.Object get(java.lang.Object key)

static java.lang.ref.ReferenceQueue getReclamationQueue()

CustomConcurrentHashMap.Segment getSegmentForAdd(int hash)

CustomConcurrentHashMap.Segment getSegmentForTraversal(int hash)

Returns the segment for possibly inserting into the table associated with given hash, constructing it if necessary.

private static sun.misc.Unsafe getUnsafe()

int hashCode()

Returns the sum of the hash codes of each entry in this map's entrySet() view, which in turn are the hash codes computed using key and value Equivalences for this Map.

boolean isEmpty()

Returns true if this map contains no key-value mappings.

CustomConcurrentHashMap.KeyIterator keyIterator()

java.util.Set keySet()

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

static CustomConcurrentHashMap newIntKeyIntValueMap(int expectedSize)

static CustomConcurrentHashMap newIntKeyMap(CustomConcurrentHashMap.Strength valueStrength, CustomConcurrentHashMap.Equivalence valueEquivalence, int expectedSize)

static CustomConcurrentHashMap newIntValueMap(CustomConcurrentHashMap.Strength keyStrength, CustomConcurrentHashMap.Equivalence keyEquivalence, int expectedSize)

java.lang.Object put(java.lang.Object key, java.lang.Object value)

Maps the specified key to the specified value in this map.

void putAll(java.util.Map m)

{@inheritDoc}

java.lang.Object putIfAbsent(java.lang.Object key, java.lang.Object value)

Copies all of the mappings from the specified map to this one.

private void readObject(java.io.ObjectInputStream s)

A hash-based set with properties identical to those of Collections.newSetFromMap applied to a CustomConcurrentHashMap, but possibly more space-efficient.

java.lang.Object remove(java.lang.Object key)

Removes the mapping for the specified key.

boolean remove(java.lang.Object key, java.lang.Object value)

{@inheritDoc}

void removeIfReclaimed(CustomConcurrentHashMap.Node r)

Removes node if its key or value are null.

java.lang.Object replace(java.lang.Object key, java.lang.Object value)

boolean replace(java.lang.Object key, java.lang.Object oldValue, java.lang.Object newValue)

{@inheritDoc}

int size()

static int spreadHash(int h)

static java.lang.ref.ReferenceQueue startReclamation()

static void storeNode(CustomConcurrentHashMap.Node[] table, int i, CustomConcurrentHashMap.Node r)

static void storeSegment(CustomConcurrentHashMap.Segment[] segs, int i, CustomConcurrentHashMap.Segment s)

CustomConcurrentHashMap valueOf(java.lang.String name)

Returns the enum constant of this type with the specified name.

CustomConcurrentHashMap[] values()

Returns an array containing the constants of this enum type, in the order they are declared.

java.util.Collection values()

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

private void writeObject(java.io.ObjectOutputStream s)

Reconstitutes the instance from a stream (that is, deserializes it).

 
Methods inherited from class java.util.AbstractMap
java.util.AbstractMap#get(java.lang.Object), java.util.AbstractMap#put(java.lang.Object, java.lang.Object), java.util.AbstractMap#equals(java.lang.Object), java.util.AbstractMap#toString(), java.util.AbstractMap#values(), java.util.AbstractMap#hashCode(), java.util.AbstractMap#clear(), java.util.AbstractMap#entrySet(), java.util.AbstractMap#putAll(java.util.Map), java.util.AbstractMap#remove(java.lang.Object), java.util.AbstractMap#containsValue(java.lang.Object), java.util.AbstractMap#keySet(), java.util.AbstractMap#containsKey(java.lang.Object), java.util.AbstractMap#isEmpty(), java.util.AbstractMap#size(), java.util.AbstractMap#wait(long, int), java.util.AbstractMap#wait(long), java.util.AbstractMap#wait(), java.util.AbstractMap#getClass(), java.util.AbstractMap#notify(), java.util.AbstractMap#notifyAll()
 
Methods inherited from class java.lang.Object
java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()
 

Field Detail

EQUALS

public static final CustomConcurrentHashMap.Equivalence EQUALS
An Equivalence object performing java.lang.Object#equals based comparisons and using java.lang.Object#hashCode hashing


IDENTITY

public static final CustomConcurrentHashMap.Equivalence IDENTITY
An Equivalence object performing identity-based comparisons and using java.lang.System#identityHashCode for hashing


INT_STRING

private static final java.lang.String INT_STRING
Config string for int maps


MAX_SEGMENT_CAPACITY

static final int MAX_SEGMENT_CAPACITY


MIN_SEGMENT_CAPACITY

static final int MIN_SEGMENT_CAPACITY


NSEGMENTS

static final int NSEGMENTS


SEGMENT_BITS

static final int SEGMENT_BITS


SEGMENT_MASK

static final int SEGMENT_MASK


SEGMENT_SHIFT

static final int SEGMENT_SHIFT


SELF_STRING

private static final java.lang.String SELF_STRING
Config string for self-map (Set view) refs


SOFT

public static final CustomConcurrentHashMap.Strength SOFT
The strength of soft references


STRONG

public static final CustomConcurrentHashMap.Strength STRONG
The strength of ordinary references


UNSAFE

static final sun.misc.Unsafe UNSAFE


WEAK

public static final CustomConcurrentHashMap.Strength WEAK
The strength of weak references


entrySet

java.util.Set entrySet


factory

final CustomConcurrentHashMap.NodeFactory factory


initialSegmentCapacity

final int initialSegmentCapacity


keyEquivalence

final CustomConcurrentHashMap.Equivalence keyEquivalence


keySet

java.util.Set keySet


refQueue

static java.lang.ref.ReferenceQueue refQueue


segments

CustomConcurrentHashMap.Segment[] segments
The segments, each of which acts as a hash table


segmentsBase

static final long segmentsBase


segmentsShift

static final int segmentsShift


serialVersionUID

private static final long serialVersionUID


tableBase

static final long tableBase


tableShift

static final int tableShift


valueEquivalence

final CustomConcurrentHashMap.Equivalence valueEquivalence


values

java.util.Collection values


 
Constructor Detail

CustomConcurrentHashMap

CustomConcurrentHashMap()


 
Method Detail

CustomConcurrentHashMap

java.lang.Object CustomConcurrentHashMap(java.lang.String ks, CustomConcurrentHashMap.Equivalence keq, java.lang.String vs, CustomConcurrentHashMap.Equivalence veq, int expectedSize)


CustomConcurrentHashMap

public java.lang.Object CustomConcurrentHashMap(CustomConcurrentHashMap.Strength keyStrength, CustomConcurrentHashMap.Equivalence keyEquivalence, CustomConcurrentHashMap.Strength valueStrength, CustomConcurrentHashMap.Equivalence valueEquivalence, int expectedSize)
Creates a new CustomConcurrentHashMap with the given parameters.
Parameters:
keyStrength - the strength for keys
keyEquivalence - the Equivalence to use for keys
valueStrength - the strength for values
valueEquivalence - the Equivalence to use for values
expectedSize - an estimate of the number of elements that will be held in the map. If no estimate is known, zero is an acceptable value.


CustomConcurrentHashMap

public java.lang.Object CustomConcurrentHashMap()


clear

public final void clear()
Removes all of the mappings from this map.


compute

public java.lang.Object compute(java.lang.Object key, CustomConcurrentHashMap.RemappingFunction remappingFunction)
Updates the mapping for the given key with the result of the given remappingFunction. This is equivalent to
   value = remappingFunction.remap(key, get(key));
   if (value != null)
     return put(key, value):
   else
     return remove(key);
 
except that the action is performed atomically. Some attempted operations on this map by other threads may be blocked while computation is in progress.

Sample Usage. A remapping function can be used to perform frequency counting of words using code such as:

 map.compute(word, new RemappingFunction<String,Integer>() {
   public Integer remap(String k, Integer v) {
     return (v == null) ? 1 : v + 1;
   }});
 
throws:
NullPointerException if the specified key or remappingFunction is null
throws:
RuntimeException or Error if the remappingFunction does so, in which case the mapping is left in its previous state
Parameters:
key - key with which the specified value is to be associated
remappingFunction - the function to compute a value
Returns:
the updated value or null if the computation returned null


computeIfAbsent

public java.lang.Object computeIfAbsent(java.lang.Object key, CustomConcurrentHashMap.MappingFunction mappingFunction)


containsKey

public boolean containsKey(java.lang.Object key)
Returns true if this map contains a key equivalent to the given key with respect to this map's key Equivalence.
throws:
NullPointerException if the specified key is null
Parameters:
key - possible key
Returns:
true if this map contains the specified key


containsValue

public final boolean containsValue(java.lang.Object value)


doPut

final java.lang.Object doPut(java.lang.Object key, java.lang.Object value, boolean onlyIfNull)


entrySet

public java.util.Set entrySet()
Compares the specified object with this map for equality. Returns true if the given object is also a map of the same size, holding keys that are equal using this Map's key Equivalence, and which map to values that are equal according to this Map's value equivalence.
Parameters:
o - object to be compared for equality with this map
Returns:
true if the specified object is equal to this map


equals

public boolean equals(java.lang.Object o)


findNode

final CustomConcurrentHashMap.Node findNode(java.lang.Object key, int hash, CustomConcurrentHashMap.Segment seg)
Returns node for key, or null if none.


get

public java.lang.Object get(java.lang.Object key)


getReclamationQueue

static java.lang.ref.ReferenceQueue getReclamationQueue()


getSegmentForAdd

final CustomConcurrentHashMap.Segment getSegmentForAdd(int hash)


getSegmentForTraversal

final CustomConcurrentHashMap.Segment getSegmentForTraversal(int hash)
Returns the segment for possibly inserting into the table associated with given hash, constructing it if necessary.
Parameters:
hash - the hash code for the key
Returns:
the segment


getUnsafe

private static sun.misc.Unsafe getUnsafe()


hashCode

public int hashCode()
Returns the sum of the hash codes of each entry in this map's entrySet() view, which in turn are the hash codes computed using key and value Equivalences for this Map.
Returns:
the hash code


isEmpty

public final boolean isEmpty()
Returns true if this map contains no key-value mappings.
Returns:
true if this map contains no key-value mappings


keyIterator

final CustomConcurrentHashMap.KeyIterator keyIterator()


keySet

public java.util.Set keySet()
Returns a java.util.Collection view of the values contained in this map. The collection is backed by the map, so changes to the map are reflected in the collection, and vice-versa. The collection supports element removal, which removes the corresponding mapping from this map, via the Iterator.remove, Collection.remove, removeAll, retainAll, and clear operations. It does not support the add or addAll operations.

The view's iterator is a "weakly consistent" iterator that will never throw java.util.ConcurrentModificationException, and guarantees to traverse elements as they existed upon construction of the iterator, and may (but is not guaranteed to) reflect any modifications subsequent to construction.


newIntKeyIntValueMap

public static CustomConcurrentHashMap newIntKeyIntValueMap(int expectedSize)


newIntKeyMap

public static CustomConcurrentHashMap newIntKeyMap(CustomConcurrentHashMap.Strength valueStrength, CustomConcurrentHashMap.Equivalence valueEquivalence, int expectedSize)


newIntValueMap

public static CustomConcurrentHashMap newIntValueMap(CustomConcurrentHashMap.Strength keyStrength, CustomConcurrentHashMap.Equivalence keyEquivalence, int expectedSize)


put

public java.lang.Object put(java.lang.Object key, java.lang.Object value)
Maps the specified key to the specified value in this map.
throws:
NullPointerException if the specified key or value is null
Parameters:
key - key with which the specified value is to be associated
value - value to be associated with the specified key
Returns:
the previous value associated with key, or null if there was no mapping for key


putAll

public void putAll(java.util.Map m)
{@inheritDoc}
throws:
NullPointerException if any of the arguments are null


putIfAbsent

public java.lang.Object putIfAbsent(java.lang.Object key, java.lang.Object value)
Copies all of the mappings from the specified map to this one. These mappings replace any mappings that this map had for any of the keys currently in the specified map.
Parameters:
m - mappings to be stored in this map


readObject

private void readObject(java.io.ObjectInputStream s)
A hash-based set with properties identical to those of Collections.newSetFromMap applied to a CustomConcurrentHashMap, but possibly more space-efficient. The set does not permit null elements. The set is serializable; however, serializing a set that uses soft or weak references can give unpredictable results.


remove

public java.lang.Object remove(java.lang.Object key)
Removes the mapping for the specified key.
throws:
NullPointerException if the specified key is null
Parameters:
key - the key to remove
Returns:
the previous value associated with key, or null if there was no mapping for key


remove

public boolean remove(java.lang.Object key, java.lang.Object value)
{@inheritDoc}
throws:
NullPointerException if the specified key is null


removeIfReclaimed

final void removeIfReclaimed(CustomConcurrentHashMap.Node r)
Removes node if its key or value are null.


replace

public java.lang.Object replace(java.lang.Object key, java.lang.Object value)


replace

public boolean replace(java.lang.Object key, java.lang.Object oldValue, java.lang.Object newValue)
{@inheritDoc}
throws:
NullPointerException if the specified key or value is null
Returns:
the previous value associated with the specified key, or null if there was no mapping for the key


size

public final int size()


spreadHash

static int spreadHash(int h)


startReclamation

static java.lang.ref.ReferenceQueue startReclamation()


storeNode

static final void storeNode(CustomConcurrentHashMap.Node[] table, int i, CustomConcurrentHashMap.Node r)


storeSegment

static final void storeSegment(CustomConcurrentHashMap.Segment[] segs, int i, CustomConcurrentHashMap.Segment s)


valueOf

CustomConcurrentHashMap valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name.


values

CustomConcurrentHashMap[] values()
Returns an array containing the constants of this enum type, in the order they are declared.


values

public java.util.Collection values()
Returns a java.util.Set view of the mappings contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll, and clear operations. It does not support the add or addAll operations.

The view's iterator is a "weakly consistent" iterator that will never throw java.util.ConcurrentModificationException, and guarantees to traverse elements as they existed upon construction of the iterator, and may (but is not guaranteed to) reflect any modifications subsequent to construction.


writeObject

private void writeObject(java.io.ObjectOutputStream s)
Reconstitutes the instance from a stream (that is, deserializes it).
Parameters:
s - the stream


 

Copyright © 2008–2013 Václav Pech. All Rights Reserved.