001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_testing/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, final double z) { 058 ord = new double[] { x, y, z }; 059 } 060 061 /** 062 * Returns a hash value for this coordinate. This value need not remain 063 * consistent between different implementations of the same class. 064 */ 065 public int hashCode() { 066 long code = 326145729; 067 if (ord != null) { 068 for (int i = ord.length; --i >= 0;) 069 code = code * 37 + Double.doubleToLongBits(ord[i]); 070 } 071 return (int) (code >>> 32) ^ (int) code; 072 } 073 074 /** 075 * Compares the specified object with this coordinate for equality. 076 */ 077 public boolean equals(final Object object) { 078 if (object != null && getClass().equals(object.getClass())) { 079 final PT_CoordinatePoint that = (PT_CoordinatePoint) object; 080 if (false) { 081 return Arrays.equals(this.ord, that.ord); 082 /* 083 * NOTE: The 'Arrays.equals(double[],double[])' method does not 084 * exists in JDK 1.1. If compatibility with JDK 1.1 is wanted, 085 * use the code below instead. 086 */ 087 } 088 089 if (this.ord == that.ord) 090 return true; 091 if (this.ord != null && that.ord != null) { 092 if (this.ord.length == that.ord.length) { 093 for (int i = ord.length; --i >= 0;) 094 if (Double.doubleToLongBits(this.ord[i]) != Double 095 .doubleToLongBits(that.ord[i])) 096 return false; 097 return true; 098 } 099 } 100 } 101 return false; 102 } 103 104 /** 105 * Returns a deep copy of this coordinate. 106 */ 107 public Object clone() { 108 try { 109 return super.clone(); 110 } catch (CloneNotSupportedException exception) { 111 // Should not happen, since we are cloneable. 112 throw new InternalError(exception.getMessage()); 113 } 114 } 115 116 /** 117 * Returns a string representation of this coordinate. The returned string 118 * is implementation dependent. It is usually provided for debugging 119 * purposes only. 120 */ 121 public String toString() { 122 final StringBuffer buffer = new StringBuffer("PT_CoordinatePoint"); 123 buffer.append('['); 124 if (ord != null) { 125 for (int i = 0; i < ord.length; i++) { 126 if (i != 0) 127 buffer.append(", "); 128 buffer.append(ord[i]); 129 } 130 } 131 buffer.append(']'); 132 return buffer.toString(); 133 } 134 }/* ******************************************************************** 135 Changes to this class. What the people have been up to: 136 $Log$ 137 Revision 1.3 2006/07/13 06:28:31 poth 138 comment footer added 139 140 ********************************************************************** */