org.norther.tammi.acorn.math
Class Equation

java.lang.Object
  extended by java.lang.Number
      extended by org.norther.tammi.acorn.math.Equation
All Implemented Interfaces:
Serializable, Comparable<Number>
Direct Known Subclasses:
Average, Product, Sum

public abstract class Equation
extends Number
implements Comparable<Number>

A numeric equation.

Version:
$Id: Equation.java,v 1.1 2009/12/09 19:57:54 cvsimp Exp $
Author:
Ilkka Priha
See Also:
Serialized Form

Constructor Summary
Equation(boolean ignoreNaNs, double... operands)
          Constructs a new double equation.
Equation(boolean ignoreNaNs, float... operands)
          Constructs a new float equation.
Equation(byte... operands)
          Constructs a new byte equation.
Equation(double... operands)
          Constructs a new double equation.
Equation(float... operands)
          Constructs a new float equation.
Equation(int... operands)
          Constructs a new int equation.
Equation(long... operands)
          Constructs a new long equation.
Equation(short... operands)
          Constructs a new short equation.
 
Method Summary
 byte byteValue()
           
 byte byteValue(int index)
          Gets the indexed byte operand.
protected abstract  Number calculate(Object operands, int length, boolean ignoreNaNs)
          Calculates the result.
 int compareTo(Number number)
           
 double doubleValue()
           
 double doubleValue(int index)
          Gets the indexed double operand.
 boolean equals(Object other)
           
 float floatValue()
           
 float floatValue(int index)
          Gets the indexed float operand.
 int getLength()
          Gets the length of the equation.
 Class<?> getOperandType()
          Gets the type of operands.
 Number getResult()
          Gets the result.
 int intValue()
           
 int intValue(int index)
          Gets the indexed int operand.
protected  boolean isFloatingPoint(Object operands)
          Checks whether the operands are floating point numbers.
 long longValue()
           
 long longValue(int index)
          Gets the indexed long operand.
 short shortValue()
           
 short shortValue(int index)
          Gets the indexed short operand.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Equation

public Equation(byte... operands)
Constructs a new byte equation.

Parameters:
operands - the operands.

Equation

public Equation(short... operands)
Constructs a new short equation.

Parameters:
operands - the operands.

Equation

public Equation(int... operands)
Constructs a new int equation.

Parameters:
operands - the operands.

Equation

public Equation(long... operands)
Constructs a new long equation.

Parameters:
operands - the operands.

Equation

public Equation(float... operands)
Constructs a new float equation.

Parameters:
operands - the operands.

Equation

public Equation(boolean ignoreNaNs,
                float... operands)
Constructs a new float equation.

Parameters:
ignoreNaNs - ignore NaNs if true.
operands - the operands.

Equation

public Equation(double... operands)
Constructs a new double equation.

Parameters:
operands - the operands.

Equation

public Equation(boolean ignoreNaNs,
                double... operands)
Constructs a new double equation.

Parameters:
ignoreNaNs - ignore NaNs if true.
operands - the operands.
Method Detail

getResult

public Number getResult()
Gets the result.

Returns:
the result.

getOperandType

public Class<?> getOperandType()
Gets the type of operands.

Returns:
the operand class type.

getLength

public int getLength()
Gets the length of the equation.

Returns:
the number of operands.

byteValue

public byte byteValue(int index)
Gets the indexed byte operand.

Parameters:
index - the index.
Returns:
the byte operand.

shortValue

public short shortValue(int index)
Gets the indexed short operand.

Parameters:
index - the index.
Returns:
the short operand.

intValue

public int intValue(int index)
Gets the indexed int operand.

Parameters:
index - the index.
Returns:
the int operand.

longValue

public long longValue(int index)
Gets the indexed long operand.

Parameters:
index - the index.
Returns:
the long operand.

floatValue

public float floatValue(int index)
Gets the indexed float operand.

Parameters:
index - the index.
Returns:
the float operand.

doubleValue

public double doubleValue(int index)
Gets the indexed double operand.

Parameters:
index - the index.
Returns:
the double operand.

byteValue

public byte byteValue()
Overrides:
byteValue in class Number

shortValue

public short shortValue()
Overrides:
shortValue in class Number

intValue

public int intValue()
Specified by:
intValue in class Number

longValue

public long longValue()
Specified by:
longValue in class Number

floatValue

public float floatValue()
Specified by:
floatValue in class Number

doubleValue

public double doubleValue()
Specified by:
doubleValue in class Number

toString

public String toString()
Overrides:
toString in class Object

equals

public boolean equals(Object other)
Overrides:
equals in class Object

compareTo

public int compareTo(Number number)
Specified by:
compareTo in interface Comparable<Number>

isFloatingPoint

protected boolean isFloatingPoint(Object operands)
Checks whether the operands are floating point numbers.

Parameters:
operands - the operands.
Returns:
true for floating point, false otherwise.

calculate

protected abstract Number calculate(Object operands,
                                    int length,
                                    boolean ignoreNaNs)
Calculates the result.

Parameters:
operands - an array of operands.
length - the number of operands.
ignoreNaNs - ignore NaNs if true.
Returns:
the result of the equation.


Copyright © 2004 The Norther Organization. All rights reserved.