visad.data.in
Class ArithProg

java.lang.Object
  extended by visad.data.in.ArithProg
Direct Known Subclasses:
LonArithProg

public class ArithProg
extends Object

Provides support for determining if a sequence of numeric values corresponds to an arithmetic progression and, if so, the progression parameters.

Author:
Steven R. Emmerson

Field Summary
protected  double dEps
           
protected  double fEps
           
protected  double first
           
protected  boolean isConsistent
           
protected  double last
           
protected  double meanDel
           
protected  long n
           
 
Constructor Summary
ArithProg()
           
 
Method Summary
 boolean accumulate(double value)
          Accumulates a value.
 boolean accumulate(double[] values)
          Accumulates a set of doubles.
 boolean accumulate(float value)
          Accumulates a value.
 boolean accumulate(float[] values)
          Accumulates a set of floats.
 double getCommonDifference()
          Gets the current common difference.
 double getFirst()
          Gets the first value.
 double getLast()
          Returns the "last" value accumulated.
 long getNumber()
          Gets the number of values.
 boolean isConsistent()
          Indicates whether or not the sequence so far is consistent with an arithmetic progression.
static void main(String[] args)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

n

protected long n

first

protected double first

last

protected double last

meanDel

protected double meanDel

isConsistent

protected boolean isConsistent

fEps

protected final double fEps
See Also:
Constant Field Values

dEps

protected final double dEps
See Also:
Constant Field Values
Constructor Detail

ArithProg

public ArithProg()
Method Detail

accumulate

public boolean accumulate(float[] values)
                   throws VisADException
Accumulates a set of floats. Indicates whether or not the sequence is consistent with the arithmetic progression so far.

Parameters:
values - The values to accumulate.
Returns:
False if the difference between any current and previous value normalized by the current increment differs from unity by more than the nearness threshold; otherwise, true.
Throws:
VisADException - isConsistent() was false before this method was invoked.
Precondition:
isConsistent() is true.
Postcondition:
A subsequent getNumber() will return values.length more than previously if the function returns true., A subsequent getLast() will return the value argument if the function returns true.

accumulate

public boolean accumulate(double[] values)
                   throws VisADException
Accumulates a set of doubles. Indicates whether or not the sequence is consistent with the arithmetic progression so far.

Parameters:
values - The values to accumulate.
Returns:
False if the difference between any current and previous value normalized by the current increment differs from unity by more than the nearness threshold; otherwise, true.
Throws:
VisADException - isConsistent() was false before this method was invoked.
Precondition:
isConsistent() is true.
Postcondition:
A subsequent getNumber() will return values.length more than previously if the function returns true., A subsequent getLast() will return the value argument if the function returns true.

accumulate

public final boolean accumulate(float value)
                         throws VisADException
Accumulates a value. Indicate whether or not the value is consistent with the arithmetic progression so far.

Parameters:
value - The value to accumulate.
Returns:
False if the difference between any current and previous value normalized by the current increment differs from unity by more than the nearness threshold; otherwise, true.
Throws:
VisADException - The sequence isn't an arithmetic progression.
Precondition:
isConsistent() is true.
Postcondition:
A subsequent getNumber() will return values.length more than previously if the function returns true., A subsequent getLast() will return the value argument if the function returns true.

accumulate

public final boolean accumulate(double value)
                         throws VisADException
Accumulates a value. Indicate whether or not the value is consistent with the arithmetic progression so far.

Parameters:
value - The value to accumulate.
Returns:
False if the difference between any current and previous value normalized by the current increment differs from unity by more than the nearness threshold; otherwise, true.
Throws:
VisADException - The sequence isn't an arithmetic progression.
Precondition:
isConsistent() is true.
Postcondition:
A subsequent getNumber() will return values.length more than previously if the function returns true., A subsequent getLast() will return the value argument if the function returns true.

isConsistent

public final boolean isConsistent()
Indicates whether or not the sequence so far is consistent with an arithmetic progression.

Returns:
true if and only if the sequence of values seen so far is consistent with an arithmetic progression.

getNumber

public final long getNumber()
                     throws VisADException
Gets the number of values. Only meaningfull if isConsistent() is true.

Returns:
The number of values accumulated so far.
Throws:
VisADException - The sequence isn't an arithmetic progression.
Requirements:
isConsistent() is true.

getFirst

public final double getFirst()
                      throws VisADException
Gets the first value.

Returns:
The first accumulated value.
Throws:
VisADException - The sequence isn't an arithmetic progression.
Requirements:
isConsistent() is true.

getLast

public final double getLast()
                     throws VisADException
Returns the "last" value accumulated. It is only meaningfull if isConsistent is true.

Returns:
The last accumulated value.
Throws:
VisADException - The sequence isn't an arithmetic progression.

getCommonDifference

public final double getCommonDifference()
                                 throws VisADException
Gets the current common difference. Only meaningfull if isConsistent() is true.

Returns:
The computed common difference so far.
Throws:
VisADException - The sequence isn't an arithmetic progression.
Requirements:
isConsistent() is true.

main

public static void main(String[] args)
                 throws Exception
Throws:
Exception