gov.sandia.cognition.math
Class RingAccumulator<RingType extends Ring<RingType>>

java.lang.Object
  extended by gov.sandia.cognition.math.RingAccumulator<RingType>
Type Parameters:
RingType - Type of Ring that this object can operate upon

@CodeReviews(reviews={@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 Object

The 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".

Since:
1.0
Author:
Justin Basilico

Constructor Summary
RingAccumulator()
          Creates a new instance of RingAccumulator
RingAccumulator(Iterable<? extends RingType> items)
          Creates a new instance of RingAccumulator, adding all of the given items to start with.
 
Method Summary
 void accumulate(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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RingAccumulator

public RingAccumulator()
Creates a new instance of RingAccumulator


RingAccumulator

public RingAccumulator(Iterable<? extends RingType> items)
Creates a new instance of RingAccumulator, adding all of the given items to start with.

Parameters:
items - The initial set of items to add to the accumulator, throws NullPointerException if null
Method Detail

clear

public void clear()
Clears the accumulator. Resetting the count and sum.


accumulate

public void accumulate(RingType item)
Adds the given object to the accumulation.

Parameters:
item - The object to add to the accumulation, throws NullPointerException if null.

accumulate

public void accumulate(Iterable<? extends RingType> items)
Adds all of the given set of objects onto the accumulation.

Parameters:
items - The objects to add to the accumulation, throws NullPointerException if null

scaleSum

public RingType scaleSum(double scaleFactor)
Returns the sum scaled by the given scale factor.

Parameters:
scaleFactor - The amount to scale the sum by.
Returns:
The sum scaled by the given amount or null if no sum has been defined.

getMean

public RingType getMean()
Computes the mean of the accumulated values.

Returns:
The mean of the accumulated values.

getSum

public RingType getSum()
Returns the sum object underlying the accumulator.

Returns:
The sum of the accumulation.

getCount

public int getCount()
Gets the number of items that have been added to the accumulator.

Returns:
The number of items that have been added to the accumulator.