Class PNCounterMap<K>

  • Type Parameters:
    K - The type for keys.
    All Implemented Interfaces:
    java.util.Map<K,​java.lang.Long>

    public final class PNCounterMap<K>
    extends java.util.AbstractMap<K,​V>
    implements java.util.Map<K,​java.lang.Long>
    Convenience wrapper class for ORMap that uses PNCounter's for values.

    This offers a few extra methods for interacting with the map.

    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.util.AbstractMap

        java.util.AbstractMap.SimpleEntry<K extends java.lang.Object,​V extends java.lang.Object>, java.util.AbstractMap.SimpleImmutableEntry<K extends java.lang.Object,​V extends java.lang.Object>
      • Nested classes/interfaces inherited from interface java.util.Map

        java.util.Map.Entry<K extends java.lang.Object,​V extends java.lang.Object>
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()  
      boolean containsKey​(java.lang.Object key)  
      long decrement​(java.lang.Object key, long by)
      Decrement the counter at the given key by the given amount.
      java.util.Set<java.util.Map.Entry<K,​V>> entrySet()  
      V get​(java.lang.Object key)  
      long getValue​(java.lang.Object key)
      Get the value for the given key.
      long increment​(java.lang.Object key, long by)
      Increment the counter at the given key by the given amount.
      java.util.Set<K> keySet()  
      java.lang.Long put​(K key, java.lang.Long value)
      Not supported on PNCounter, use increment/decrement instead.
      V remove​(java.lang.Object key)  
      int size()  
      • Methods inherited from class java.util.AbstractMap

        clone, containsValue, equals, hashCode, isEmpty, putAll, toString, values
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Map

        clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keySet, merge, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
    • Constructor Detail

    • Method Detail

      • getValue

        public long getValue​(java.lang.Object key)
        Get the value for the given key.

        This differs from Map.get(Object) in that it returns a primitive long, and thus avoids an allocation.

        Parameters:
        key - The key to get the value for.
        Returns:
        The current value of the counter at that key, or zero if no counter exists for that key.
      • increment

        public long increment​(java.lang.Object key,
                              long by)
        Increment the counter at the given key by the given amount.

        The counter will be created if it is not already in the map.

        Parameters:
        key - The key of the counter.
        by - The amount to increment by.
        Returns:
        The new value of the counter.
      • decrement

        public long decrement​(java.lang.Object key,
                              long by)
        Decrement the counter at the given key by the given amount.

        The counter will be created if it is not already in the map.

        Parameters:
        key - The key of the counter.
        by - The amount to decrement by.
        Returns:
        The new value of the counter.
      • put

        public java.lang.Long put​(K key,
                                  java.lang.Long value)
        Not supported on PNCounter, use increment/decrement instead.
        Specified by:
        put in interface java.util.Map<K,​java.lang.Long>
      • size

        public int size()
        Specified by:
        size in interface java.util.Map<K,​V>
        Overrides:
        size in class java.util.AbstractMap<K,​V>
      • containsKey

        public boolean containsKey​(java.lang.Object key)
        Specified by:
        containsKey in interface java.util.Map<K,​V>
        Overrides:
        containsKey in class java.util.AbstractMap<K,​V>
      • get

        public V get​(java.lang.Object key)
        Specified by:
        get in interface java.util.Map<K,​V>
        Overrides:
        get in class java.util.AbstractMap<K,​V>
      • remove

        public V remove​(java.lang.Object key)
        Specified by:
        remove in interface java.util.Map<K,​V>
        Overrides:
        remove in class java.util.AbstractMap<K,​V>
      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Map<K,​V>
        Overrides:
        clear in class java.util.AbstractMap<K,​V>
      • keySet

        public java.util.Set<K> keySet()
        Specified by:
        keySet in interface java.util.Map<K,​V>
        Overrides:
        keySet in class java.util.AbstractMap<K,​V>
      • entrySet

        public java.util.Set<java.util.Map.Entry<K,​V>> entrySet()
        Specified by:
        entrySet in interface java.util.Map<K,​V>
        Specified by:
        entrySet in class java.util.AbstractMap<K,​V>