Package net.sf.jga.fn.arithmetic

Provides simple arithmetic Functors for Number classes.

See:
          Description

Interface Summary
Arithmetic<T extends Number> Defines arithmetic operations for classes derived from Number.
Average.Visitor Interface for classes that may interpret an Average functor.
BitwiseAnd.Visitor Interface for classes that may interpret a BitwiseAnd functor.
BitwiseNot.Visitor Interface for classes that may interpret a BitwiseNot functor.
BitwiseOr.Visitor Interface for classes that may interpret a BitwiseOr functor.
BitwiseXor.Visitor Interface for classes that may interpret a BitwiseXor functor.
Divides.Visitor Interface for classes that may interpret a Divides functor.
IntegerArithmetic<T extends Number> Defines arithmetic operations appropriate for Integral Numbers.
Minus.Visitor Interface for classes that may interpret a Minus functor.
Modulus.Visitor Interface for classes that may interpret a Modulus functor.
Multiplies.Visitor Interface for classes that may interpret a Multiplies functor.
Negate.Visitor Interface for classes that may interpret a Negate functor.
Plus.Visitor Interface for classes that may interpret a Plus functor.
ShiftLeft.Visitor Interface for classes that may interpret a ShiftLeft functor.
ShiftRight.Visitor Interface for classes that may interpret a ShiftRight functor.
UnsignedShiftRight.Visitor Interface for classes that may interpret a UnsignedShiftRight functor.
ValueOf.Visitor Interface for classes that may interpret a ValueOf functor.
 

Class Summary
ArithmeticFactory Builds and distributes implementations of the Arithmetic and IntegerArithmetic interfaces that are available for supported Number classes.
ArithmeticFunctors Static factory methods for the functors in the Comparison package.
Average<T extends Number> Averages numeric values in an iteration.
BitwiseAnd<T extends Number> Binary Functor that returns the bitwise and of its two arguments
BitwiseNot<T extends Number> Unary Functor that returns the bitwise not of its argument
BitwiseOr<T extends Number> Binary Functor that returns the bitwise or of its two arguments
BitwiseXor<T extends Number> Binary Functor that returns the bitwise xor of its two arguments
Divides<T extends Number> Returns the quotient of two numeric arguments.
Minus<T extends Number> Returns the difference of two numeric arguments.
Modulus<T extends Number> Returns the remainder of the division of two integral arguments.
Multiplies<T extends Number> Returns the product of two numeric arguments.
Negate<T extends Number> Returns the negative of its numeric argument.
Plus<T extends Number> Returns the sum of two numeric arguments.
ShiftLeft<T extends Number> Returns the first argument shifted left by the number of places given in the second argument.
ShiftRight<T extends Number> Returns the first argument shifted right by the number of places given in the second argument.
UnsignedShiftRight<T extends Number> Returns the first argument shifted right by the number of places given in the second argument.
ValueOf<T extends Number,R extends Number> Returns the value of its numeric argument, converted to the approprate class.
 

Package net.sf.jga.fn.arithmetic Description

Provides simple arithmetic Functors for Number classes.

Implementation is provided by a set of adaptor objects that implement the Arithmatic interface. Adaptors are provided for all standard Number classes: the six Reference classes in the java.lang package (Byte, Short, Integer, Long, Float, and Double) and the two classes defined in the java.math package (BigInteger and BigDecimal).

To apply the Functors found in this package with user-defined Number implementations, it is necessary to create and register an implementation of Arithmetic or IntegerArithmetic. For example, assuming that a Fraction class has been defined, support for arithmetic operations could be provided by

public class FractionMath implements Arithmetic<Fraction> {
    public Fraction plus (Fraction x, Fraction y) {
        // implementation omitted
    }
    ...
}

Before any Functors can be built using the Fraction class, it is necessary to register the FractionMath implementation with the ArithmeticFactory.

ArithmeticFactory.register(Fraction.class, new FractionMath());



Copyright © 2002-2006 David A. Hall. All Rights Reserved.