Package dev.nm.combinatorics
Class Counter
- java.lang.Object
-
- dev.nm.combinatorics.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.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(double number)
Add a number to the counter.void
add(double... numbers)
Add numbers to the counter.int
count(double number)
Get the count, i.e., the number of occurrences, of a particular number.Set<Double>
keySet()
Get the set of numbers the counter has seen.
-
-
-
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
- adouble
-
add
public void add(double... numbers)
Add numbers to the counter.- Parameters:
numbers
-double
s
-
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
-
-