org.jaitools.numeric
Class AbstractProcessor

java.lang.Object
  extended by org.jaitools.numeric.AbstractProcessor
All Implemented Interfaces:
Processor
Direct Known Subclasses:
ApproxMedianProcessor, ExactMedianProcessor, ExtremaProcessor, MeanVarianceProcessor, SumProcessor

public abstract class AbstractProcessor
extends Object
implements Processor

Abstract base class for statistics processors used with StreamingSampleStats.

Since:
1.0
Version:
$Id$
Author:
Michael Bedward, Daniele Romagnoli, GeoSolutions S.A.S.

Field Summary
protected  long numAccepted
          Number of samples accepted.
protected  long numNaN
          Number of NaN samples offered.
protected  long numNoData
          Number of NODATA samples offered.
protected  long numOffered
          Number of samples offered.
 
Constructor Summary
AbstractProcessor()
          Default constructor.
AbstractProcessor(Range.Type rangesType)
          Creates a new processor with specified use of Ranges.
 
Method Summary
 void addNoDataRange(Range<Double> noData)
          Sets a range of values to be considered as NoData.
 void addNoDataValue(Double noData)
          Convenience method to specify a single value to be considered as NoData.
 void addRange(Range<Double> range)
          Sets a range of values to exclude from or include in from calculations.
 void addRange(Range<Double> range, Range.Type rangesType)
          Sets a range of values to exclude from or include in calculations.
 Map<Statistic,Double> get()
          Gets the value of all statistics calculated by this processor.
 List<Range<Double>> getNoDataRanges()
          Gets the ranges of sample values to be considered as NoData.
 long getNumAccepted()
          Gets the number of samples that have been accepted by this processor (ie.
 long getNumNaN()
          Gets the number of NaN samples passed to the processor
 long getNumNoData()
          Gets the number of NoData samples passed to the processor.
 long getNumOffered()
          Gets the number of samples that have been offered to this processor.
 List<Range<Double>> getRanges()
          Gets the Ranges of sample values excluded from/included in calculations.
 Range.Type getRangesType()
          Gets the type of ranges being used by this processor.
 boolean isAccepted(Double sample)
          Tests whether a sample value will be accepted for calculations by the processor.
 void offer(Double sample)
          Offers a sample value to the processor.
 void setRangesType(Range.Type rangesType)
          Sets the type of the ranges to be added to the processor.
protected abstract  boolean update(Double sample)
          Processes a sample value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jaitools.numeric.Processor
get, getSupported
 

Field Detail

numOffered

protected long numOffered
Number of samples offered.


numAccepted

protected long numAccepted
Number of samples accepted.


numNaN

protected long numNaN
Number of NaN samples offered.


numNoData

protected long numNoData
Number of NODATA samples offered.

Constructor Detail

AbstractProcessor

public AbstractProcessor()
Default constructor.


AbstractProcessor

public AbstractProcessor(Range.Type rangesType)
Creates a new processor with specified use of Ranges.

Parameters:
rangesType - normally either Range.Type.INCLUDE to indicate that Ranges will define values to operate on, or Range.Type.EXCLUDE when Ranges will define values to exclude from operations.
Method Detail

addNoDataRange

public void addNoDataRange(Range<Double> noData)
Sets a range of values to be considered as NoData. Processors count the number of NoData values offered as samples but exclude them from calculations.

NoData ranges take precedence over included / excluded data ranges.

Specified by:
addNoDataRange in interface Processor
Parameters:
noData - a range of values to be excluded

addNoDataValue

public void addNoDataValue(Double noData)
Convenience method to specify a single value to be considered as NoData.

Specified by:
addNoDataValue in interface Processor
Parameters:
noData - the value to be treated as NoData
See Also:
Processor.addNoDataRange(org.jaitools.numeric.Range)

getNumOffered

public final long getNumOffered()
Gets the number of samples that have been offered to this processor.

Specified by:
getNumOffered in interface Processor
Returns:
number of samples offered

getNumAccepted

public final long getNumAccepted()
Gets the number of samples that have been accepted by this processor (ie. contributed to the calculations).

Specified by:
getNumAccepted in interface Processor
Returns:
number of samples used for calculations

getNumNaN

public long getNumNaN()
Gets the number of NaN samples passed to the processor

Specified by:
getNumNaN in interface Processor
Returns:
number of NaN samples

offer

public void offer(Double sample)
Offers a sample value to the processor.

Specified by:
offer in interface Processor
Parameters:
sample - the sample value

get

public Map<Statistic,Double> get()
Gets the value of all statistics calculated by this processor.

Specified by:
get in interface Processor
Returns:
the calculated statistic(s)

update

protected abstract boolean update(Double sample)
Processes a sample value.

Parameters:
sample - the sample value
Returns:
true if the sample is accepted; false otherwise

addRange

public void addRange(Range<Double> range)
Sets a range of values to exclude from or include in from calculations. Ie. if a sample value in this range is offered it will be ignored or accepted with the behavior depending on which range type has been set previously.

Specified by:
addRange in interface Processor
Parameters:
range - the range

addRange

public void addRange(Range<Double> range,
                     Range.Type rangesType)
Sets a range of values to exclude from or include in calculations. Note that you can only add ranges of the same type to a Processor.

Specified by:
addRange in interface Processor
Parameters:
range - the range
rangesType - the type of range

getRanges

public List<Range<Double>> getRanges()
Gets the Ranges of sample values excluded from/included in calculations.

Specified by:
getRanges in interface Processor
Returns:
the Ranges or an empty list if no ranges are defined

getNoDataRanges

public List<Range<Double>> getNoDataRanges()
Gets the ranges of sample values to be considered as NoData.

Specified by:
getNoDataRanges in interface Processor
Returns:
the NoData Ranges or an empty list if no NoData are defined

setRangesType

public void setRangesType(Range.Type rangesType)
Sets the type of the ranges to be added to the processor. It is worth to point out that this method can be called only one time in case the rangesType haven't been specified at construction time and no ranges have been added yet.

Specified by:
setRangesType in interface Processor
Parameters:
rangesType - the type of range.

getRangesType

public final Range.Type getRangesType()
Gets the type of ranges being used by this processor.

Specified by:
getRangesType in interface Processor
Returns:
the rangesType of this processor

isAccepted

public boolean isAccepted(Double sample)
Tests whether a sample value will be accepted for calculations by the processor.

Specified by:
isAccepted in interface Processor
Parameters:
sample - the sample value
Returns:
true if the sample is accepted in compliance with the ranges settings. false otherwise

getNumNoData

public long getNumNoData()
Gets the number of NoData samples passed to the processor. This count includes values in user-specified NoData ranges as well as Double.NaN values.

Specified by:
getNumNoData in interface Processor
Returns:
number of NoData samples
See Also:
Processor.addNoDataRange(org.jaitools.numeric.Range), Processor.addNoDataValue(java.lang.Double)


Copyright © 2009-2013. All Rights Reserved.