com.googlecode.concurrentlinkedhashmap
Class Weighers

java.lang.Object
  extended by com.googlecode.concurrentlinkedhashmap.Weighers

public final class Weighers
extends Object

A common set of Weigher implementations.

Author:
ben.manes@gmail.com (Ben Manes)
See Also:
http://code.google.com/p/concurrentlinkedhashmap/

Method Summary
static Weigher<byte[]> byteArray()
          A weigher where the value is a byte array and its weight is the number of bytes.
static
<E> Weigher<? super Collection<E>>
collection()
          A weigher where the value is a Collection and its weight is the number of elements.
static
<E> Weigher<? super Iterable<E>>
iterable()
          A weigher where the value is a Iterable and its weight is the number of elements.
static
<E> Weigher<? super List<E>>
list()
          A weigher where the value is a List and its weight is the number of elements.
static
<A,B> Weigher<? super Map<A,B>>
map()
          A weigher where the value is a Map and its weight is the number of entries.
static
<E> Weigher<? super Set<E>>
set()
          A weigher where the value is a Set and its weight is the number of elements.
static
<V> Weigher<V>
singleton()
          A weigher where a value has a weight of 1.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

singleton

public static <V> Weigher<V> singleton()
A weigher where a value has a weight of 1. A map bounded with this weigher will evict when the number of key-value pairs exceeds the capacity.

Returns:
A weigher where a value takes one unit of capacity.

byteArray

public static Weigher<byte[]> 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

public static <E> Weigher<? super Iterable<E>> iterable()
A weigher where the value is a Iterable and its weight is the number of elements. This weigher only should be used when the alternative collection() 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.

Returns:
A weigher where each element takes one unit of capacity.

collection

public static <E> Weigher<? super Collection<E>> collection()
A weigher where the value is a Collection 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.

Returns:
A weigher where each element takes one unit of capacity.

list

public static <E> Weigher<? super List<E>> list()
A weigher where the value is a List 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.

Returns:
A weigher where each element takes one unit of capacity.

set

public static <E> Weigher<? super Set<E>> set()
A weigher where the value is a Set 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.

Returns:
A weigher where each element takes one unit of capacity.

map

public static <A,B> Weigher<? super Map<A,B>> map()
A weigher where the value is a Map 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.

Returns:
A weigher where each entry takes one unit of capacity.


Copyright © 2012. All Rights Reserved.