com.bigzip.plugin.support
Class Ratio

java.lang.Object
  |
  +--java.lang.Number
        |
        +--com.bigzip.plugin.support.Ratio
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable

public class Ratio
extends java.lang.Number
implements java.lang.Cloneable

The Ratio class wraps a value of a fraction made in an object. An object of type ratio contains a two fields, a numerator and denominator whose type inherits from number.

Since:
BPDK1.0
See Also:
Serialized Form

Field Summary
static Ratio INFINITY_LIMIT
          The largest reciprocal value of type ratio.
static Ratio MAX_VALUE
          The largest value of type ratio.
static Ratio MIN_VALUE
          The smallest value of type ratio.
static Ratio ONE_VALUE
          The value for which type ratio.
static Ratio UNDEFINED
          The value for which type ratio.
static Ratio ZERO_LIMIT
          The smallest reciprocal value of type ratio.
static Ratio ZERO_VALUE
          The value for which type ratio.
 
Constructor Summary
Ratio(java.lang.Number numerator)
          Creates an instance of ratio with the value of numerator / 1.
Ratio(java.lang.Number numerator, java.lang.Number denominator)
          Creates an instance of ratio with the value of numerator / denominator.
 
Method Summary
 java.lang.Object clone()
          Creates and returns a copy of this object and values stored.
 int compareTo(java.lang.Object object)
          Compares this Ratio to another Object.
 double doubleValue()
          Returns the double value of this Ratio.
 boolean equals(Ratio ratio)
          Returns the result of comparing this Ratio's numerator and denominator with the Ratio parsed.
 float floatValue()
          Returns the float value of this Ratio.
 java.lang.Number getDenominator()
          Provides access to the denominator.
 java.lang.Number getNumerator()
          Provides access to the numerator.
 Ratio getReciprocal()
          Returns the reciprocal of the current instance of ratio.
 int intValue()
          Returns the integer value of this Ratio.
 boolean isInfinity()
          Checks to see if the numerator and denominator satifies an infinity result.
 boolean isUndefined()
          Checks to see if the numerator and denominator satifies an undefined result.
 boolean isZero()
          Checks to see if the numerator and denominator satifies a zero result.
 long longValue()
          Returns the long value of this Ratio.
 void reciprocal()
          The reciprocal of the current values are stored in the current object.
 void setDenominator(java.lang.Number number)
          Allocates a new denominator.
 void setNumerator(java.lang.Number number)
          Allocates a new numerator.
 java.lang.String toString()
          Returns the string equivalent of the numerator and denominator.
 
Methods inherited from class java.lang.Number
byteValue, shortValue
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ZERO_VALUE

public static final transient Ratio ZERO_VALUE
The value for which type ratio. is 0. The constant value of this field is (0 / 1).

ONE_VALUE

public static final transient Ratio ONE_VALUE
The value for which type ratio. is 1. The constant value of this field is (1 / 1).

MIN_VALUE

public static final transient Ratio MIN_VALUE
The smallest value of type ratio. The constant value of this field is -2147483648.

MAX_VALUE

public static final transient Ratio MAX_VALUE
The largest value of type ratio. The constant value of this field is 2147483647.

ZERO_LIMIT

public static final transient Ratio ZERO_LIMIT
The smallest reciprocal value of type ratio. The constant value of this field is (1 / -2147483648).

INFINITY_LIMIT

public static final transient Ratio INFINITY_LIMIT
The largest reciprocal value of type ratio. The constant value of this field is (1 / 2147483647).

UNDEFINED

public static final transient Ratio UNDEFINED
The value for which type ratio. is undefiend. The constant value of this field is (0 / 1).
Constructor Detail

Ratio

public Ratio(java.lang.Number numerator)
Creates an instance of ratio with the value of numerator / 1.
Parameters:
numerator - the numerator part of the fraction.

Ratio

public Ratio(java.lang.Number numerator,
             java.lang.Number denominator)
Creates an instance of ratio with the value of numerator / denominator.
Parameters:
numerator - the numerator part of the fraction.
denominator - the demoniator part of the fraction.
Method Detail

getNumerator

public java.lang.Number getNumerator()
Provides access to the numerator.
Returns:
numerator part of the fraction.

setNumerator

public void setNumerator(java.lang.Number number)
Allocates a new numerator.
Parameters:
number - the new numerator part of the fraction.

getDenominator

public java.lang.Number getDenominator()
Provides access to the denominator.
Returns:
denominator part of the fraction.

setDenominator

public void setDenominator(java.lang.Number number)
Allocates a new denominator.
Parameters:
number - the new denominator part of the fraction.

clone

public java.lang.Object clone()
Creates and returns a copy of this object and values stored.
Overrides:
clone in class java.lang.Object
Returns:
an exact copy of this object and values.

intValue

public int intValue()
Returns the integer value of this Ratio.
Overrides:
intValue in class java.lang.Number
Returns:
the ratio value represented by this object is converted to type int and the result of the conversion is returned.

longValue

public long longValue()
Returns the long value of this Ratio.
Overrides:
longValue in class java.lang.Number
Returns:
the ratio value represented by this object is converted to type long and the result of the conversion is returned.

floatValue

public float floatValue()
Returns the float value of this Ratio.
Overrides:
floatValue in class java.lang.Number
Returns:
the ratio value represented by this object is converted to type float and the result of the conversion is returned.

doubleValue

public double doubleValue()
Returns the double value of this Ratio.
Overrides:
doubleValue in class java.lang.Number
Returns:
the ratio value represented by this object is converted to type double and the result of the conversion is returned.

reciprocal

public void reciprocal()
The reciprocal of the current values are stored in the current object.

getReciprocal

public Ratio getReciprocal()
Returns the reciprocal of the current instance of ratio.
Returns:
the reciprocal of the ratio.

compareTo

public int compareTo(java.lang.Object object)
              throws java.lang.Exception
Compares this Ratio to another Object. If the Object is a Ratio, this function behaves like compareTo(Ratio). Otherwise, it throws a ClassCastException (as Doubles are comparable only to other Doubles).
Parameters:
object - the Object to be compared.
Returns:
the value 0 if the argument is a Double numerically equal to this Double; a value less than 0 if the argument is a Double numerically greater than this Double; and a value greater than 0 if the argument is a Double numerically less than this Double.
Throws:
ClassCastException - if the argument is not a Ratio.

equals

public boolean equals(Ratio ratio)
Returns the result of comparing this Ratio's numerator and denominator with the Ratio parsed.
Returns:
true if the object has an identical numerator and denominator, otherwise false.

isUndefined

public boolean isUndefined()
Checks to see if the numerator and denominator satifies an undefined result.
Returns:
true if the numerator and denominator satifies an undefined result, otherwise false.

isZero

public boolean isZero()
Checks to see if the numerator and denominator satifies a zero result.
Returns:
true if the numerator and denominator satifies a zero result, otherwise false.

isInfinity

public boolean isInfinity()
Checks to see if the numerator and denominator satifies an infinity result.
Returns:
true if the numerator and denominator satifies an infinity result, otherwise false.

toString

public java.lang.String toString()
Returns the string equivalent of the numerator and denominator.
Overrides:
toString in class java.lang.Object
Returns:
the string equivalent in the form of "(numerator / denominator)".