KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > swt > graphics > Point


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

11 package org.eclipse.swt.graphics;
12
13
14 import org.eclipse.swt.internal.SerializableCompatibility;
15
16 /**
17  * Instances of this class represent places on the (x, y)
18  * coordinate plane.
19  * <p>
20  * The coordinate space for rectangles and points is considered
21  * to have increasing values downward and to the right from its
22  * origin making this the normal, computer graphics oriented notion
23  * of (x, y) coordinates rather than the strict mathematical one.
24  * </p>
25  * <p>
26  * The hashCode() method in this class uses the values of the public
27  * fields to compute the hash value. When storing instances of the
28  * class in hashed collections, do not modify these fields after the
29  * object has been inserted.
30  * </p>
31  * <p>
32  * Application code does <em>not</em> need to explicitly release the
33  * resources managed by each instance when those instances are no longer
34  * required, and thus no <code>dispose()</code> method is provided.
35  * </p>
36  *
37  * @see Rectangle
38  */

39
40 public final class Point implements SerializableCompatibility {
41     
42     /**
43      * the x coordinate of the point
44      */

45     public int x;
46     
47     /**
48      * the y coordinate of the point
49      */

50     public int y;
51     
52     static final long serialVersionUID = 3257002163938146354L;
53     
54 /**
55  * Constructs a new point with the given x and y coordinates.
56  *
57  * @param x the x coordinate of the new point
58  * @param y the y coordinate of the new point
59  */

60 public Point (int x, int y) {
61     this.x = x;
62     this.y = y;
63 }
64
65 /**
66  * Compares the argument to the receiver, and returns true
67  * if they represent the <em>same</em> object using a class
68  * specific comparison.
69  *
70  * @param object the object to compare with this object
71  * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
72  *
73  * @see #hashCode()
74  */

75 public boolean equals (Object JavaDoc object) {
76     if (object == this) return true;
77     if (!(object instanceof Point)) return false;
78     Point p = (Point)object;
79     return (p.x == this.x) && (p.y == this.y);
80 }
81
82 /**
83  * Returns an integer hash code for the receiver. Any two
84  * objects that return <code>true</code> when passed to
85  * <code>equals</code> must return the same value for this
86  * method.
87  *
88  * @return the receiver's hash
89  *
90  * @see #equals(Object)
91  */

92 public int hashCode () {
93     return x ^ y;
94 }
95
96 /**
97  * Returns a string containing a concise, human-readable
98  * description of the receiver.
99  *
100  * @return a string representation of the point
101  */

102 public String JavaDoc toString () {
103     return "Point {" + x + ", " + y + "}"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
104
}
105
106 }
107
108
Popular Tags