001: /*******************************************************************************
002: * Copyright (c) 2000, 2005 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.swt.graphics;
011:
012: import org.eclipse.swt.internal.SerializableCompatibility;
013:
014: /**
015: * Instances of this class represent places on the (x, y)
016: * coordinate plane.
017: * <p>
018: * The coordinate space for rectangles and points is considered
019: * to have increasing values downward and to the right from its
020: * origin making this the normal, computer graphics oriented notion
021: * of (x, y) coordinates rather than the strict mathematical one.
022: * </p>
023: * <p>
024: * The hashCode() method in this class uses the values of the public
025: * fields to compute the hash value. When storing instances of the
026: * class in hashed collections, do not modify these fields after the
027: * object has been inserted.
028: * </p>
029: * <p>
030: * Application code does <em>not</em> need to explicitly release the
031: * resources managed by each instance when those instances are no longer
032: * required, and thus no <code>dispose()</code> method is provided.
033: * </p>
034: *
035: * @see Rectangle
036: */
037:
038: public final class Point implements SerializableCompatibility {
039:
040: /**
041: * the x coordinate of the point
042: */
043: public int x;
044:
045: /**
046: * the y coordinate of the point
047: */
048: public int y;
049:
050: static final long serialVersionUID = 3257002163938146354L;
051:
052: /**
053: * Constructs a new point with the given x and y coordinates.
054: *
055: * @param x the x coordinate of the new point
056: * @param y the y coordinate of the new point
057: */
058: public Point(int x, int y) {
059: this .x = x;
060: this .y = y;
061: }
062:
063: /**
064: * Compares the argument to the receiver, and returns true
065: * if they represent the <em>same</em> object using a class
066: * specific comparison.
067: *
068: * @param object the object to compare with this object
069: * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
070: *
071: * @see #hashCode()
072: */
073: public boolean equals(Object object) {
074: if (object == this )
075: return true;
076: if (!(object instanceof Point))
077: return false;
078: Point p = (Point) object;
079: return (p.x == this .x) && (p.y == this .y);
080: }
081:
082: /**
083: * Returns an integer hash code for the receiver. Any two
084: * objects that return <code>true</code> when passed to
085: * <code>equals</code> must return the same value for this
086: * method.
087: *
088: * @return the receiver's hash
089: *
090: * @see #equals(Object)
091: */
092: public int hashCode() {
093: return x ^ y;
094: }
095:
096: /**
097: * Returns a string containing a concise, human-readable
098: * description of the receiver.
099: *
100: * @return a string representation of the point
101: */
102: public String toString() {
103: return "Point {" + x + ", " + y + "}"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
104: }
105:
106: }
|