SuanShu, a Java numerical and statistical library

com.numericalmethod.suanshu.number
Class Counter

java.lang.Object
  extended by com.numericalmethod.suanshu.number.Counter

public class Counter
extends java.lang.Object

This class counts the number of repeated numbers.

Two numbers are considered the same if they are close enough, rounded to a user specified number of decimal points.


Field Summary
 int scale
          a precision parameter for rounding a double: number of decimal points to keep
 
Constructor Summary
Counter()
          Construct an instance of Counter.
Counter(int scale)
          Construct an instance of Counter.
 
Method Summary
 void add(double... numbers)
          Add more doubles to the counter.
 void add(double number)
          Add a new double to the counter.
 int count(double number)
          Get the counts, i.e., the number of repetitions, for a particular double.
 java.util.Set<java.lang.Double> keySet()
          Get the set of numbers the counter has seen.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

scale

public final int scale
a precision parameter for rounding a double: number of decimal points to keep

Constructor Detail

Counter

public Counter()
Construct an instance of Counter.

No rounding.


Counter

public Counter(int scale)
Construct an instance of Counter.

Round the doubles to scale number of decimal points.

Parameters:
scale - number of decimal points
Method Detail

add

public void add(double number)
Add a new double to the counter.

Parameters:
number - a double

add

public void add(double... numbers)
Add more doubles to the counter.

Parameters:
numbers - doubles

count

public int count(double number)
Get the counts, i.e., the number of repetitions, for a particular double.

If the counter has not see the number, it returns 0.

Parameters:
number - a double
Returns:
the counts

keySet

public java.util.Set<java.lang.Double> keySet()
Get the set of numbers the counter has seen.

Returns:
a set of Double

SuanShu, a Java numerical and statistical library

Copyright © 2011 Numerical Method Inc. Ltd. All Rights Reserved.