KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > gestures > Point


1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.ui.internal.gestures;
13
14 public final class Point implements Comparable JavaDoc {
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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc toString() {
72         if (string == null) {
73             final StringBuffer JavaDoc stringBuffer = new StringBuffer JavaDoc();
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