com.hazelcast.util

## Class ItemCounter<T>

- java.lang.Object
- - com.hazelcast.util.ItemCounter<T>

- Type Parameters:
    `T` -

      public final class ItemCounter<T>
      extends Object

  Non Thread-Safe Counter of things. It allows to count items without worrying about nulls.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ItemCounter()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `add(T item, long delta)` Add delta to the item
    `void` | `clear()` Clears the counter.
    `List<T>` | `descendingKeys()` Returns a List of keys in descending value order.
    `boolean` | `equals(Object o)`
    `long` | `get(T item)` Get current counter for an item item
    `long` | `getAndSet(T item, long value)` Set counter for item and return previous value
    `int` | `hashCode()`
    `void` | `inc(T item)` Increases the count by on for the given item.
    `Set<T>` | `keySet()` Returns an iterator over all keys.
    `void` | `remove(T item)`
    `void` | `reset()` Reset state of the counter to 0.
    `void` | `set(T item, long value)` Set counter of item to value
    `String` | `toString()`
    `long` | `total()` Returns the total counts.

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

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### ItemCounter

          public ItemCounter()

  - ### Method Detail

    - #### total

          public long total()

      Returns the total counts. Complexity is O(1).
      Returns:
        total count.

    - #### keySet

          public Set<T> keySet()

      Returns an iterator over all keys.
      Returns:
        the key iterator.

    - #### descendingKeys

          public List<T> descendingKeys()

      Returns a List of keys in descending value order.
      Returns:
        the list of keys

    - #### get

          public long get(T item)

      Get current counter for an item item
      Parameters:
        `item` -
      Returns:
        current state of a counter for item

    - #### set

          public void set(T item,
                          long value)

      Set counter of item to value
      Parameters:
        `item` - to set set the value for
        `value` - a new value

    - #### inc

          public void inc(T item)

      Increases the count by on for the given item.
      Parameters:
        `item` -

    - #### add

          public void add(T item,
                          long delta)

      Add delta to the item
      Parameters:
        `item` -
        `delta` -

    - #### reset

          public void reset()

      Reset state of the counter to 0. It will NOT necessary remove all data referenced. Time complexity of this operation is O(n) where n is number of items.

    - #### clear

          public void clear()

      Clears the counter.

    - #### getAndSet

          public long getAndSet(T item,
                                long value)

      Set counter for item and return previous value
      Parameters:
        `item` -
        `value` -
      Returns:

    - #### remove

          public void remove(T item)

    - #### equals

          public boolean equals(Object o)

      Overrides:
        `equals` in class `Object`

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `Object`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

Copyright © 2019. All rights reserved.