xapi.util.impl.ComparablePair Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of xapi-dev Show documentation
Show all versions of xapi-dev Show documentation
Everything needed to run a comprehensive dev environment.
Just type X_ and pick a service from autocomplete;
new dev modules will be added as they are built.
The only dev service not included in the uber jar is xapi-dev-maven,
as it includes all runtime dependencies of maven, adding ~4 seconds to build time,
and 6 megabytes to the final output jar size (without xapi-dev-maven, it's ~1MB).
The newest version!
package xapi.util.impl;
import xapi.util.api.Pair;
/**
* A pair which implements comparable, using both components as comparable objects.
*
* It allows you to define whether to compare x before y (slot 0 or 1), or vice versa.
* This is useful in graphical mapping, where you may want to sort a map horizontally or vertically.
*
* @author "James X. Nelson ([email protected])"
*
* @param
* @param
*/
public class ComparablePair ,Y extends Comparable>
implements Pair,Comparable>{
private X x;
private Y y;
public ComparablePair() {
}
public ComparablePair(X x,Y y) {
set0(x);
set1(y);
}
@Override
public int compareTo(ComparablePair o) {
X _x = o.get0();
Y _y = o.get1();
final int dX, dY;
if (x == null) {
if (_x != null) {
return 1;
}
dX = 0;
} else {
if (_x == null) {
return -1;
}
dX = x.compareTo(_x);
}
if (y == null) {
if (_y != null) {
return 1;
}
dY = 0;
} else {
if (_y == null) {
return -1;
}
dY = y.compareTo(_y);
}
return dX ^ dY;
}
@Override
public X get0() {
return x;
}
@Override
public Y get1() {
return y;
}
@Override
public void set0(X x) {
this.x=x;
}
@Override
public void set1(Y y) {
this.y=y;
}
}