source: ether_statistics/service/implementation/gov/noaa/pmel/sgt/dm/PointCollection.java @ 569

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

Nouveau projet

File size: 3.4 KB
Line 
1/*
2 * $Id: PointCollection.java,v 1.6 2001/02/06 00:47:24 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 
13package gov.noaa.pmel.sgt.dm;
14
15import java.util.Vector;
16import java.util.Enumeration;
17
18import gov.noaa.pmel.util.SoTRange;
19 
20/**
21 * <code>PointCollection</code> is an extension to <code>Vector</code>
22 * designed to hold <code>SGTPoint</code> objects.
23 *
24 * @author Donald Denbo
25 * @version $Revision: 1.6 $, $Date: 2001/02/06 00:47:24 $
26 * @since 2.0
27 * @see SGTData
28 * @see SGTPoint
29 * @see SGTLine
30 * @see SGTGrid
31 * @see SGTVector
32 */
33public class PointCollection extends Collection {
34  private SoTRange xRange_ = null;
35  private SoTRange yRange_ = null;
36  private int colLen_ = 0;
37
38  /**
39   * @link aggregation
40   * @clientRole x
41   */
42  private SGTMetaData xMetaData_;
43
44  /**
45   * @link aggregation
46   * @clientRole y
47   */
48  private SGTMetaData yMetaData_;
49  /**
50   * Default consturctor
51   */
52  public PointCollection() {
53    this("");
54  }
55  public PointCollection(String title) {
56    super(title);
57  }
58  public PointCollection(String title, int initialCapacity) {
59    super(title, initialCapacity);
60  }
61  public PointCollection(String title, int initialCapacity, int increment) {
62    super(title, initialCapacity, increment);
63  }
64  /**
65   * Create a copy.
66   *
67   * @see SGTData
68   */
69  public SGTData copy() {
70    PointCollection newCollection;
71    newCollection = (PointCollection)clone();
72    return (SGTData)newCollection;
73  }
74  public SoTRange getXRange() {
75    computeRange();
76    return xRange_.copy();
77  }
78
79  public SoTRange getYRange() {
80    computeRange();
81    return yRange_.copy();
82  }
83
84  private void computeRange() {
85    if(colLen_ == size()) return;
86    colLen_ = size();
87    double xmin = Double.POSITIVE_INFINITY;
88    double xmax = Double.NEGATIVE_INFINITY;
89    double ymin = xmin;
90    double ymax = xmax;
91    double ptx, pty;
92
93    int count = 0;
94    Enumeration e = elements();
95    while(e.hasMoreElements()) {
96      Object obj = e.nextElement();
97      if(obj instanceof SGTPoint) {
98        SGTPoint pt = (SGTPoint)obj;
99        ptx = pt.getX();
100        pty = pt.getY();
101        if(!(Double.isNaN(ptx) || Double.isNaN(pty))) {
102          xmin = Math.min(xmin, ptx);
103          xmax = Math.max(xmax, ptx);
104          ymin = Math.min(ymin, pty);
105          ymax = Math.max(ymax, pty);
106          count++;
107        }
108      }
109    }
110    if(count == 0) {
111      xRange_ = new SoTRange.Double(Double.NaN, Double.NaN);
112      yRange_ = new SoTRange.Double(Double.NaN, Double.NaN);
113    } else {
114      xRange_ = new SoTRange.Double(xmin, xmax);
115      yRange_ = new SoTRange.Double(ymin, ymax);
116    }
117  }
118
119  public SGTMetaData getXMetaData(){ 
120    return xMetaData_; 
121  }
122  /**
123   * Set the <code>SGTMetaData</code> associated with the x axis.
124   */
125  public void setXMetaData(SGTMetaData xMetaData){ 
126    xMetaData_ = xMetaData; 
127  }
128
129  public SGTMetaData getYMetaData(){ 
130    return yMetaData_; 
131  }
132  /**
133   * Set the <code>SGTMetaData</code> associated with the y axis.
134   */
135  public void setYMetaData(SGTMetaData yMetaData){ 
136    yMetaData_ = yMetaData; 
137  }
138}
Note: See TracBrowser for help on using the repository browser.