public final class RationalImpl extends Number implements Rational, Serializable, XMLSerializable, Cloneable, Comparable<Rational>
Implements a rational number by means of a Java integer numerator (Int32) and a
Java integer (Int32) denominator.
This implementation of the AAF rational number interface extends Java's Number
class so that its integer and floating point value can be found, by methods such as intValue()
and doubleValue(). Numerical comparison with other numbers can take place using the
compareToNumber(Number) method.
| Modifier and Type | Field and Description |
|---|---|
static String |
MYSQL_COLUMN_DEFINITION |
| Constructor and Description |
|---|
RationalImpl()
Create a rational number with a numerator of 0 and a denominator of 1.
|
RationalImpl(int numerator,
int denominator)
Create a rational number from its numerator and denominator.
|
| Modifier and Type | Method and Description |
|---|---|
void |
appendXMLChildren(Node parent)
Append extra child elements to the given parent node to serialize the value of an object
to an XML fragment.
|
Rational |
clone()
Create a cloned copy of this rational value.
|
int |
compareTo(Rational o)
Numerically compare this rational with the given rational value.
|
int |
compareToNumber(Number n)
Numerically compare this value with another number.
|
double |
doubleValue()
Returns the rational calculated as double value.
|
boolean |
equals(Object o)
Tests to see if this rational value is equal to the given value.
|
float |
floatValue()
Returns the rational calculated as float value.
|
static Rational |
fromPersistentForm(String rational) |
String |
getComment()
Include a comment when serializing a value to XML.
|
int |
getDenominator()
Returns the denominator of the value represented by this rational number.
|
int |
getNumerator()
Returns the numerator of the value represented by this rational number.
|
int |
hashCode() |
int |
intValue()
Calculates the integer value of the numerator divided by the denominator.
|
long |
longValue()
Calculates the long value corresponding to the numerator devided by the
denominator.
|
static RationalImpl |
parseFactory(String rationalAsString)
Convert a string representation of a rational value into a value of this type.
|
void |
setDenominator(int denominator)
Sets the denominator of the value represented by this rational number.
|
void |
setNumerator(int numerator)
Sets the numerator of the value represented by this rational number.
|
void |
setRational(int numerator,
int denominator)
Set the value of this rational number with both its numerator and denominator.
|
static String |
toPersistentForm(Rational rational) |
String |
toString()
Returns a string representation of this rational value as the numerator, followed by a
slash (/), followed by the denominator.
|
byteValue, shortValuepublic static final String MYSQL_COLUMN_DEFINITION
public RationalImpl(@Int32 int numerator, @Int32 int denominator)
Create a rational number from its numerator and denominator.
numerator - denominator - public RationalImpl()
Create a rational number with a numerator of 0 and a denominator of 1.
public static final RationalImpl parseFactory(String rationalAsString) throws NullPointerException, ParseException
Convert a string representation of a rational value into a value of this type.
The string representation is expected to take the form of the numerator, followed
by a slash character ('/'), followed by the denominator, e.g.
"-123/4567".
rationalAsString - String to use to create a rational value.NullPointerException - The rational as string argument is null.PraseException - The string is not formatted as a rational number
representation.ParseExceptiontoString()@Int32 public final int getDenominator()
RationalReturns the denominator of the value represented by this rational number.
getDenominator in interface Rationalpublic final void setDenominator(@Int32 int denominator)
RationalSets the denominator of the value represented by this rational number.
setDenominator in interface Rationaldenominator - Denominator part of the rational value.@Int32 public final int getNumerator()
RationalReturns the numerator of the value represented by this rational number.
getNumerator in interface Rationalpublic final void setNumerator(@Int32 int numerator)
RationalSets the numerator of the value represented by this rational number.
setNumerator in interface Rationalnumerator - Numerator part of the rational value.public final void setRational(@Int32 int numerator, @Int32 int denominator)
RationalSet the value of this rational number with both its numerator and denominator.
setRational in interface Rationalnumerator - Numerator part of the rational value.denominator - Denominator part of the rational value.public final boolean equals(Object o)
Tests to see if this rational value is equal to the given value. Two values
are equals if and only if they are both rational values with the same numerator
and denominator. For a numerical comparison, use
compareTo(tv.amwa.maj.record.Rational).
equals in class ObjectObject.equals(java.lang.Object)public final String toString()
Returns a string representation of this rational value as the numerator, followed by a
slash (/), followed by the denominator. For example, "1/4". The format is the same as that
parsed by parseFactory(String).
toString in interface RationaltoString in class ObjectparseFactory(String)public final double doubleValue()
Returns the rational calculated as double value. In the event of a division by
zero, a value of Double.POSITIVE_INFINITY is returned.
doubleValue in interface RationaldoubleValue in class NumberNumber.doubleValue()public final float floatValue()
Returns the rational calculated as float value. In the event of a division by
zero, a value of Float.POSITIVE_INFINITY is returned.
floatValue in class NumberNumber.floatValue()public final int intValue()
throws ArithmeticException
Calculates the integer value of the numerator divided by the denominator. If
the magnitude of the numerator is less than the denominator, a value of
0 is returned.
intValue in class NumberArithmeticException - The denominator is zero.Number.intValue()public final long longValue()
throws ArithmeticException
Calculates the long value corresponding to the numerator devided by the
denominator. If the magnitude of the numerator is less than the denominator, a
value of 0 is returned.
longValue in class NumberArithmeticException - The denominator is 0.Number.longValue()public final int compareTo(Rational o) throws NullPointerException
Numerically compare this rational with the given rational value.
compareTo in interface Comparable<Rational>o - Value to compare with this one with.-1 if this value is less than the one given,
1 if this value is greater than the one given and 0 if
they are equal.NullPointerException - Argument is null.Comparable.compareTo(Object)public final int compareToNumber(Number n) throws NullPointerException
Numerically compare this value with another number.
n - Number to compare with this one.-1 if this value is less than the one given,
1 if this value is greater than the one given and 0 if
they are equal.NullPointerException - Argument is null.public final Rational clone()
RationalCreate a cloned copy of this rational value.
public void appendXMLChildren(Node parent)
XMLSerializableAppend extra child elements to the given parent node to serialize the value of an object
to an XML fragment. Methods of the XMLBuilder class are provided to help with this
process.
appendXMLChildren in interface XMLSerializableparent - XML parent element to append child nodes to.public String getComment()
XMLSerializableInclude a comment when serializing a value to XML. The comment will be inserted as the first child node of the element representing the class.
getComment in interface XMLSerializable(c)2007-2016 Richard Cartwright, all rights reserved. Licensed under Apache 2 license and subject to the AMWA IPR policy.