[569] | 1 | /* |
---|
| 2 | * $Id: SoTPoint.java,v 1.6 2003/08/22 23:02:40 dwd Exp $ |
---|
| 3 | * |
---|
| 4 | * This software is provided by NOAA for full, free and open release. It is |
---|
| 5 | * understood by the recipient/user that NOAA assumes no liability for any |
---|
| 6 | * errors contained in the code. Although this software is released without |
---|
| 7 | * conditions or restrictions in its use, it is expected that appropriate |
---|
| 8 | * credit be given to its author and to the National Oceanic and Atmospheric |
---|
| 9 | * Administration should the software be included by the recipient as an |
---|
| 10 | * element in other product development. |
---|
| 11 | */ |
---|
| 12 | |
---|
| 13 | package gov.noaa.pmel.util; |
---|
| 14 | |
---|
| 15 | import java.io.Serializable; |
---|
| 16 | |
---|
| 17 | /** |
---|
| 18 | * <code>SoTPoint</code> has two coordinates which are of |
---|
| 19 | * type <code>SoTValue</code>. SoT stands for |
---|
| 20 | * space or time, but being basically lazy I've abbreviated it. |
---|
| 21 | * |
---|
| 22 | * @author Donald Denbo |
---|
| 23 | * @version $Revision: 1.6 $, $Date: 2003/08/22 23:02:40 $ |
---|
| 24 | * @sgt 2.0 |
---|
| 25 | */ |
---|
| 26 | public class SoTPoint implements Serializable, Cloneable { |
---|
| 27 | /** X coordinate */ |
---|
| 28 | private SoTValue x_; |
---|
| 29 | /** Y coordinate */ |
---|
| 30 | private SoTValue y_; |
---|
| 31 | /** |
---|
| 32 | * Default constructor. |
---|
| 33 | */ |
---|
| 34 | public SoTPoint() { |
---|
| 35 | } |
---|
| 36 | /** |
---|
| 37 | * Construct a <code>SoTPoint</code> from <code>SoTValue</code>s. |
---|
| 38 | * |
---|
| 39 | * @param x space or time coordinate |
---|
| 40 | * @param y space or time coordinate |
---|
| 41 | */ |
---|
| 42 | public SoTPoint(SoTValue x, SoTValue y) { |
---|
| 43 | x_ = x; |
---|
| 44 | y_ = y; |
---|
| 45 | } |
---|
| 46 | /** |
---|
| 47 | * Construct a <code>SoTPoint</code> from <code>double</code>s. |
---|
| 48 | */ |
---|
| 49 | public SoTPoint(double x, double y) { |
---|
| 50 | this(new SoTValue.Double(x), new SoTValue.Double(y)); |
---|
| 51 | } |
---|
| 52 | /** |
---|
| 53 | * Construct a <code>SoTPoint</code> from a <code>double</code> and |
---|
| 54 | * a <code>GeoDate</code>. |
---|
| 55 | */ |
---|
| 56 | public SoTPoint(double x, GeoDate y) { |
---|
| 57 | this(new SoTValue.Double(x), new SoTValue.Time(y)); |
---|
| 58 | } |
---|
| 59 | /** |
---|
| 60 | * @since sgt 3.0 |
---|
| 61 | */ |
---|
| 62 | public SoTPoint(double x, long y) { |
---|
| 63 | this(new SoTValue.Double(x), new SoTValue.Time(y)); |
---|
| 64 | } |
---|
| 65 | /** |
---|
| 66 | * Construct a <code>SoTPoint</code> from a <code>GeoDate</code> and |
---|
| 67 | * a <code>double</code>. |
---|
| 68 | */ |
---|
| 69 | public SoTPoint(GeoDate x, double y) { |
---|
| 70 | this(new SoTValue.Time(x), new SoTValue.Double(y)); |
---|
| 71 | } |
---|
| 72 | /** |
---|
| 73 | * @since sgt 3.0 |
---|
| 74 | */ |
---|
| 75 | public SoTPoint(long x, double y) { |
---|
| 76 | this(new SoTValue.Time(x), new SoTValue.Double(y)); |
---|
| 77 | } |
---|
| 78 | /** |
---|
| 79 | * Construct a <code>SoTPoint</code> from a <code>SoTPoint</code>. |
---|
| 80 | */ |
---|
| 81 | public SoTPoint(SoTPoint pt) { |
---|
| 82 | this(pt.getX(), pt.getY()); |
---|
| 83 | } |
---|
| 84 | /** |
---|
| 85 | * Get x value |
---|
| 86 | */ |
---|
| 87 | public SoTValue getX() { |
---|
| 88 | return x_; |
---|
| 89 | } |
---|
| 90 | /** |
---|
| 91 | * Set x value |
---|
| 92 | * @since sgt 3.0 |
---|
| 93 | */ |
---|
| 94 | public void setX(SoTValue x) { |
---|
| 95 | x_ = x; |
---|
| 96 | } |
---|
| 97 | /** |
---|
| 98 | * Get y value |
---|
| 99 | */ |
---|
| 100 | public SoTValue getY() { |
---|
| 101 | return y_; |
---|
| 102 | } |
---|
| 103 | /** |
---|
| 104 | * Set y value |
---|
| 105 | * @since sgt 3.0 |
---|
| 106 | */ |
---|
| 107 | public void setY(SoTValue y) { |
---|
| 108 | y_ = y; |
---|
| 109 | } |
---|
| 110 | /** |
---|
| 111 | * Test for equality. For equality both x and y values must be |
---|
| 112 | * equal. |
---|
| 113 | */ |
---|
| 114 | public boolean equals(SoTPoint stp) { |
---|
| 115 | return (x_.equals(stp.getX()) && |
---|
| 116 | y_.equals(stp.getY())); |
---|
| 117 | } |
---|
| 118 | /** |
---|
| 119 | * Test if x value is time |
---|
| 120 | */ |
---|
| 121 | public boolean isXTime() { |
---|
| 122 | return x_.isTime(); |
---|
| 123 | } |
---|
| 124 | /** |
---|
| 125 | * Test if y value is time |
---|
| 126 | */ |
---|
| 127 | public boolean isYTime() { |
---|
| 128 | return y_.isTime(); |
---|
| 129 | } |
---|
| 130 | /** |
---|
| 131 | * Add to point. |
---|
| 132 | * |
---|
| 133 | * @since sgt 3.0 |
---|
| 134 | */ |
---|
| 135 | public void add(SoTPoint point) { |
---|
| 136 | x_.add(point.getX()); |
---|
| 137 | y_.add(point.getY()); |
---|
| 138 | } |
---|
| 139 | /** |
---|
| 140 | * Make a copy of the <code>SoTRange</code>. |
---|
| 141 | * @since sgt 3.0 |
---|
| 142 | */ |
---|
| 143 | public SoTPoint copy() { |
---|
| 144 | try { |
---|
| 145 | return (SoTPoint)clone(); |
---|
| 146 | } catch (CloneNotSupportedException e) { |
---|
| 147 | return null; |
---|
| 148 | } |
---|
| 149 | } |
---|
| 150 | /** |
---|
| 151 | * Convert <code>SoTPoint</code> to a default string |
---|
| 152 | * |
---|
| 153 | * @return string representation of the SoTPoint. |
---|
| 154 | */ |
---|
| 155 | public String toString() { |
---|
| 156 | return new String("(" + x_ + ", " + y_ + ")"); |
---|
| 157 | } |
---|
| 158 | } |
---|