Debian Codegraph @

src/dr/app/gui/chart/XY.java

raw symbols SCIP
1 package dr.app.gui.chart;
2
3 /**
4 * make x and y together as the key of map
5 *
6 * @author Walter Xie
7 */
8 public class XY implements Comparable<XY> {
9 final double x, y;
10
11 XY(double x, double y) {
12 this.x = x;
13 this.y = y;
14 }
15
16 public boolean equals(Object o){
17 if(this==o)return true;
18 if(o==null)return false;
19 if(o instanceof XY){
20 XY xy = (XY)o;
21 return this.x==xy.x && this.y==xy.y;
22 }
23 return false;
24 }
25
26 public int hashCode(){
27 return (int) (x * 31 + y);
28 }
29
30 //http://stackoverflow.com/questions/9307751/override-compareto-and-sort-using-two-strings
31 @Override
32 public int compareTo(final XY o) {
33 int cmp = Double.compare(this.x, o.x);
34 if (cmp == 0) cmp = Double.compare(this.y, o.y);
35 return cmp;
36 }
37
38 // public String toString() {
39 // return Double.toString(x) + "|" + Double.toString(y);
40 // }
41 }