mae.tut.num
Class Factory

java.lang.Object
  extended bymae.tut.num.Factory

public class Factory
extends java.lang.Object

Defines static methods to construct Numbers.

Factory methods for constructing Whole, Rational, Decimal, Complex.

These methods are preferred to the constructors, because they select the proper constructor depending on the arguments.


Method Summary
static Cruncher cruncher()
          Returns Cruncher instance for calculation on Numbers
static Number newComplex(float re, float im)
          Factory method that constructs a Complex, a Decimal or a Whole.
static Number newDecimal(float x)
          Factory method that constructs a Decimal or a Whole.
static Number newMatrix(float a, float b, float c, float d)
          Factory method that constructs a Matrix.
static Number newRational(long num, long den)
          Factory method that constructs a Rational or a Whole.
static Number newWhole(long n)
          Factory method that constructs a Whole.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

cruncher

public static Cruncher cruncher()
Returns Cruncher instance for calculation on Numbers


newWhole

public static Number newWhole(long n)
Factory method that constructs a Whole.

This is equivalant to new Whole(n).


newRational

public static Number newRational(long num,
                                 long den)
Factory method that constructs a Rational or a Whole.

If den==gcd(num,den), a Whole is returned.


newDecimal

public static Number newDecimal(float x)
Factory method that constructs a Decimal or a Whole.

If String value of x ends with ".0", x represents an integer, a Whole is returned.


newComplex

public static Number newComplex(float re,
                                float im)
Factory method that constructs a Complex, a Decimal or a Whole.

If im==0, newDecimal() is invoked.


newMatrix

public static Number newMatrix(float a,
                               float b,
                               float c,
                               float d)
Factory method that constructs a Matrix.