Provides simple arithmetic Functors for Number classes.
See: Description
Interface Summary | |
---|---|
Arithmetic<T> | Defines arithmetic operations for classes derived from Number. |
Divides.Visitor | Interface for classes that may interpret a Divides functor. |
IntegerArithmetic<T> | 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. |
Class Summary | |
---|---|
ArithmeticFactory | Builds and distributes implementations of the Arithmetic and IntegerArithmetic interfaces that are available for supported Number classes. |
Divides<T> | Returns the quotient of two numeric arguments. |
Minus<T> | Returns the difference of two numeric arguments. |
Modulus<T> | Returns the remainder of the division of two integral arguments. |
Multiplies<T> | Returns the product of two numeric arguments. |
Negate<T> | Returns the negative of its numeric argument. |
Plus<T> | Returns the sum of two numeric arguments. |
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());