001: /* ===========================================================
002: * JFreeChart : a free chart library for the Java(tm) platform
003: * ===========================================================
004: *
005: * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors.
006: *
007: * Project Info: http://www.jfree.org/jfreechart/index.html
008: *
009: * This library is free software; you can redistribute it and/or modify it
010: * under the terms of the GNU Lesser General Public License as published by
011: * the Free Software Foundation; either version 2.1 of the License, or
012: * (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but
015: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
016: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
017: * License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
022: * USA.
023: *
024: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
025: * in the United States and other countries.]
026: *
027: * -----------------
028: * XYCoordinate.java
029: * -----------------
030: * (C) Copyright 2007, by Object Refinery Limited and Contributors.
031: *
032: * Original Author: David Gilbert (for Object Refinery Limited);
033: * Contributor(s): -;
034: *
035: * $Id: XYCoordinate.java,v 1.1.2.1 2007/05/25 14:44:38 mungady Exp $
036: *
037: * Changes
038: * -------
039: * 30-Jan-2007 : Version 1 (DG);
040: * 25-May-2007 : Moved from experimental to the main source tree (DG);
041: *
042: */
043:
044: package org.jfree.data.xy;
045:
046: import java.io.Serializable;
047:
048: /**
049: * Represents an (x, y) coordinate.
050: *
051: * @since 1.0.6
052: */
053: public class XYCoordinate implements Comparable, Serializable {
054:
055: /** The x-coordinate. */
056: private double x;
057:
058: /** The y-coordinate. */
059: private double y;
060:
061: /**
062: * Creates a new coordinate for the point (0.0, 0.0).
063: */
064: public XYCoordinate() {
065: this (0.0, 0.0);
066: }
067:
068: /**
069: * Creates a new coordinate for the point (x, y).
070: *
071: * @param x the x-coordinate.
072: * @param y the y-coordinate.
073: */
074: public XYCoordinate(double x, double y) {
075: this .x = x;
076: this .y = y;
077: }
078:
079: /**
080: * Returns the x-coordinate.
081: *
082: * @return The x-coordinate.
083: */
084: public double getX() {
085: return this .x;
086: }
087:
088: /**
089: * Returns the y-coordinate.
090: *
091: * @return The y-coordinate.
092: */
093: public double getY() {
094: return this .y;
095: }
096:
097: /**
098: * Tests this coordinate for equality with an arbitrary object.
099: *
100: * @param obj the object (<code>null</code> permitted).
101: *
102: * @return A boolean.
103: */
104: public boolean equals(Object obj) {
105: if (obj == this ) {
106: return true;
107: }
108: if (!(obj instanceof XYCoordinate)) {
109: return false;
110: }
111: XYCoordinate that = (XYCoordinate) obj;
112: if (this .x != that.x) {
113: return false;
114: }
115: if (this .y != that.y) {
116: return false;
117: }
118: return true;
119: }
120:
121: /**
122: * Returns a hash code for this instance.
123: *
124: * @return A hash code.
125: */
126: public int hashCode() {
127: int result = 193;
128: long temp = Double.doubleToLongBits(this .x);
129: result = 37 * result + (int) (temp ^ (temp >>> 32));
130: temp = Double.doubleToLongBits(this .y);
131: result = 37 * result + (int) (temp ^ (temp >>> 32));
132: return result;
133: }
134:
135: /**
136: * Returns a string representation of this instance, primarily for
137: * debugging purposes.
138: *
139: * @return A string.
140: */
141: public String toString() {
142: return "(" + this .x + ", " + this .y + ")";
143: }
144:
145: /**
146: * Compares this instance against an arbitrary object.
147: *
148: * @param obj the object (<code>null</code> not permitted).
149: *
150: * @return An integer indicating the relative order of the items.
151: */
152: public int compareTo(Object obj) {
153: if (!(obj instanceof XYCoordinate)) {
154: throw new IllegalArgumentException("Incomparable object.");
155: }
156: XYCoordinate that = (XYCoordinate) obj;
157: if (this .x > that.x) {
158: return 1;
159: } else if (this .x < that.x) {
160: return -1;
161: } else {
162: if (this .y > that.y) {
163: return 1;
164: } else if (this .y < that.y) {
165: return -1;
166: }
167: }
168: return 0;
169: }
170:
171: }
|