Class Weighers
Weigher
and EntryWeigher
implementations.- Author:
- ben.manes@gmail.com (Ben Manes)
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic <K,
V> EntryWeigher<K, V> asEntryWeigher
(Weigher<? super V> weigher) An entry weigher backed by the specified weigher.static Weigher<byte[]>
A weigher where the value is a byte array and its weight is the number of bytes.static <E> Weigher<? super Collection<E>>
A weigher where the value is aCollection
and its weight is the number of elements.static <K,
V> EntryWeigher<K, V> A weigher where an entry has a weight of1
.iterable()
A weigher where the value is aIterable
and its weight is the number of elements.list()
A weigher where the value is aList
and its weight is the number of elements.map()
A weigher where the value is aMap
and its weight is the number of entries.set()
A weigher where the value is aSet
and its weight is the number of elements.static <V> Weigher<V>
A weigher where a value has a weight of1
.
-
Method Details
-
asEntryWeigher
An entry weigher backed by the specified weigher. The weight of the value determines the weight of the entry.- Type Parameters:
K
- The key typeV
- The value type- Parameters:
weigher
- the weigher to be "wrapped" in an entry weigher.- Returns:
- An entry weigher view of the specified weigher.
-
entrySingleton
A weigher where an entry has a weight of1
. A map bounded with this weigher will evict when the number of key-value pairs exceeds the capacity.- Type Parameters:
K
- The key typeV
- The value type- Returns:
- A weigher where a value takes one unit of capacity.
-
singleton
A weigher where a value has a weight of1
. A map bounded with this weigher will evict when the number of key-value pairs exceeds the capacity.- Type Parameters:
V
- The value type- Returns:
- A weigher where a value takes one unit of capacity.
-
byteArray
A weigher where the value is a byte array and its weight is the number of bytes. A map bounded with this weigher will evict when the number of bytes exceeds the capacity rather than the number of key-value pairs in the map. This allows for restricting the capacity based on the memory-consumption and is primarily for usage by dedicated caching servers that hold the serialized data.A value with a weight of
0
will be rejected by the map. If a value with this weight can occur then the caller should eagerly evaluate the value and treat it as a removal operation. Alternatively, a custom weigher may be specified on the map to assign an empty value a positive weight.- Returns:
- A weigher where each byte takes one unit of capacity.
-
iterable
A weigher where the value is aIterable
and its weight is the number of elements. This weigher only should be used when the alternativecollection()
weigher cannot be, as evaluation takes O(n) time. A map bounded with this weigher will evict when the total number of elements exceeds the capacity rather than the number of key-value pairs in the map.A value with a weight of
0
will be rejected by the map. If a value with this weight can occur then the caller should eagerly evaluate the value and treat it as a removal operation. Alternatively, a custom weigher may be specified on the map to assign an empty value a positive weight.- Type Parameters:
E
- The element type- Returns:
- A weigher where each element takes one unit of capacity.
-
collection
A weigher where the value is aCollection
and its weight is the number of elements. A map bounded with this weigher will evict when the total number of elements exceeds the capacity rather than the number of key-value pairs in the map.A value with a weight of
0
will be rejected by the map. If a value with this weight can occur then the caller should eagerly evaluate the value and treat it as a removal operation. Alternatively, a custom weigher may be specified on the map to assign an empty value a positive weight.- Type Parameters:
E
- The element type- Returns:
- A weigher where each element takes one unit of capacity.
-
list
A weigher where the value is aList
and its weight is the number of elements. A map bounded with this weigher will evict when the total number of elements exceeds the capacity rather than the number of key-value pairs in the map.A value with a weight of
0
will be rejected by the map. If a value with this weight can occur then the caller should eagerly evaluate the value and treat it as a removal operation. Alternatively, a custom weigher may be specified on the map to assign an empty value a positive weight.- Type Parameters:
E
- The element type- Returns:
- A weigher where each element takes one unit of capacity.
-
set
A weigher where the value is aSet
and its weight is the number of elements. A map bounded with this weigher will evict when the total number of elements exceeds the capacity rather than the number of key-value pairs in the map.A value with a weight of
0
will be rejected by the map. If a value with this weight can occur then the caller should eagerly evaluate the value and treat it as a removal operation. Alternatively, a custom weigher may be specified on the map to assign an empty value a positive weight.- Type Parameters:
E
- The element type- Returns:
- A weigher where each element takes one unit of capacity.
-
map
A weigher where the value is aMap
and its weight is the number of entries. A map bounded with this weigher will evict when the total number of entries across all values exceeds the capacity rather than the number of key-value pairs in the map.A value with a weight of
0
will be rejected by the map. If a value with this weight can occur then the caller should eagerly evaluate the value and treat it as a removal operation. Alternatively, a custom weigher may be specified on the map to assign an empty value a positive weight.- Type Parameters:
A
- The key typeB
- The value type- Returns:
- A weigher where each entry takes one unit of capacity.
-