package rebelsky.newvec; /** * Something that knows how to compare vectors based on their * radius. */ public class CompareVectorsByRadius { public int compare(Object alpha, Object beta) { double alphaRadius = alpha.getRadius(); double betaRadius = beta.getRadius(); if (Math.abs(alphaRadius - betaRadius) < .000001) return 0; else if (alphaRadius < betaRadius) return -1; else return 1; } // int compare(Object, Object) /* public boolean equals(Object other) { // Strategy: Try some sample vectors. // Strategy: If both are objects in class CompareVectorsByRadius, // they are both equal. If not, they're not. return other instanceof CompareVectorByRadius; // Strategy: Don't bother to write equals at all. Java will use // the default. } // equals(Object) */ } // class CompareVectorsByRadius