|
Media Authoring with Java API |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.lang.Number tv.amwa.maj.embeddable.Rational
public final class 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.
TypeDefinitionRecord.Rational
,
TimelineMobSlot.getEditRate()
,
Serialized FormConstructor Summary | |
---|---|
Rational()
Create a rational number with a numerator of 0 and a denominator of 1. |
|
Rational(int numerator,
int denominator)
Create a rational number from its numerator and denominator. |
Method Summary | |
---|---|
void |
appendXMLChildren(Node parent)
Append child elements to the given parent node to serialize the value of an object to an XML fragment. |
static Rational |
castFromInterface(Rational alien)
Cast a tv.amwa.maj.record.Rational
value from the generic interface to this implementation of
the interface. |
Rational |
clone()
Creates a cloned deep copy of this embeddable 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. |
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()
Returns a hash code value for this embeddable object. |
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 Rational |
parseRational(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 |
setPropertiesFromInterface(Rational castFrom)
Set the properties of this value from those available in the given value, which is specified by the rational value interface. |
void |
setRational(int numerator,
int denominator)
Set the value of this rational number with both its numerator and denominator. |
String |
toString()
Returns a string representation of this rational value as the numerator, followed by a slash (/), followed by the denominator. |
Methods inherited from class java.lang.Number |
---|
byteValue, shortValue |
Methods inherited from class java.lang.Object |
---|
getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Rational(@Int32 int numerator, @Int32 int denominator)
Create a rational number from its numerator and denominator.
numerator
- denominator
- public Rational()
Create a rational number with a numerator of 0 and a denominator of 1.
Method Detail |
---|
public static final Rational parseRational(String rationalAsString) throws NullPointerException, NumberFormatException
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
.
NumberFormatException
- The string is not formatted as a rational number
representation.toString()
public static final Rational castFromInterface(Rational alien) throws NullPointerException
Cast a tv.amwa.maj.record.Rational
value from the generic interface to this implementation of
the interface. If the given value is not this
MAJ API implementation, a copy will be instantiated of this type and with an equivalent
value.
alien
- A potentially alien implementation of an instance of the Rational
interface.
NullPointerException
- The given alien rational value is null
.setPropertiesFromInterface(tv.amwa.maj.record.Rational)
public final void setPropertiesFromInterface(Rational castFrom) throws NullPointerException
Set the properties of this value from those available in the given value, which is specified by the rational value interface.
castFrom
- Value to extract properties from.
NullPointerException
- The given value to use to set this value is null
.castFromInterface(tv.amwa.maj.record.Rational)
@Int32 public final int getDenominator()
Rational
Returns the denominator of the value represented by this rational number.
getDenominator
in interface Rational
public final void setDenominator(@Int32 int denominator)
Rational
Sets the denominator of the value represented by this rational number.
setDenominator
in interface Rational
denominator
- Denominator part of the rational value.@Int32 public final int getNumerator()
Rational
Returns the numerator of the value represented by this rational number.
getNumerator
in interface Rational
public final void setNumerator(@Int32 int numerator)
Rational
Sets the numerator of the value represented by this rational number.
setNumerator
in interface Rational
numerator
- Numerator part of the rational value.public final void setRational(@Int32 int numerator, @Int32 int denominator)
Rational
Set the value of this rational number with both its numerator and denominator.
setRational
in interface Rational
numerator
- Numerator part of the rational value.denominator
- Denominator part of the rational value.public final int hashCode()
MAJCommon
Returns a hash code value for this embeddable object.
hashCode
in interface MAJCommon
hashCode
in class Object
Object.hashCode()
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 interface MAJCommon
equals
in class Object
o
- Object to test for equality with.
Object.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 parseRational(String)
.
toString
in interface MAJCommon
toString
in class Object
parseRational(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 class Number
Number.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 Number
Number.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 Number
ArithmeticException
- 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 Number
ArithmeticException
- 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()
MAJCommon
Creates a cloned deep copy of this embeddable value. The clone will be initialized to have the same value as this value but exists independently from then on. Changes to this value will not effect the clone and changes to the clone will not effect this. MAJ API clones are true deep clones with no shared references to areas of memory within the original.
This method does not throw a CloneNotSupportedException
as all
embeddable values must implement the Cloneable
interface.
clone
in interface MAJCommon
clone
in class Object
Object.clone()
public void appendXMLChildren(Node parent)
XMLSerializable
Append 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 XMLSerializable
parent
- XML parent element to append child nodes to.
|
Media Authoring with Java API |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |