Package: org.apache.groovy.util.concurrentlinkedhashmap

## [Java] Class Weighers

- org.apache.groovy.util.concurrentlinkedhashmap.Weighers

- A common set of Weigher and EntryWeigher implementations.

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

- - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `<K, V>` | `static EntryWeigher<K, V>` | `asEntryWeigher(Weigher<? super V> weigher)` A entry weigher backed by the specified weigher.
    `` | `static Weigher<byte[]>` | `byteArray()` A weigher where the value is a byte array and its weight is the number of bytes.
    `<E>` | `static Weigher<? super def>` | `collection()` A weigher where the value is a Collection and its weight is the number of elements.
    `<K, V>` | `static EntryWeigher<K, V>` | `entrySingleton()` A weigher where an entry has a weight of `1`.
    `<E>` | `static Weigher<? super def>` | `iterable()` A weigher where the value is a Iterable and its weight is the number of elements.
    `<E>` | `static Weigher<? super def>` | `list()` A weigher where the value is a List and its weight is the number of elements.
    `<A, B>` | `static Weigher<? super def>` | `map()` A weigher where the value is a Map and its weight is the number of entries.
    `<E>` | `static Weigher<? super def>` | `set()` A weigher where the value is a Set and its weight is the number of elements.
    `<V>` | `static Weigher<V>` | `singleton()` A weigher where a value has a weight of `1`.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Object` | `wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll`

- - ### Method Detail

    - #### <K, V> public static EntryWeigher<K, V> asEntryWeigher(Weigher<? super V> weigher)

      A entry weigher backed by the specified weigher. The weight of the value determines the weight of the entry.

      Parameters:
        `weigher` - the weigher to be "wrapped" in a entry weigher.
      Returns:
        A entry weigher view of the specified weigher.

    - #### 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.

    - #### <E> @SuppressWarnings({"cast", "unchecked"}) public static Weigher<? super def> 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.

    - #### <K, V> @SuppressWarnings({"cast", "unchecked"}) public static EntryWeigher<K, V> entrySingleton()

      A weigher where an entry 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.

    - #### <E> @SuppressWarnings({"cast", "unchecked"}) public static Weigher<? super def> 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.

    - #### <E> @SuppressWarnings({"cast", "unchecked"}) public static Weigher<? super def> 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.

    - #### <A, B> @SuppressWarnings({"cast", "unchecked"}) public static Weigher<? super def> 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.

    - #### <E> @SuppressWarnings({"cast", "unchecked"}) public static Weigher<? super def> 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.

    - #### <V> @SuppressWarnings({"cast", "unchecked"}) public static 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.