source: ether_statistics/service/implementation/gov/noaa/pmel/util/SoTDomain.java @ 569

Last change on this file since 569 was 569, checked in by vmipsl, 12 years ago

Nouveau projet

File size: 4.9 KB
Line 
1/*
2 * $Id: SoTDomain.java,v 1.4 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 */
12package  gov.noaa.pmel.util;
13
14/**
15 * <code>SoTDomain</code> contains the X and Y ranges of a domain in
16 * user units.  These ranges are <code>SoTRange</code> objects which
17 * can be either Space or Time.
18 *
19 * @author Donald Denbo
20 * @version $Revision: 1.4 $, $Date: 2003/08/22 23:02:40 $
21 * @since sgt 2.0
22 */
23public class SoTDomain implements java.io.Serializable {
24  SoTRange xRange_ = null;
25  SoTRange yRange_ = null;
26  boolean xReversed_ = false;
27  boolean yReversed_ = false;
28  /**
29   * Default constructor.
30   */
31  public SoTDomain() {
32  }
33  /**
34   * Construct a <code>SoTDomain</code> from a <code>Domain</code>.
35   */
36  public SoTDomain(Domain domain) {
37    if(domain.isXTime()) {
38//      xRange_ = new SoTRange.GeoDate(domain.getTimeRange());
39      xRange_ = new SoTRange.Time(domain.getTimeRange());
40    } else {
41      xRange_ = new SoTRange.Double(domain.getXRange());
42    }
43    if(domain.isYTime()) {
44//      yRange_ = new SoTRange.GeoDate(domain.getTimeRange());
45      yRange_ = new SoTRange.Time(domain.getTimeRange());
46    } else {
47      yRange_ = new SoTRange.Double(domain.getYRange());
48    }
49    xReversed_ = domain.isXReversed();
50    yReversed_ = domain.isYReversed();
51  }
52  /**
53   * Constract a <code>SoTDomain</code> from a <code>SoTDomain</code>
54   */
55  public SoTDomain(SoTDomain domain) {
56    xRange_ = domain.getXRange();
57    yRange_ = domain.getYRange();
58    xReversed_ = domain.isXReversed();
59    yReversed_ = domain.isYReversed();
60  }
61  /**
62   * Construct a <code>SoTDomain</code> from <code>SoTRange</code>s.
63   */
64  public SoTDomain(SoTRange xRange, SoTRange yRange) {
65    xRange_ = xRange;
66    yRange_ = yRange;
67    xReversed_ = false;
68    yReversed_ = false;
69  }
70  /**
71   * @since sgt 3.0
72   */
73  public SoTDomain(SoTRange xRange, SoTRange yRange,
74                   boolean xRev, boolean yRev) {
75    xRange_ = xRange;
76    yRange_ = yRange;
77    xReversed_ = xRev;
78    yReversed_ = yRev;
79  }
80  /**
81   * Set the x range
82   */
83  public void setXRange(SoTRange xRange) {
84    xRange_ = xRange;
85  }
86  /**
87   * Get the x range
88   */
89  public SoTRange getXRange() {
90    return xRange_;
91  }
92  /**
93   * Set the y range
94   */
95  public void setYRange(SoTRange yRange) {
96    yRange_ = yRange;
97  }
98  /**
99   * Get the y range
100   */
101  public SoTRange getYRange() {
102    return yRange_;
103  }
104  /**
105   * Test if the x range is temporal.
106   */
107  public boolean isXTime() {
108    return xRange_.isTime();
109  }
110  /**
111   * Test if the y range is temporal
112   */
113  public boolean isYTime() {
114    return yRange_.isTime();
115  }
116  /**
117   * Get the center of the domain.
118   * @since sgt 3.0
119   */
120  public SoTPoint getCenter() {
121    SoTValue xVal = null;
122    SoTValue yVal = null;
123    if(isXTime()) {
124      xVal = new SoTValue.Time((xRange_.getStart().getLongTime()+
125                                xRange_.getEnd().getLongTime())/2);
126    } else {
127      xVal = new SoTValue.Double((((Number)xRange_.getStart().getObjectValue()).doubleValue() +
128                                  ((Number)xRange_.getEnd().getObjectValue()).doubleValue())/2.0);
129    }
130    if(isYTime()) {
131      yVal = new SoTValue.Time((yRange_.getStart().getLongTime()+
132                                yRange_.getEnd().getLongTime())/2);
133    } else {
134      yVal = new SoTValue.Double((((Number)yRange_.getStart().getObjectValue()).doubleValue() +
135                                  ((Number)yRange_.getEnd().getObjectValue()).doubleValue())/2.0);
136    }
137
138    return new SoTPoint(xVal, yVal);
139  }
140  /**
141   * Test for equality.  Both ranges must be equal for equality.
142   */
143  public boolean equals(SoTDomain d) {
144    if(!xRange_.equals(d.getXRange())) return false;
145    if(!yRange_.equals(d.getYRange())) return false;
146    if(xReversed_ != d.isXReversed()) return false;
147    if(yReversed_ != d.isYReversed()) return false;
148    return true;
149  }
150  public String toString() {
151    StringBuffer buf = new StringBuffer(100);
152    buf.append("x=");
153    buf.append(xRange_).append(",y=");
154    buf.append(yRange_);
155    buf.append(", xRev=").append(xReversed_);
156    buf.append(", yRev=").append(yReversed_);
157    return buf.toString();
158  }
159  /**
160  * @since sgt 3.0
161  */
162 public void setXReversed(boolean rev) {
163    xReversed_ = rev;
164  }
165  /**
166   * @since sgt 3.0
167   */
168  public boolean isXReversed() {
169    return xReversed_;
170  }
171  /**
172   * @since sgt 3.0
173   */
174  public void setYReversed(boolean rev) {
175    yReversed_ = rev;
176  }
177  /**
178   * @since sgt 3.0
179   */
180  public boolean isYReversed() {
181    return yReversed_;
182  }
183}
Note: See TracBrowser for help on using the repository browser.