(for examplewe can compare the distances of and from the originthusfor the most general and reusable form of priority queuewe should not rely on the keys to provide their comparison rules insteadwe use special comparator objects that are external to the keys to supply the comparison rules comparator is an object that compares two keys we assume that priority queue is given comparator when is constructedand we might also imagine the ability of priority queue to be given new comparator if its old one ever becomes "out of date when needs to compare two keysit uses the comparator it was given to perform the comparison thusa programmer can write general priority queue implementation that works correctly in wide variety of contexts the comparator adt formallythe comparator adt provides streamlined comparison mechanismbased on single method that takes two keys and compares them (or reports an error if the keys are incomparable)compare( , ):returns an integer such that if bi if band if ban error occurs if and cannot be compared the standard java interface java util comparator corresponds to the comparator adt abovewhich offers generaldynamic reusable way to compare objects it also includes an equals(method for comparing comparator to other comparators in code fragment we provide an example of comparatorfor two-dimensional points (code fragment )which is also an example of the composition pattern code fragment comparator for twodimensional points based on the lexicographic order