1 11 12 package org.eclipse.ui.internal.gestures; 13 14 import java.util.Arrays ; 15 16 import org.eclipse.ui.internal.util.Util; 17 18 public final class CaptureEvent implements Comparable { 19 20 private final static int HASH_FACTOR = 89; 21 private final static int HASH_INITIAL = 22 CaptureEvent.class.getName().hashCode(); 23 24 public static CaptureEvent create(int data, int pen, Point[] points) { 25 return new CaptureEvent(data, pen, points); 26 } 27 28 private int data; 29 private int pen; 30 private Point[] points; 31 32 private CaptureEvent(int data, int pen, Point[] points) { 33 super(); 34 this.data = data; 35 this.pen = pen; 36 37 if (points == null) 38 throw new NullPointerException (); 39 40 points = (Point[]) points.clone(); 41 42 for (int i = 0; i < points.length; i++) 43 if (points[i] == null) 44 throw new IllegalArgumentException (); 45 46 this.points = points; 47 } 48 49 public int compareTo(Object object) { 50 CaptureEvent castedObject = (CaptureEvent) object; 51 int compareTo = data - castedObject.data; 52 53 if (compareTo == 0) { 54 compareTo = pen - castedObject.pen; 55 56 if (compareTo == 0) 57 compareTo = Util.compare(points, castedObject.points); 58 } 59 60 return compareTo; 61 } 62 63 public boolean equals(Object object) { 64 if (!(object instanceof CaptureEvent)) 65 return false; 66 67 CaptureEvent castedObject = (CaptureEvent) object; 68 return data == castedObject.data 69 && pen == castedObject.pen 70 && Arrays.equals(points, castedObject.points); 71 } 72 73 public int getData() { 74 return data; 75 } 76 77 public int getPen() { 78 return pen; 79 } 80 81 public Point[] getPoints() { 82 return (Point[]) points.clone(); 83 } 84 85 public int hashCode() { 86 int result = HASH_INITIAL; 87 result = result * HASH_FACTOR + data; 88 result = result * HASH_FACTOR + pen; 89 90 for (int i = 0; i < points.length; i++) 91 result = result * HASH_FACTOR + points[i].hashCode(); 92 93 return result; 94 } 95 } 96 | Popular Tags |