Interface MultiCounter<K,​V>

  • Type Parameters:
    K - component type of the first key in the pair
    V - component type of the second key in the pair
    All Known Implementing Classes:
    BaseMultiCounter, ConcurrentHashMapMultiCounter, HashMapMultiCounter

    public interface MultiCounter<K,​V>

    A specialized object-object to double map that allows basic statistics over the object pairs and their values.

    Author:
    David B. Bracewell
    • Method Detail

      • adjustValues

        MultiCounter<K,​V> adjustValues​(DoubleUnaryOperator function)
        Constructs a new multi-counter made up of counts that are adjusted using the supplied function.
        Parameters:
        function - The function to use to adjust the counts
        Returns:
        The new counter with adjusted counts.
      • adjustValuesSelf

        MultiCounter<K,​V> adjustValuesSelf​(DoubleUnaryOperator function)
        Adjust the values in-place using the supplied function
        Parameters:
        function - The function to use to adjust the counts
        Returns:
        this counter
      • average

        default double average()
        Calculates the average of the values in the counter
        Returns:
        The average count in the counter
      • clear

        void clear()
        Clears the counter
      • contains

        boolean contains​(K item)
        Determines if (item,*) is in the counter, i.e. if the item is a first key in the counter
        Parameters:
        item - item relating to a first key to check
        Returns:
        True if item is in the counter, false otherwise
      • contains

        boolean contains​(K item1,
                         V item2)
        Determines if the pair (item1,item2) is in the counter.
        Parameters:
        item1 - the item 1
        item2 - the item 2
        Returns:
        the boolean
      • decrement

        default MultiCounter<K,​V> decrement​(K item1,
                                                  V item2)
        Decrements the count of the pair (item1, item2) by one.
        Parameters:
        item1 - the first key
        item2 - the second key
        Returns:
        This multi-counter (for fluent design)
      • decrement

        default MultiCounter<K,​V> decrement​(K item1,
                                                  V item2,
                                                  double amount)
        Decrements the count of the pair (item1, item2) by the given amount.
        Parameters:
        item1 - the first key
        item2 - the second key
        amount - the amount to decrement the (item1,item2) pair by
        Returns:
        This multi-counter (for fluent design)
      • decrementAll

        default MultiCounter<K,​V> decrementAll​(Iterable<? extends Map.Entry<K,​V>> iterable)
        Decrements the counts of the entries in the iterable in this counter by one.
        Parameters:
        iterable - the iterable of entries that we want to decrement
        Returns:
        This multi-counter (for fluent design)
      • decrementAll

        default MultiCounter<K,​V> decrementAll​(K item,
                                                     Iterable<? extends V> iterable)
        Decrements the count of the item and each second key in the iterable by one in this counter.
        Parameters:
        item - the first key
        iterable - the iterable of second keys
        Returns:
        This multi-counter (for fluent design)
      • divideByKeySum

        default MultiCounter<K,​V> divideByKeySum()
        Divides the counter of each first key by its sum.
        Returns:
        This multi-counter (for fluent design)
      • divideBySum

        default MultiCounter<K,​V> divideBySum()
        Divides the values in the counter by the sum and sets the sum to 1.0
        Returns:
        This multi-counter (for fluent design)
      • entries

        Set<Tuple3<K,​V,​Double>> entries()
        A set of triplies entries (key1,key2,double) making up the counter
        Returns:
        the set of entries
      • filterByFirstKey

        MultiCounter<K,​V> filterByFirstKey​(Predicate<K> predicate)
        Creates a new multi-counter containing only those entries whose first key evaluate true for the given predicate
        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

        MultiCounter<K,​V> filterBySecondKey​(Predicate<V> predicate)
        Creates a new multi-counter containing only those entries whose second key evaluate true for the given predicate
        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

        MultiCounter<K,​V> filterByValue​(DoublePredicate predicate)
        Creates a new multi-counter containing only those entries whose value evaluate true for the given predicate
        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

        Set<K> firstKeys()
        Retrieves a set of the first keys in the counter
        Returns:
        The items making up the first level keys in the counter
      • get

        default double get​(K item1,
                           V item2)
        Gets the count of the item1, item2 pair
        Parameters:
        item1 - the first key
        item2 - the second key
        Returns:
        the count of the pair
      • get

        Counter<V> get​(K firstKey)
        Gets a counter of second keys associated with the first key.
        Parameters:
        firstKey - the first key whose counter we want
        Returns:
        A counter of second key - double values associated with the first key
      • increment

        default MultiCounter<K,​V> increment​(K item1,
                                                  V item2)
        Increments the count of the pair (item1, item2) by one.
        Parameters:
        item1 - the first key
        item2 - the second key
        Returns:
        This multi-counter (for fluent design)
      • increment

        default MultiCounter<K,​V> increment​(K item1,
                                                  V item2,
                                                  double amount)
        Increments the count of the pair (item1, item2) by the given amount.
        Parameters:
        item1 - the first key
        item2 - the second key
        amount - the amount to increment the (item1,item2) pair by
        Returns:
        This multi-counter (for fluent design)
      • incrementAll

        default MultiCounter<K,​V> incrementAll​(K item,
                                                     Iterable<? extends V> iterable)
        Increments the count of the item and each second key in the iterable by one in this counter.
        Parameters:
        item - the first key
        iterable - the iterable of second keys
        Returns:
        This multi-counter (for fluent design)
      • incrementAll

        default MultiCounter<K,​V> incrementAll​(Iterable<? extends Map.Entry<K,​V>> iterable)
        Increments the counts of the entries in the iterable in this counter by one.
        Parameters:
        iterable - the iterable of entries that we want to increments
        Returns:
        This multi-counter (for fluent design)
      • isEmpty

        boolean isEmpty()
        Determines if the counter is empty or not
        Returns:
        True if the counter is empty
      • itemsByCount

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

        Set<Map.Entry<K,​V>> keyPairs()
        Retrieves the set of key pairs making up the counts in the counter
        Returns:
        A set of key pairs that make up the items in the counter
      • magnitude

        default double magnitude()
        Calculates the magnitude (square root of sum of squares) of the items in the Counter.
        Returns:
        the magnitude
      • maximumCount

        default double maximumCount()
        Determines the maximum value in the counter
        Returns:
        The maximum count in the counter
      • merge

        MultiCounter<K,​V> merge​(MultiCounter<K,​V> other)
        Merges the counts in one counter with this one.
        Parameters:
        other - The other counter to merge.
        Returns:
        the multi counter
      • minimumCount

        default double minimumCount()
        Determines the minimum value in the counter
        Returns:
        The minimum count in the counter
      • remove

        Counter<V> remove​(K item)
        Removes an item and its associated secondary keys from the counter
        Parameters:
        item - The first level key to remove
        Returns:
        the counter associated with the removed item
      • remove

        double remove​(K item1,
                      V item2)
        Removes a key pair from the counter.
        Parameters:
        item1 - the first key
        item2 - the second key
        Returns:
        the count of the key pair
      • removeAll

        default MultiCounter<K,​V> removeAll​(Iterable<K> items)
        Removes all the given items from the counter
        Parameters:
        items - The items to remove
        Returns:
        the multi counter
      • secondKeys

        default Set<V> secondKeys()
        Retrieves an unmodifiable set of secondary level keys in the counter
        Returns:
        an unmodifiable set of secondary level keys in the counter
      • set

        MultiCounter<K,​V> set​(K item1,
                                    V item2,
                                    double amount)
        Sets the value of the given key pair to the given amount
        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

        MultiCounter<K,​V> set​(K item,
                                    Counter<V> counter)
        Sets the secondary keys and counts associated with a first level kek
        Parameters:
        item - the first key
        counter - the counter of secondary keys and counts
        Returns:
        This MultiCounter (for fluent design)
      • setIfAbsent

        default double setIfAbsent​(K key1,
                                   V key2,
                                   BiFunction<K,​V,​Double> function)
      • size

        int size()
        The total number of items in the counter
        Returns:
        The number of items in the counter
      • standardDeviation

        default double standardDeviation()
        Calculates the standard deviation of the items in the counter
        Returns:
        The standard deviation of the counts in the counter
      • sum

        default double sum()
        The sum of values in the counter
        Returns:
        The sum of the counts in the counter
      • transpose

        default MultiCounter<V,​K> transpose()
        Transpose multi counter.
        Returns:
        the multi counter
      • values

        Collection<Double> values()
        The values associated with the items in the counter
        Returns:
        The values of the items in the counter.
      • writeCsv

        default void writeCsv​(Resource output)
                       throws IOException
        Writes the counter items and values to CSV
        Parameters:
        output - the resource to write to
        Throws:
        IOException - Something went wrong writing