Package net.i2p.util

Class ObjectCounterUnsafe<K>


  • public class ObjectCounterUnsafe<K>
    extends Object
    Count things. NOT thread safe, mostly for UI and Sybil. Dropin replacement for ObjectCounter. Much less object churn than ObjectCounter. Also provides add() and sortedObjects()
    Since:
    0.9.58
    • Constructor Detail

      • ObjectCounterUnsafe

        public ObjectCounterUnsafe()
    • Method Detail

      • increment

        public int increment​(K h)
        Add one.
        Returns:
        count after increment
      • add

        public int add​(K h,
                       int val)
        Add a value
        Returns:
        count after adding
      • count

        public int count​(K h)
        Returns:
        current count
      • objects

        public Set<K> objects()
        Returns:
        set of objects with counts > 0
      • sortedObjects

        public List<K> sortedObjects()
        Returns:
        list of objects reverse sorted by count, highest to lowest
      • clear

        public void clear()
        Start over. Reset the count for all keys to zero.
      • clear

        public void clear​(K h)
        Reset the count for this key to zero