
/** please see pg 212 of your textbook for Comparator info */ 


public class IntegerComparator implements Comparator {
    private int num1, num2;

    private void getXY(Object a, Object b) {
        if (a == null || b == null)
            throw new InvalidElementException("Null Argument");
        try {
            Integer i1 = (Integer)a;
            Integer i2 = (Integer)b;
            num1 = i1.intValue();
            num2 = i2.intValue();
        } catch(ClassCastException e) {
            throw new InvalidElementException("Argument not an Integer");
        }
    }

    public boolean isLessThan(Object a, Object b) {
        getXY(a,b);
        return (num1 < num2);
    }

    public boolean isLessThanOrEqualTo(Object a, Object b) {
        getXY(a,b);
        return (num1 <= num2);
    }

    public boolean isEqualTo(Object a, Object b) {
        getXY(a,b);
        return (num1 == num2);
    }

    public boolean isGreaterThan(Object a, Object b) {
        getXY(a,b);
        return (num1 > num2);
    }

    public boolean isGreaterThanOrEqualTo(Object a, Object b) {
        getXY(a,b);
        return (num1 >= num2);
    }

    public boolean isComparable(Object a) {
        if (a == null)
            return false;
        else {
            try {
                Integer i1 = (Integer)a;
            } catch(ClassCastException e) {
                return false;
            }
        }
        return true;
    }
}  // end class IntegerComparator


