I have one class having two variables named as `x` and `y`. In this class I have overrided the `equals` and `hashCode` methods to compare two object of this class. But our requirement is to compare two object of this class sometimes on the basis of `x` and sometimes on the basis of `y`. Is it possible dynamically in Java?

Edit:
 I have one more class named as B, in this class there is two method m1 and m2 and I want to compare the above class object in such a way that when we call from m1 (for sorting) the above objects will be compared on the basis of x (means compare object by compare x variable) and when we call from m2 (for sorting) then we compare according to y.