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-gwt Show documentation
Show all versions of xapi-gwt Show documentation
This module exists solely to package all other gwt modules into a single
uber jar. This makes deploying to non-mavenized targets much easier.
Of course, you would be wise to inherit your dependencies individually;
the uber jar is intended for projects like collide,
which have complex configuration, and adding many jars would be a pain.
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;
}
}