package org.psjava.math.ns;

import org.psjava.javautil.EqualityTester;
import org.psjava.javautil.StrictEqualityTester;


public class Fraction<T> implements EqualityTester<Fraction<T>> {
	
	public static <T> Fraction<T> valueOf(T numerator, T denominator) {
		// cache? difficult because of generic. :(
		return new Fraction<T>(numerator, denominator);
	}

	public final T numerator;
	public final T denominator;
	
	private Fraction(T numerator, T denominator) {
		this.numerator = numerator;
		this.denominator = denominator;
	}

	@Override
	public String toString() {
		return numerator + "/" + denominator;
	}
	
	@Override
	public boolean equals(Object obj) {
		return StrictEqualityTester.areEqual(this, obj, this);
	}

	@Override
	public boolean areEqual(Fraction<T> o1, Fraction<T> o2) {
		return o1.numerator.equals(o2.numerator) && o1.denominator.equals(o2.denominator);
	}

	@Override
	public int hashCode() {
		return numerator.hashCode() ^ denominator.hashCode();
	}
	
}

@@ -561,24 +561,130 @@
 oString() %7B%0A
+%09%09String denom = denominator.toString();%0A%09%09if (denom.equals(%221%22))%0A%09%09%09return numerator.toString();%0A%09%09else%0A%09
 %09%09return num
@@ -699,30 +699,24 @@
  %22/%22 + denom
-inator
 ;%0A%09%7D%0A%09%0A%09@Ove

improve tostring