Class BaseMultiCounter<K,​V>

    • Constructor Detail

      • BaseMultiCounter

        protected BaseMultiCounter​(Map<K,​Counter<V>> backingMap)
        Instantiates a new Base multi counter.
        Parameters:
        backingMap - the backing map
    • Method Detail

      • adjustValues

        public MultiCounter<K,​V> adjustValues​(DoubleUnaryOperator function)
        Description copied from interface: MultiCounter
        Constructs a new multi-counter made up of counts that are adjusted using the supplied function.
        Specified by:
        adjustValues in interface MultiCounter<K,​V>
        Parameters:
        function - The function to use to adjust the counts
        Returns:
        The new counter with adjusted counts.
      • contains

        public boolean contains​(K item)
        Description copied from interface: MultiCounter
        Determines if (item,*) is in the counter, i.e. if the item is a first key in the counter
        Specified by:
        contains in interface MultiCounter<K,​V>
        Parameters:
        item - item relating to a first key to check
        Returns:
        True if item is in the counter, false otherwise
      • contains

        public boolean contains​(K item1,
                                V item2)
        Description copied from interface: MultiCounter
        Determines if the pair (item1,item2) is in the counter.
        Specified by:
        contains in interface MultiCounter<K,​V>
        Parameters:
        item1 - the item 1
        item2 - the item 2
        Returns:
        the boolean
      • createCounter

        protected abstract Counter<V> createCounter()
        Creates a new counter.
        Returns:
        the counter
      • entries

        public Set<Tuple3<K,​V,​Double>> entries()
        Description copied from interface: MultiCounter
        A set of triplies entries (key1,key2,double) making up the counter
        Specified by:
        entries in interface MultiCounter<K,​V>
        Returns:
        the set of entries
      • filterByFirstKey

        public MultiCounter<K,​V> filterByFirstKey​(Predicate<K> predicate)
        Description copied from interface: MultiCounter
        Creates a new multi-counter containing only those entries whose first key evaluate true for the given predicate
        Specified by:
        filterByFirstKey in interface MultiCounter<K,​V>
        Parameters:
        predicate - the predicate to use to filter the first keys
        Returns:
        A new counter containing only those entries whose first key evaluate true for the given predicate
      • filterBySecondKey

        public MultiCounter<K,​V> filterBySecondKey​(Predicate<V> predicate)
        Description copied from interface: MultiCounter
        Creates a new multi-counter containing only those entries whose second key evaluate true for the given predicate
        Specified by:
        filterBySecondKey in interface MultiCounter<K,​V>
        Parameters:
        predicate - the predicate to use to filter the second keys
        Returns:
        A new counter containing only those entries whose second key evaluate true for the given predicate
      • filterByValue

        public MultiCounter<K,​V> filterByValue​(DoublePredicate predicate)
        Description copied from interface: MultiCounter
        Creates a new multi-counter containing only those entries whose value evaluate true for the given predicate
        Specified by:
        filterByValue in interface MultiCounter<K,​V>
        Parameters:
        predicate - the predicate to use to filter the values
        Returns:
        A new counter containing only those entries whose value evaluate true for the given predicate
      • firstKeys

        public Set<K> firstKeys()
        Description copied from interface: MultiCounter
        Retrieves a set of the first keys in the counter
        Specified by:
        firstKeys in interface MultiCounter<K,​V>
        Returns:
        The items making up the first level keys in the counter
      • get

        public Counter<V> get​(K firstKey)
        Description copied from interface: MultiCounter
        Gets a counter of second keys associated with the first key.
        Specified by:
        get in interface MultiCounter<K,​V>
        Parameters:
        firstKey - the first key whose counter we want
        Returns:
        A counter of second key - double values associated with the first key
      • isEmpty

        public boolean isEmpty()
        Description copied from interface: MultiCounter
        Determines if the counter is empty or not
        Specified by:
        isEmpty in interface MultiCounter<K,​V>
        Returns:
        True if the counter is empty
      • itemsByCount

        public List<Map.Entry<K,​V>> itemsByCount​(boolean ascending)
        Description copied from interface: MultiCounter
        Returns the items as a sorted list by their counts.
        Specified by:
        itemsByCount in interface MultiCounter<K,​V>
        Parameters:
        ascending - True if the counts are sorted in ascending order, False if in descending order.
        Returns:
        The sorted list of items.
      • keyPairs

        public Set<Map.Entry<K,​V>> keyPairs()
        Description copied from interface: MultiCounter
        Retrieves the set of key pairs making up the counts in the counter
        Specified by:
        keyPairs in interface MultiCounter<K,​V>
        Returns:
        A set of key pairs that make up the items in the counter
      • merge

        public MultiCounter<K,​V> merge​(MultiCounter<K,​V> other)
        Description copied from interface: MultiCounter
        Merges the counts in one counter with this one.
        Specified by:
        merge in interface MultiCounter<K,​V>
        Parameters:
        other - The other counter to merge.
        Returns:
        the multi counter
      • newInstance

        protected abstract MultiCounter<K,​V> newInstance()
        New instance.
        Returns:
        the multi counter
      • remove

        public Counter<V> remove​(K item)
        Description copied from interface: MultiCounter
        Removes an item and its associated secondary keys from the counter
        Specified by:
        remove in interface MultiCounter<K,​V>
        Parameters:
        item - The first level key to remove
        Returns:
        the counter associated with the removed item
      • remove

        public double remove​(K item1,
                             V item2)
        Description copied from interface: MultiCounter
        Removes a key pair from the counter.
        Specified by:
        remove in interface MultiCounter<K,​V>
        Parameters:
        item1 - the first key
        item2 - the second key
        Returns:
        the count of the key pair
      • set

        public MultiCounter<K,​V> set​(K item1,
                                           V item2,
                                           double amount)
        Description copied from interface: MultiCounter
        Sets the value of the given key pair to the given amount
        Specified by:
        set in interface MultiCounter<K,​V>
        Parameters:
        item1 - the first key
        item2 - the second key
        amount - the amount to set the key pair to
        Returns:
        This MultiCounter (for fluent design)
      • set

        public MultiCounter<K,​V> set​(K item,
                                           Counter<V> counter)
        Description copied from interface: MultiCounter
        Sets the secondary keys and counts associated with a first level kek
        Specified by:
        set in interface MultiCounter<K,​V>
        Parameters:
        item - the first key
        counter - the counter of secondary keys and counts
        Returns:
        This MultiCounter (for fluent design)
      • size

        public int size()
        Description copied from interface: MultiCounter
        The total number of items in the counter
        Specified by:
        size in interface MultiCounter<K,​V>
        Returns:
        The number of items in the counter
      • values

        public Collection<Double> values()
        Description copied from interface: MultiCounter
        The values associated with the items in the counter
        Specified by:
        values in interface MultiCounter<K,​V>
        Returns:
        The values of the items in the counter.