Class BaseMapCounter<T>

    • Constructor Detail

      • BaseMapCounter

        protected BaseMapCounter​(Map<T,​Double> backingMap)
        Instantiates a new map counter.
        Parameters:
        backingMap - the backing map
    • Method Detail

      • adjustValues

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

        public Counter<T> adjustValuesSelf​(DoubleUnaryOperator function)
        Description copied from interface: Counter
        Adjust the values in-place using the supplied function
        Specified by:
        adjustValuesSelf in interface Counter<T>
        Parameters:
        function - The function to use to adjust the counts
        Returns:
        this counter
      • asMap

        public Map<T,​Double> asMap()
        Description copied from interface: Counter
        Provides a map view of this counter
        Specified by:
        asMap in interface Counter<T>
        Returns:
        The counter as a Map
      • bottomN

        public Counter<T> bottomN​(int n)
        Description copied from interface: Counter
        Creates a new counter containing the N items with lowest values
        Specified by:
        bottomN in interface Counter<T>
        Parameters:
        n - the number of items desired
        Returns:
        a counter containing the N items with lowest values from this counter
      • clear

        public void clear()
        Description copied from interface: Counter
        Clears the counter
        Specified by:
        clear in interface Counter<T>
      • contains

        public boolean contains​(T item)
        Description copied from interface: Counter
        Determines if the item is in the counter
        Specified by:
        contains in interface Counter<T>
        Parameters:
        item - item to check
        Returns:
        True if item is in the counter, false otherwise
      • copy

        public Counter<T> copy()
        Description copied from interface: Copyable

        Makes a copy of this object.

        Specified by:
        copy in interface Copyable<T>
        Returns:
        A copy of this object.
      • divideBySum

        public Counter<T> divideBySum()
        Description copied from interface: Counter
        Divides the values in the counter by the sum and sets the sum to 1.0
        Specified by:
        divideBySum in interface Counter<T>
        Returns:
        the counter
      • entries

        public Set<Map.Entry<T,​Double>> entries()
        Description copied from interface: Counter
        A set of object - double entries making up the counter
        Specified by:
        entries in interface Counter<T>
        Returns:
        the set of entries
      • filterByKey

        public Counter<T> filterByKey​(Predicate<? super T> predicate)
        Description copied from interface: Counter
        Creates a new counter containing only those items that evaluate true for the given predicate
        Specified by:
        filterByKey in interface Counter<T>
        Parameters:
        predicate - the predicate to use to filter the keys
        Returns:
        A new counter containing only those items that evaluate true for the given predicate
      • filterByValue

        public Counter<T> filterByValue​(DoublePredicate doublePredicate)
        Description copied from interface: Counter
        Creates a new counter containing only those items whose value evaluate true for the given predicate
        Specified by:
        filterByValue in interface Counter<T>
        Parameters:
        doublePredicate - the predicate to use to filter the values
        Returns:
        A new counter containing only those items whose value evaluate true for the given predicate
      • get

        public double get​(T item)
        Description copied from interface: Counter
        Returns the value for the given item
        Specified by:
        get in interface Counter<T>
        Parameters:
        item - The item we want the count for
        Returns:
        The value of the item or 0 if it is not in the counter.
      • increment

        public Counter<T> increment​(T item,
                                    double amount)
        Description copied from interface: Counter
        Increments the count of the item by a given amount
        Specified by:
        increment in interface Counter<T>
        Parameters:
        item - The item to increment
        amount - The amount to increment
        Returns:
        the counter
      • isEmpty

        public boolean isEmpty()
        Description copied from interface: Counter
        Determines if the counter is empty or not
        Specified by:
        isEmpty in interface Counter<T>
        Returns:
        True if the counter is empty
      • items

        public Set<T> items()
        Description copied from interface: Counter
        The items in the counter
        Specified by:
        items in interface Counter<T>
        Returns:
        The items in the counter
      • itemsByCount

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

        public <R> Counter<R> mapKeys​(Function<? super T,​? extends R> function)
        Description copied from interface: Counter
        Creates a new counter by mapping the items of this counter using the supplied function
        Specified by:
        mapKeys in interface Counter<T>
        Type Parameters:
        R - The component type of the new counter
        Parameters:
        function - the function to use to transform the keys
        Returns:
        A new counter containing only those items that evaluate true for the given predicate
      • merge

        public Counter<T> merge​(Counter<? extends T> other)
        Description copied from interface: Counter
        Merges the counts in one counter with this one.
        Specified by:
        merge in interface Counter<T>
        Parameters:
        other - The other counter to merge.
        Returns:
        the counter
      • merge

        public Counter<T> merge​(Map<? extends T,​? extends Number> other)
        Description copied from interface: Counter
        Merges the counts in a map with this counter.
        Specified by:
        merge in interface Counter<T>
        Parameters:
        other - The other counter to merge.
        Returns:
        the counter
      • newInstance

        protected abstract <R> Counter<R> newInstance()
        New instance counter.
        Type Parameters:
        R - the type parameter
        Returns:
        the counter
      • remove

        public double remove​(T item)
        Description copied from interface: Counter
        Removes an item from the counter
        Specified by:
        remove in interface Counter<T>
        Parameters:
        item - The item to remove
        Returns:
        the count of the removed item
      • removeAll

        public Counter<T> removeAll​(Iterable<T> items)
        Description copied from interface: Counter
        Removes all the given items from the counter
        Specified by:
        removeAll in interface Counter<T>
        Parameters:
        items - The items to remove
        Returns:
        the counter
      • set

        public Counter<T> set​(T item,
                              double count)
        Description copied from interface: Counter
        Sets the value of an item in the counter
        Specified by:
        set in interface Counter<T>
        Parameters:
        item - The item
        count - The count
        Returns:
        the counter
      • size

        public int size()
        Description copied from interface: Counter
        The total number of items in the counter
        Specified by:
        size in interface Counter<T>
        Returns:
        The number of items in the counter
      • sum

        public double sum()
        Description copied from interface: Counter
        The sum of values in the counter
        Specified by:
        sum in interface Counter<T>
        Returns:
        The sum of the counts in the counter
      • topN

        public Counter<T> topN​(int n)
        Description copied from interface: Counter
        Creates a new counter containing the N items with highest values
        Specified by:
        topN in interface Counter<T>
        Parameters:
        n - the number of items desired
        Returns:
        a counter containing the N items with highest values from this counter
      • values

        public Collection<Double> values()
        Description copied from interface: Counter
        The values associated with the items in the counter
        Specified by:
        values in interface Counter<T>
        Returns:
        The values of the items in the counter.