001/*
002 * This file is part of McIDAS-V
003 *
004 * Copyright 2007-2024
005 * Space Science and Engineering Center (SSEC)
006 * University of Wisconsin - Madison
007 * 1225 W. Dayton Street, Madison, WI 53706, USA
008 * https://www.ssec.wisc.edu/mcidas/
009 * 
010 * All Rights Reserved
011 * 
012 * McIDAS-V is built on Unidata's IDV and SSEC's VisAD libraries, and
013 * some McIDAS-V source code is based on IDV and VisAD source code.  
014 * 
015 * McIDAS-V is free software; you can redistribute it and/or modify
016 * it under the terms of the GNU Lesser Public License as published by
017 * the Free Software Foundation; either version 3 of the License, or
018 * (at your option) any later version.
019 * 
020 * McIDAS-V is distributed in the hope that it will be useful,
021 * but WITHOUT ANY WARRANTY; without even the implied warranty of
022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
023 * GNU Lesser Public License for more details.
024 * 
025 * You should have received a copy of the GNU Lesser Public License
026 * along with this program.  If not, see https://www.gnu.org/licenses/.
027 */
028
029package edu.wisc.ssec.mcidasv.data.cyclone;
030
031import java.util.List;
032
033import ucar.unidata.data.DataChoice;
034import ucar.unidata.util.TwoFacedObject;
035import ucar.visad.Util;
036import visad.Real;
037import visad.RealType;
038import visad.Unit;
039import visad.VisADException;
040
041/**
042 * Created by IntelliJ IDEA. User: yuanho Date: Apr 18, 2008 Time: 1:45:38 PM To
043 * change this template use File | Settings | File Templates.
044 */
045
046public class StormParam {
047
048        /** _more_ */
049        RealType type;
050
051        /** _more_ */
052        private boolean canDoDifference = true;
053
054        /** _more_ */
055        private boolean derived = false;
056
057        /** _more_ */
058        private boolean isChartParam = true;
059
060        /**
061         * _more_
062         */
063        public StormParam() {
064        }
065
066        /**
067         * _more_
068         * 
069         * @param type
070         *            _more_
071         */
072        public StormParam(RealType type) {
073                this.type = type;
074                if (type != null) {
075                        DataChoice.addCurrentName(new TwoFacedObject("Storm Track>" + type,
076                                        Util.cleanTypeName(type)));
077                }
078        }
079
080        /**
081         * _more_
082         * 
083         * @param type
084         *            _more_
085         * @param derived
086         *            _more_
087         */
088        public StormParam(RealType type, boolean derived) {
089                this(type);
090                this.derived = derived;
091        }
092
093        /**
094         * _more_
095         * 
096         * @param type
097         *            _more_
098         * @param derived
099         *            _more_
100         * @param canDoDiff
101         *            _more_
102         */
103        public StormParam(RealType type, boolean derived, boolean canDoDiff) {
104                this(type);
105                this.derived = derived;
106                this.canDoDifference = canDoDiff;
107        }
108
109        /**
110         * _more_
111         * 
112         * @param type
113         *            _more_
114         * @param derived
115         *            _more_
116         * @param canDoDiff
117         *            _more_
118         * @param chartList
119         *            _more_
120         */
121        public StormParam(RealType type, boolean derived, boolean canDoDiff,
122                        boolean chartList) {
123                this(type);
124                this.derived = derived;
125                this.canDoDifference = canDoDiff;
126                this.isChartParam = chartList;
127        }
128
129        /**
130         * _more_
131         * 
132         * @param value
133         *            _more_
134         * 
135         * @return _more_
136         * 
137         * @throws VisADException
138         *             _more_
139         */
140        public Real getReal(double value) throws VisADException {
141                return new Real(type, value);
142        }
143
144        /**
145         * _more_
146         * 
147         * @return _more_
148         */
149        public Unit getUnit() {
150                return type.getDefaultUnit();
151        }
152
153        /**
154         * _more_
155         * 
156         * @return _more_
157         */
158        public int hashCode() {
159                return type.hashCode();
160        }
161
162        /**
163         * Set the CanDoDifference property.
164         * 
165         * @param value
166         *            The new value for CanDoDifference
167         */
168        public void setCanDoDifference(boolean value) {
169                canDoDifference = value;
170        }
171
172        /**
173         * Get the CanDoDifference property.
174         * 
175         * @return The CanDoDifference
176         */
177        public boolean getCanDoDifference() {
178                return canDoDifference;
179        }
180
181        /**
182         * Set the CanDoDifference property.
183         * 
184         * @param value
185         *            The new value for CanDoDifference
186         */
187        public void setIsChartParam(boolean value) {
188                isChartParam = value;
189        }
190
191        /**
192         * Get the CanDoDifference property.
193         * 
194         * @return The CanDoDifference
195         */
196        public boolean getIsChartParam() {
197                return isChartParam;
198        }
199
200        /**
201         * _more_
202         * 
203         * @param attributes
204         *            _more_
205         * 
206         * @return _more_
207         */
208        public Real getAttribute(List<Real> attributes) {
209                if (attributes == null) {
210                        return null;
211                }
212                for (Real attr : attributes) {
213                        if (attr.getType().equals(type)) {
214                                return attr;
215                        }
216                }
217                return null;
218        }
219
220        /**
221         * _more_
222         * 
223         * @param o
224         *            _more_
225         * 
226         * @return _more_
227         */
228        public boolean equals(Object o) {
229                if (!this.getClass().equals(o.getClass())) {
230                        return false;
231                }
232                StormParam that = (StormParam) o;
233                return this.type.equals(that.type);
234        }
235
236        /**
237         * _more_
238         * 
239         * @return _more_
240         */
241        public String toString() {
242                return Util.cleanTypeName(type.getName()).replace("_", " ");
243        }
244
245        /**
246         * _more_
247         * 
248         * @return _more_
249         */
250        public String getName() {
251                return Util.cleanTypeName(type.getName());
252        }
253
254        /**
255         * Set the Type property.
256         * 
257         * @param value
258         *            The new value for Type
259         */
260        public void setType(RealType value) {
261                type = value;
262        }
263
264        /**
265         * Get the Type property.
266         * 
267         * @return The Type
268         */
269        public RealType getType() {
270                return type;
271        }
272
273        /**
274         * Set the Derived property.
275         * 
276         * @param value
277         *            The new value for Derived
278         */
279        public void setDerived(boolean value) {
280                derived = value;
281        }
282
283        /**
284         * Get the Derived property.
285         * 
286         * @return The Derived
287         */
288        public boolean getDerived() {
289                return derived;
290        }
291
292}