com.google.common.collect
Class CustomConcurrentHashMap.Builder

java.lang.Object
  extended by com.google.common.collect.CustomConcurrentHashMap.Builder
Enclosing class:
CustomConcurrentHashMap

public static final class CustomConcurrentHashMap.Builder
extends java.lang.Object

Builds a custom concurrent hash map.


Constructor Summary
CustomConcurrentHashMap.Builder()
           
 
Method Summary
<K,V,E> java.util.concurrent.ConcurrentMap<K,V>
buildComputingMap(CustomConcurrentHashMap.ComputingStrategy<K,V,E> strategy, Function<? super K,? extends V> computer)
          Creates a ConcurrentMap, backed by the given strategy, that supports atomic, on-demand computation of values.
<K,V,E> java.util.concurrent.ConcurrentMap<K,V>
buildMap(CustomConcurrentHashMap.Strategy<K,V,E> strategy)
          Creates a new concurrent hash map backed by the given strategy.
 CustomConcurrentHashMap.Builder concurrencyLevel(int concurrencyLevel)
          Guides the allowed concurrency among update operations.
 CustomConcurrentHashMap.Builder initialCapacity(int initialCapacity)
          Sets a custom initial capacity (defaults to 16).
 CustomConcurrentHashMap.Builder loadFactor(float loadFactor)
          Sets a custom load factor (defaults to 0.75).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CustomConcurrentHashMap.Builder

public CustomConcurrentHashMap.Builder()
Method Detail

loadFactor

public CustomConcurrentHashMap.Builder loadFactor(float loadFactor)
Sets a custom load factor (defaults to 0.75).

Throws:
java.lang.IllegalArgumentException - if loadFactor <= 0

initialCapacity

public CustomConcurrentHashMap.Builder initialCapacity(int initialCapacity)
Sets a custom initial capacity (defaults to 16). Resizing this or any other kind of hash table is a relatively slow operation, so, when possible, it is a good idea to provide estimates of expected table sizes.

Throws:
java.lang.IllegalArgumentException - if initialCapacity < 0

concurrencyLevel

public CustomConcurrentHashMap.Builder concurrencyLevel(int concurrencyLevel)
Guides the allowed concurrency among update operations. Used as a hint for internal sizing. The table is internally partitioned to try to permit the indicated number of concurrent updates without contention. Because placement in hash tables is essentially random, the actual concurrency will vary. Ideally, you should choose a value to accommodate as many threads as will ever concurrently modify the table. Using a significantly higher value than you need can waste space and time, and a significantly lower value can lead to thread contention. But overestimates and underestimates within an order of magnitude do not usually have much noticeable impact. A value of one is appropriate when it is known that only one thread will modify and all others will only read. Defaults to 16.

Throws:
java.lang.IllegalArgumentException - if concurrencyLevel < 0

buildMap

public <K,V,E> java.util.concurrent.ConcurrentMap<K,V> buildMap(CustomConcurrentHashMap.Strategy<K,V,E> strategy)
Creates a new concurrent hash map backed by the given strategy.

Type Parameters:
K - the type of keys to be stored in the returned map
V - the type of values to be stored in the returned map
E - the type of internal entry to be stored in the returned map
Parameters:
strategy - used to implement and manipulate the entries
Throws:
java.lang.NullPointerException - if strategy is null

buildComputingMap

public <K,V,E> java.util.concurrent.ConcurrentMap<K,V> buildComputingMap(CustomConcurrentHashMap.ComputingStrategy<K,V,E> strategy,
                                                                         Function<? super K,? extends V> computer)
Creates a ConcurrentMap, backed by the given strategy, that supports atomic, on-demand computation of values. Map.get(java.lang.Object) returns the value corresponding to the given key, atomically computes it using the computer function passed to this builder, or waits for another thread to compute the value if necessary. Only one value will be computed for each key at a given time.

If an entry's value has not finished computing yet, query methods besides Map.get(java.lang.Object) return immediately as if an entry doesn't exist. In other words, an entry isn't externally visible until the value's computation completes.

Map.get(java.lang.Object) in the returned map implementation throws:

Note: Callers of get() must ensure that the key argument is of type K. Map.get() takes Object, so the key type is not checked at compile time. Passing an object of a type other than K can result in that object being unsafely passed to the computer function as type K not to mention the unsafe key being stored in the map.

Type Parameters:
K - the type of keys to be stored in the returned map
V - the type of values to be stored in the returned map
E - the type of internal entry to be stored in the returned map
Parameters:
strategy - used to implement and manipulate the entries
computer - used to compute values for keys
Throws:
java.lang.NullPointerException - if strategy or computer is null


Copyright © 2007-2009 Google. All Rights Reserved.