1 11 12 package org.eclipse.ui.internal.gestures; 13 14 public final class Point implements Comparable { 15 16 private final static int HASH_FACTOR = 89; 17 private final static int HASH_INITIAL = Point.class.getName().hashCode(); 18 19 private transient int hashCode; 20 private transient boolean hashCodeComputed; 21 private transient String string; 22 23 private int x; 24 private int y; 25 26 public Point(int x, int y) { 27 this.x = x; 28 this.y = y; 29 } 30 31 public int compareTo(Object object) { 32 Point castedObject = (Point) object; 33 int compareTo = x - castedObject.x; 34 35 if (compareTo == 0) 36 compareTo = y - castedObject.y; 37 38 return compareTo; 39 } 40 41 public boolean equals(Object object) { 42 if (!(object instanceof Point)) 43 return false; 44 45 Point castedObject = (Point) object; 46 boolean equals = true; 47 equals &= x == castedObject.x; 48 equals &= y == castedObject.y; 49 return equals; 50 } 51 52 public int getX() { 53 return x; 54 } 55 56 public int getY() { 57 return y; 58 } 59 60 public int hashCode() { 61 if (!hashCodeComputed) { 62 hashCode = HASH_INITIAL; 63 hashCode = hashCode * HASH_FACTOR + x; 64 hashCode = hashCode * HASH_FACTOR + y; 65 hashCodeComputed = true; 66 } 67 68 return hashCode; 69 } 70 71 public String toString() { 72 if (string == null) { 73 final StringBuffer stringBuffer = new StringBuffer (); 74 stringBuffer.append('['); 75 stringBuffer.append(x); 76 stringBuffer.append(','); 77 stringBuffer.append(y); 78 stringBuffer.append(']'); 79 string = stringBuffer.toString(); 80 } 81 82 return string; 83 } 84 } 85 | Popular Tags |