RingType
- Type of Ring that this object can operate upon@CodeReview(reviewer="Kevin R. Dixon",date="2008-02-26",changesNeeded=false,comments="Looks good.") @CodeReview(reviewer="Jonathan McClain",date="2006-05-16",changesNeeded=true,comments="A few minor changes.",response=@CodeReviewResponse(respondent="Justin Basilico",date="2006-05-16",moreChangesNeeded=false,comments="Minor updates based on comments.")) public class RingAccumulator<RingType extends Ring<RingType>> extends java.lang.Object
RingAccumulator
class implements a simple object that
is used to accumulate objects that implement the Ring interface. This
provides an easy way to compute sums or means of Ring objects by simply
adding them to the accumulator.
Note that if nothing is added to the accumulator, the results returned
will be null because it will not be given a default object to use to
start at "zero".Constructor and Description |
---|
RingAccumulator()
Creates a new instance of RingAccumulator
|
RingAccumulator(java.lang.Iterable<? extends RingType> items)
Creates a new instance of RingAccumulator, adding all of the given
items to start with.
|
Modifier and Type | Method and Description |
---|---|
void |
accumulate(java.lang.Iterable<? extends RingType> items)
Adds all of the given set of objects onto the accumulation.
|
void |
accumulate(RingType item)
Adds the given object to the accumulation.
|
void |
clear()
Clears the accumulator.
|
int |
getCount()
Gets the number of items that have been added to the accumulator.
|
RingType |
getMean()
Computes the mean of the accumulated values.
|
RingType |
getSum()
Returns the sum object underlying the accumulator.
|
RingType |
scaleSum(double scaleFactor)
Returns the sum scaled by the given scale factor.
|
public RingAccumulator()
public RingAccumulator(java.lang.Iterable<? extends RingType> items)
items
- The initial set of items to add to the accumulator,
throws NullPointerException if nullpublic void clear()
public void accumulate(RingType item)
item
- The object to add to the accumulation,
throws NullPointerException if null.public void accumulate(java.lang.Iterable<? extends RingType> items)
items
- The objects to add to the accumulation,
throws NullPointerException if nullpublic RingType scaleSum(double scaleFactor)
scaleFactor
- The amount to scale the sum by.public RingType getMean()
public RingType getSum()
public int getCount()