Package io.micronaut.core.util.clhm
Class ConcurrentLinkedHashMap.Builder<K,V>
java.lang.Object
io.micronaut.core.util.clhm.ConcurrentLinkedHashMap.Builder<K,V>
- Type Parameters:
K
- The key typeV
- The value type
- Enclosing class:
- ConcurrentLinkedHashMap<K,
V>
A builder that creates
ConcurrentLinkedHashMap
instances. It
provides a flexible approach for constructing customized instances with
a named parameter syntax. It can be used in the following manner:
ConcurrentMap<Vertex, Set<Edge>> graph = new Builder<Vertex, Set<Edge>>()
.maximumWeightedCapacity(5000)
.weigher(Weighers.<Edge>set())
.build();
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionbuild()
Creates a newConcurrentLinkedHashMap
instance.concurrencyLevel
(int concurrencyLevel) Specifies the estimated number of concurrently updating threads.initialCapacity
(int initialCapacity) Specifies the initial capacity of the hash table (default16
).listener
(EvictionListener<K, V> listener) Specifies an optional listener that is registered for notification when an entry is evicted.maximumWeightedCapacity
(long capacity) Specifies the maximum weighted capacity to coerce the map to and may exceed it temporarily.weigher
(EntryWeigher<? super K, ? super V> weigher) Specifies an algorithm to determine how many the units of capacity an entry consumes.Specifies an algorithm to determine how many the units of capacity a value consumes.
-
Constructor Details
-
Builder
public Builder()Default constructor.
-
-
Method Details
-
initialCapacity
Specifies the initial capacity of the hash table (default16
). This is the number of key-value pairs that the hash table can hold before a resize operation is required.- Parameters:
initialCapacity
- the initial capacity used to size the hash table to accommodate this many entries.- Returns:
- This builder
- Throws:
IllegalArgumentException
- if the initialCapacity is negative
-
maximumWeightedCapacity
Specifies the maximum weighted capacity to coerce the map to and may exceed it temporarily.- Parameters:
capacity
- the weighted threshold to bound the map by- Returns:
- This builder
- Throws:
IllegalArgumentException
- if the maximumWeightedCapacity is negative
-
concurrencyLevel
Specifies the estimated number of concurrently updating threads. The implementation performs internal sizing to try to accommodate this many threads (default16
).- Parameters:
concurrencyLevel
- the estimated number of concurrently updating threads- Returns:
- This builder
- Throws:
IllegalArgumentException
- if the concurrencyLevel is less than or equal to zero
-
listener
Specifies an optional listener that is registered for notification when an entry is evicted.- Parameters:
listener
- the object to forward evicted entries to- Returns:
- This builder
- Throws:
NullPointerException
- if the listener is null
-
weigher
Specifies an algorithm to determine how many the units of capacity a value consumes. The default algorithm bounds the map by the number of key-value pairs by giving each entry a weight of1
.- Parameters:
weigher
- the algorithm to determine a value's weight- Returns:
- This builder
- Throws:
NullPointerException
- if the weigher is null
-
weigher
Specifies an algorithm to determine how many the units of capacity an entry consumes. The default algorithm bounds the map by the number of key-value pairs by giving each entry a weight of1
.- Parameters:
weigher
- the algorithm to determine an entry's weight- Returns:
- This builder
- Throws:
NullPointerException
- if the weigher is null
-
build
Creates a newConcurrentLinkedHashMap
instance.- Returns:
- This builder
- Throws:
IllegalStateException
- if the maximum weighted capacity was not set
-