com.twelvemonkeys.imageio.metadata.exif
Class Rational

java.lang.Object
  extended by java.lang.Number
      extended by com.twelvemonkeys.imageio.metadata.exif.Rational
All Implemented Interfaces:
Serializable, Comparable<Rational>

public final class Rational
extends Number
implements Comparable<Rational>

Represents a rational number with a long numerator and long denominator. Rational numbers are stored in reduced form with the sign stored with the numerator. Rationals are immutable.

Adapted from sample code featured in "Intro to Programming in Java: An Interdisciplinary Approach" (Addison Wesley) by Robert Sedgewick and Kevin Wayne. Permission granted to redistribute under BSD license.

Version:
$Id: Rational.java,v 1.0 Nov 18, 2009 1:12:00 AM haraldk Exp$
Author:
Harald Kuhr, Robert Sedgewick and Kevin Wayne (original version), last modified by $Author: haraldk$
See Also:
Serialized Form

Constructor Summary
Rational(long pNumber)
           
Rational(long pNumerator, long pDenominator)
           
 
Method Summary
 int compareTo(Rational pOther)
           
 long denominator()
           
 Rational divides(Rational pOther)
           
 double doubleValue()
           
 boolean equals(Object pOther)
           
 float floatValue()
           
 int hashCode()
           
 int intValue()
           
 long longValue()
           
 Rational minus(Rational pOther)
           
 Rational negate()
           
 long numerator()
           
 Rational plus(Rational pOther)
           
 Rational reciprocal()
           
 Rational times(Rational pOther)
           
 String toString()
           
 
Methods inherited from class java.lang.Number
byteValue, shortValue
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Rational

public Rational(long pNumber)

Rational

public Rational(long pNumerator,
                long pDenominator)
Method Detail

numerator

public long numerator()

denominator

public long denominator()

intValue

public int intValue()
Specified by:
intValue in class Number

longValue

public long longValue()
Specified by:
longValue in class Number

floatValue

public float floatValue()
Specified by:
floatValue in class Number

doubleValue

public double doubleValue()
Specified by:
doubleValue in class Number

compareTo

public int compareTo(Rational pOther)
Specified by:
compareTo in interface Comparable<Rational>

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object pOther)
Overrides:
equals in class Object

toString

public String toString()
Overrides:
toString in class Object

times

public Rational times(Rational pOther)

plus

public Rational plus(Rational pOther)

negate

public Rational negate()

minus

public Rational minus(Rational pOther)

reciprocal

public Rational reciprocal()

divides

public Rational divides(Rational pOther)


Copyright © 2015. All Rights Reserved.