public static final class ConcurrentLinkedHashMap.Builder<K,V> extends Object
ConcurrentLinkedHashMap
instances. It
provides a flexible approach for constructing customized instances with
a named parameter syntax. It can be used in the following manner:
// a cache of the groups that a user belongs to
ConcurrentMap<User, Set<Group>> groups = new Builder<User, Set<Group>>()
.weigher(Weighers.<Group>set())
.maximumWeightedCapacity(5000)
.build();
Constructor and Description |
---|
Builder() |
Modifier and Type | Method and Description |
---|---|
ConcurrentLinkedHashMap<K,V> |
build()
Creates a new
ConcurrentLinkedHashMap instance. |
ConcurrentLinkedHashMap.Builder<K,V> |
capacityLimiter(CapacityLimiter capacityLimiter)
Specifies an algorithm to determine if the maximum capacity has been
exceeded and that an entry should be evicted from the map.
|
ConcurrentLinkedHashMap.Builder<K,V> |
concurrencyLevel(int concurrencyLevel)
Specifies the estimated number of concurrently updating threads.
|
ConcurrentLinkedHashMap.Builder<K,V> |
initialCapacity(int initialCapacity)
Specifies the initial capacity of the hash table (default 16).
|
ConcurrentLinkedHashMap.Builder<K,V> |
listener(EvictionListener<K,V> listener)
Specifies an optional listener that is registered for notification when
an entry is evicted.
|
ConcurrentLinkedHashMap.Builder<K,V> |
maximumWeightedCapacity(int maximumWeightedCapacity)
Specifies the maximum weighted capacity to coerces the map to and may
exceed it temporarily.
|
ConcurrentLinkedHashMap.Builder<K,V> |
weigher(Weigher<? super V> weigher)
Specifies an algorithm to determine how many the units of capacity a
value consumes.
|
public ConcurrentLinkedHashMap.Builder<K,V> initialCapacity(int initialCapacity)
initialCapacity
- the initial capacity used to size the hash table
to accommodate this many entries.IllegalArgumentException
- if the initialCapacity is negativepublic ConcurrentLinkedHashMap.Builder<K,V> maximumWeightedCapacity(int maximumWeightedCapacity)
maximumWeightedCapacity
- the weighted threshold to bound the map
byIllegalArgumentException
- if the maximumWeightedCapacity is
negativepublic ConcurrentLinkedHashMap.Builder<K,V> concurrencyLevel(int concurrencyLevel)
concurrencyLevel
- the estimated number of concurrently updating
threadsIllegalArgumentException
- if the concurrencyLevel is less than or
equal to zeropublic ConcurrentLinkedHashMap.Builder<K,V> listener(EvictionListener<K,V> listener)
listener
- the object to forward evicted entries toNullPointerException
- if the listener is nullpublic ConcurrentLinkedHashMap.Builder<K,V> weigher(Weigher<? super V> weigher)
weigher
- the algorithm to determine a value's weightNullPointerException
- if the weigher is nullpublic ConcurrentLinkedHashMap.Builder<K,V> capacityLimiter(CapacityLimiter capacityLimiter)
capacityLimiter
- the algorithm to determine whether to evict an
entryNullPointerException
- if the capacity limiter is nullpublic ConcurrentLinkedHashMap<K,V> build()
ConcurrentLinkedHashMap
instance.IllegalStateException
- if the maximum weighted capacity was
not setCopyright © 2019. All rights reserved.