EDU.oswego.cs.dl.util.concurrent.misc

Class Fraction

public class Fraction extends Object implements Cloneable, Comparable, Serializable

An immutable class representing fractions as pairs of longs. Fractions are always maintained in reduced form.
Field Summary
protected longdenominator_
protected longnumerator_
Constructor Summary
Fraction(long num, long den)
Create a Fraction equal in value to num / den *
Fraction(Fraction f)
Create a fraction with the same value as Fraction f *
Method Summary
doubleasDouble()
Return the value of the Fraction as a double *
Objectclone()
intcompareTo(Object other)
return a number less, equal, or greater than zero reflecting whether this Fraction is less, equal or greater than the value of Fraction other.
intcompareTo(long n)
return a number less, equal, or greater than zero reflecting whether this Fraction is less, equal or greater than n.
longdenominator()
Return the denominator *
FractiondividedBy(Fraction b)
return a Fraction representing this Fraction divided by b *
FractiondividedBy(long n)
return a Fraction representing this Fraction divided by n *
booleanequals(Object other)
booleanequals(long n)
static longgcd(long a, long b)
Compute the nonnegative greatest common divisor of a and b.
inthashCode()
Fractioninverse()
return a Fraction representing 1 / this Fraction *
Fractionminus(Fraction b)
return a Fraction representing this Fraction minus b *
Fractionminus(long n)
return a Fraction representing this Fraction minus n *
Fractionnegative()
return a Fraction representing the negated value of this Fraction *
longnumerator()
Return the numerator *
Fractionplus(Fraction b)
return a Fraction representing this Fraction plus b *
Fractionplus(long n)
return a Fraction representing this Fraction plus n *
Fractiontimes(Fraction b)
return a Fraction representing this Fraction times b *
Fractiontimes(long n)
return a Fraction representing this Fraction times n *
StringtoString()

Field Detail

denominator_

protected final long denominator_

numerator_

protected final long numerator_

Constructor Detail

Fraction

public Fraction(long num, long den)
Create a Fraction equal in value to num / den *

Fraction

public Fraction(Fraction f)
Create a fraction with the same value as Fraction f *

Method Detail

asDouble

public double asDouble()
Return the value of the Fraction as a double *

clone

public Object clone()

compareTo

public int compareTo(Object other)
return a number less, equal, or greater than zero reflecting whether this Fraction is less, equal or greater than the value of Fraction other.

compareTo

public int compareTo(long n)
return a number less, equal, or greater than zero reflecting whether this Fraction is less, equal or greater than n.

denominator

public final long denominator()
Return the denominator *

dividedBy

public Fraction dividedBy(Fraction b)
return a Fraction representing this Fraction divided by b *

dividedBy

public Fraction dividedBy(long n)
return a Fraction representing this Fraction divided by n *

equals

public boolean equals(Object other)

equals

public boolean equals(long n)

gcd

public static long gcd(long a, long b)
Compute the nonnegative greatest common divisor of a and b. (This is needed for normalizing Fractions, but can be useful on its own.)

hashCode

public int hashCode()

inverse

public Fraction inverse()
return a Fraction representing 1 / this Fraction *

minus

public Fraction minus(Fraction b)
return a Fraction representing this Fraction minus b *

minus

public Fraction minus(long n)
return a Fraction representing this Fraction minus n *

negative

public Fraction negative()
return a Fraction representing the negated value of this Fraction *

numerator

public final long numerator()
Return the numerator *

plus

public Fraction plus(Fraction b)
return a Fraction representing this Fraction plus b *

plus

public Fraction plus(long n)
return a Fraction representing this Fraction plus n *

times

public Fraction times(Fraction b)
return a Fraction representing this Fraction times b *

times

public Fraction times(long n)
return a Fraction representing this Fraction times n *

toString

public String toString()