Сравнение комплексных чисел
Листинг 6.6. Сравнение комплексных чисел
import java.util.*;
class ComplexCompare implements Comparator{
public int compare(Object objl, Object obj2){
Complex zl = (Complex)objl, z2 = (Complex)obj2;
double rel = zl.getReO, iml = zl.getlm();
double re2 = z2.getRe(), im2 = z2.getlm();
if (rel != re2) return (int)(rel - re2);
else if (iml != im2) return (int)(iml — im2);
else return 0;
}
public boolean equals(Object z) {
return compare(this, z) == 0;
}
}