com.hazelcast.util.collection

## Class WeightedEvictableList<T>

- java.lang.Object
- - com.hazelcast.util.collection.WeightedEvictableList<T>

- Type Parameters:
    `T` -

      public class WeightedEvictableList<T>
      extends Object

  This list keeps the items as long as its size is less than maximum capacity. Once the list size reaches `maxSize`, the half of the entries with less weight are evicted. When a specified number of votes are cast the list is re-organized to bring the items with the most votes in front. Also, every time `maxSize` is reached, the list is reorganized. The list is not thread-safe.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `WeightedEvictableList.WeightedItem<T>` A node that contains an item and its weight

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `WeightedEvictableList(int maxSize, int maxVotesBeforeReorganization)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `WeightedEvictableList.WeightedItem<T>` | `addOrVote(T item)` Adds a new item to the list or votes for the given item if it already exists.
    `List<WeightedEvictableList.WeightedItem<T>>` | `getList()`
    `WeightedEvictableList.WeightedItem<T>` | `getWeightedItem(int index)`
    `int` | `size()`
    `void` | `voteFor(WeightedEvictableList.WeightedItem<T> weightedItem)` Casts a vote for given list node.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### WeightedEvictableList

          public WeightedEvictableList(int maxSize,
                                       int maxVotesBeforeReorganization)

      Parameters:
        `maxSize` - Maximum number of items this list can keep.
        `maxVotesBeforeReorganization` - How many `voteFor(WeightedItem)` operations are allowed, before items are re-ordered based on on their weights.

  - ### Method Detail

    - #### getList

          public List<WeightedEvictableList.WeightedItem<T>> getList()

    - #### voteFor

          public void voteFor(WeightedEvictableList.WeightedItem<T> weightedItem)

      Casts a vote for given list node. This vote is added to the item's weight.
      Parameters:
        `weightedItem` -

    - #### addOrVote

          public WeightedEvictableList.WeightedItem<T> addOrVote(T item)

      Adds a new item to the list or votes for the given item if it already exists. If the `maxSize` is reached, half of the list is removed. When half of the list is removed, the weights of all the items are reset. The newly added item gets a vote if applicable.
      Parameters:
        `item` -
      Returns:
        The node that can be used to vote for

    - #### getWeightedItem

          public WeightedEvictableList.WeightedItem<T> getWeightedItem(int index)

    - #### size

          public int size()

Copyright © 2019. All rights reserved.