001: //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/trunk/src/org/opengis/pt/PT_CoordinatePoint.java $
002: /*
003: * OpenGIS� Coordinate Transformation Services Implementation Specification
004: * Copyright (2001) OpenGIS consortium
005: *
006: * THIS COPYRIGHT NOTICE IS A TEMPORARY PATCH. Version 1.00 of official
007: * OpenGIS's interface files doesn't contain a copyright notice yet. This
008: * file is a slightly modified version of official OpenGIS's interface.
009: * Changes have been done in order to fix RMI problems and are documented
010: * on the SEAGIS web site (seagis.sourceforge.net). THIS FILE WILL LIKELY
011: * BE REPLACED BY NEXT VERSION OF OPENGIS SPECIFICATIONS.
012: */
013: package org.opengis.pt;
014:
015: // Various JDK's classes
016: import java.io.Serializable;
017: import java.util.Arrays;
018:
019: /**
020: * A position defined by a list of numbers. The ordinate values are indexed from
021: * 0 to (<code>NumDim-1</code>), where <code>NumDim</code> is the
022: * dimension of the coordinate system the coordinate point belongs in.
023: *
024: * @version 1.01
025: * @since 1.00
026: * @author Martin Daly
027: * @author Martin Desruisseaux
028: */
029: public class PT_CoordinatePoint implements Cloneable, Serializable {
030: /**
031: * Use <code>serialVersionUID</code> from first draft for interoperability
032: * with CSS 1.00.
033: */
034: private static final long serialVersionUID = -5747198890219811554L;
035:
036: /**
037: * The ordinates of the coordinate point.
038: */
039: public double[] ord;
040:
041: /**
042: * Construct an empty coordinate point. Caller must initialize {@link #ord}.
043: */
044: public PT_CoordinatePoint() {
045: }
046:
047: /**
048: * Construct a 2D coordinate from the specified ordinates.
049: */
050: public PT_CoordinatePoint(final double x, final double y) {
051: ord = new double[] { x, y };
052: }
053:
054: /**
055: * Construct a 3D coordinate from the specified ordinates.
056: */
057: public PT_CoordinatePoint(final double x, final double y,
058: final double z) {
059: ord = new double[] { x, y, z };
060: }
061:
062: /**
063: * Returns a hash value for this coordinate. This value need not remain
064: * consistent between different implementations of the same class.
065: */
066: public int hashCode() {
067: long code = 326145729;
068: if (ord != null) {
069: for (int i = ord.length; --i >= 0;)
070: code = code * 37 + Double.doubleToLongBits(ord[i]);
071: }
072: return (int) (code >>> 32) ^ (int) code;
073: }
074:
075: /**
076: * Compares the specified object with this coordinate for equality.
077: */
078: public boolean equals(final Object object) {
079: if (object != null && getClass().equals(object.getClass())) {
080: final PT_CoordinatePoint that = (PT_CoordinatePoint) object;
081: if (false) {
082: return Arrays.equals(this .ord, that.ord);
083: /*
084: * NOTE: The 'Arrays.equals(double[],double[])' method does not
085: * exists in JDK 1.1. If compatibility with JDK 1.1 is wanted,
086: * use the code below instead.
087: */
088: }
089:
090: if (this .ord == that.ord)
091: return true;
092: if (this .ord != null && that.ord != null) {
093: if (this .ord.length == that.ord.length) {
094: for (int i = ord.length; --i >= 0;)
095: if (Double.doubleToLongBits(this .ord[i]) != Double
096: .doubleToLongBits(that.ord[i]))
097: return false;
098: return true;
099: }
100: }
101: }
102: return false;
103: }
104:
105: /**
106: * Returns a deep copy of this coordinate.
107: */
108: public Object clone() {
109: try {
110: return super .clone();
111: } catch (CloneNotSupportedException exception) {
112: // Should not happen, since we are cloneable.
113: throw new InternalError(exception.getMessage());
114: }
115: }
116:
117: /**
118: * Returns a string representation of this coordinate. The returned string
119: * is implementation dependent. It is usually provided for debugging
120: * purposes only.
121: */
122: public String toString() {
123: final StringBuffer buffer = new StringBuffer(
124: "PT_CoordinatePoint");
125: buffer.append('[');
126: if (ord != null) {
127: for (int i = 0; i < ord.length; i++) {
128: if (i != 0)
129: buffer.append(", ");
130: buffer.append(ord[i]);
131: }
132: }
133: buffer.append(']');
134: return buffer.toString();
135: }
136: }/* ********************************************************************
137: Changes to this class. What the people have been up to:
138: $Log$
139: Revision 1.3 2006/07/13 06:28:31 poth
140: comment footer added
141:
142: ********************************************************************** */
|