Class Counter


  • public class Counter
    extends Object
    A counter keeps track of the number of occurrences of numbers. Two numbers are considered the same if they are close enough by a user specified number of decimal points.
    • Constructor Detail

      • Counter

        public Counter()
        Construct a counter with no rounding. Two numbers are considered the same if they have the same binary representations.
      • Counter

        public Counter​(int scale)
        Construct a counter. Two numbers are considered the same if they are close enough by a number of decimal points.
        Parameters:
        scale - a precision in terms of the number of decimal points
    • Method Detail

      • add

        public void add​(double number)
        Add a number to the counter.
        Parameters:
        number - a double
      • add

        public void add​(double... numbers)
        Add numbers to the counter.
        Parameters:
        numbers - doubles
      • count

        public int count​(double number)
        Get the count, i.e., the number of occurrences, of a particular number. If the counter has not seen the number before, it returns 0.
        Parameters:
        number - a number
        Returns:
        the count
      • keySet

        public Set<Double> keySet()
        Get the set of numbers the counter has seen.
        Returns:
        a set of seen numbers