org.codehaus.gpars

groovyx.gpars.extra166y
[Java] Enum CustomConcurrentHashMap.Strength

java.lang.Object
  groovyx.gpars.extra166y.CustomConcurrentHashMap.Strength

public 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.


Enum Constant Summary
soft

strong

weak

 
Field Summary
private java.lang.String name

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.

 
Method Summary
java.lang.Object Strength(java.lang.String name)

java.lang.String getName()

 
Methods inherited from class java.lang.Object
java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#wait(long, int), 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()
 

Enum Constant Detail

soft

CustomConcurrentHashMap.Strength soft


strong

CustomConcurrentHashMap.Strength strong


weak

CustomConcurrentHashMap.Strength weak


 
Field Detail

name

private final java.lang.String name
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
     (STRONG, IDENTITY, STRONG, EQUALS, 0);
 weakKeyMap = new CustomConcurrentHashMap
     (WEAK, IDENTITY, STRONG, EQUALS, 0);
     .weakKeys());
 byNameMap = new CustomConcurrentHashMap
     (STRONG,
      new Equivalence() {
          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


 
Method Detail

Strength

java.lang.Object Strength(java.lang.String name)


getName

java.lang.String getName()


 

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