More updates to localization provided by Ruslan Uss.
[debian/openrocket] / core / src / net / sf / openrocket / aerodynamics / Warning.java
1 package net.sf.openrocket.aerodynamics;
2
3 import net.sf.openrocket.l10n.Translator;
4 import net.sf.openrocket.motor.Motor;
5 import net.sf.openrocket.startup.Application;
6 import net.sf.openrocket.unit.UnitGroup;
7
8 public abstract class Warning {
9         
10         private static final Translator trans = Application.getTranslator();
11
12         /**
13          * Return a Warning with the specific text.
14          */
15         public static Warning fromString(String text) {
16                 return new Warning.Other(text);
17         }
18         
19         
20         /**
21          * Return <code>true</code> if the <code>other</code> warning should replace
22          * this warning.  The method should return <code>true</code> if the other
23          * warning indicates a "worse" condition than the current warning.
24          * 
25          * @param other  the warning to compare to
26          * @return       whether this warning should be replaced
27          */
28         public abstract boolean replaceBy(Warning other);
29         
30         
31         /**
32          * Two <code>Warning</code>s are by default considered equal if they are of
33          * the same class.  Therefore only one instance of a particular warning type 
34          * is stored in a {@link WarningSet}.  Subclasses may override this method for
35          * more specific functionality.
36          */
37         @Override
38         public boolean equals(Object o) {
39         return o != null && (o.getClass() == this.getClass());
40     }
41         
42         /**
43          * A <code>hashCode</code> method compatible with the <code>equals</code> method.
44          */
45         @Override
46         public int hashCode() {
47                 return this.getClass().hashCode();
48         }
49         
50         
51         
52         
53         /////////////  Specific warning classes  /////////////
54         
55         
56         /**
57          * A <code>Warning</code> indicating a large angle of attack was encountered.
58          * 
59          * @author Sampo Niskanen <sampo.niskanen@iki.fi>
60          */
61         public static class LargeAOA extends Warning {
62                 private double aoa;
63                 
64                 /**
65                  * Sole constructor.  The argument is the AOA that caused this warning.
66                  * 
67                  * @param aoa  the angle of attack that caused this warning
68                  */
69                 public LargeAOA(double aoa) {
70                         this.aoa = aoa;
71                 }
72                 
73                 @Override
74                 public String toString() {
75                         if (Double.isNaN(aoa))
76                                 //// Large angle of attack encountered.
77                                 return trans.get("Warning.LargeAOA.str1");
78                         //// Large angle of attack encountered (
79                         return (trans.get("Warning.LargeAOA.str2") +
80                                         UnitGroup.UNITS_ANGLE.getDefaultUnit().toString(aoa) + ").");
81                 }
82
83                 @Override
84                 public boolean replaceBy(Warning other) {
85                         if (!(other instanceof LargeAOA))
86                                 return false;
87                         
88                         LargeAOA o = (LargeAOA)other;
89                         if (Double.isNaN(this.aoa))   // If this has value NaN then replace
90                                 return true;
91                         return (o.aoa > this.aoa);
92                 }
93         }
94         
95         public static class MissingMotor extends Warning {
96
97                 private Motor.Type type = null;
98                 private String manufacturer = null;
99                 private String designation = null;
100                 private String digest = null;
101                 private double diameter = Double.NaN;
102                 private double length = Double.NaN;
103                 private double delay = Double.NaN;
104
105                 @Override
106                 public String toString() {
107                         String str = "No motor with designation '" + designation + "'";
108                         if (manufacturer != null)
109                                 str += " for manufacturer '" + manufacturer + "'";
110                         str += " found.";
111                         return str;
112                 }
113
114                 public Motor.Type getType() {
115                         return type;
116                 }
117
118
119                 public void setType(Motor.Type type) {
120                         this.type = type;
121                 }
122
123
124                 public String getManufacturer() {
125                         return manufacturer;
126                 }
127
128
129                 public void setManufacturer(String manufacturer) {
130                         this.manufacturer = manufacturer;
131                 }
132
133
134                 public String getDesignation() {
135                         return designation;
136                 }
137
138
139                 public void setDesignation(String designation) {
140                         this.designation = designation;
141                 }
142
143
144                 public String getDigest() {
145                         return digest;
146                 }
147
148
149                 public void setDigest(String digest) {
150                         this.digest = digest;
151                 }
152
153
154                 public double getDiameter() {
155                         return diameter;
156                 }
157
158
159                 public void setDiameter(double diameter) {
160                         this.diameter = diameter;
161                 }
162
163
164                 public double getLength() {
165                         return length;
166                 }
167
168
169                 public void setLength(double length) {
170                         this.length = length;
171                 }
172
173
174                 public double getDelay() {
175                         return delay;
176                 }
177
178
179                 public void setDelay(double delay) {
180                         this.delay = delay;
181                 }
182
183
184                 @Override
185                 public boolean replaceBy(Warning other) {
186                         return false;
187                 }
188
189                 @Override
190                 public int hashCode() {
191                         final int prime = 31;
192                         int result = super.hashCode();
193                         long temp;
194                         temp = Double.doubleToLongBits(delay);
195                         result = prime * result + (int) (temp ^ (temp >>> 32));
196                         result = prime * result
197                                         + ((designation == null) ? 0 : designation.hashCode());
198                         temp = Double.doubleToLongBits(diameter);
199                         result = prime * result + (int) (temp ^ (temp >>> 32));
200                         result = prime * result
201                                         + ((digest == null) ? 0 : digest.hashCode());
202                         temp = Double.doubleToLongBits(length);
203                         result = prime * result + (int) (temp ^ (temp >>> 32));
204                         result = prime * result
205                                         + ((manufacturer == null) ? 0 : manufacturer.hashCode());
206                         result = prime * result + ((type == null) ? 0 : type.hashCode());
207                         return result;
208                 }
209
210                 @Override
211                 public boolean equals(Object obj) {
212                         if (this == obj)
213                                 return true;
214                         if (!super.equals(obj))
215                                 return false;
216                         if (getClass() != obj.getClass())
217                                 return false;
218                         MissingMotor other = (MissingMotor) obj;
219                         if (Double.doubleToLongBits(delay) != Double
220                                         .doubleToLongBits(other.delay))
221                                 return false;
222                         if (designation == null) {
223                                 if (other.designation != null)
224                                         return false;
225                         } else if (!designation.equals(other.designation))
226                                 return false;
227                         if (Double.doubleToLongBits(diameter) != Double
228                                         .doubleToLongBits(other.diameter))
229                                 return false;
230                         if (digest == null) {
231                                 if (other.digest != null)
232                                         return false;
233                         } else if (!digest.equals(other.digest))
234                                 return false;
235                         if (Double.doubleToLongBits(length) != Double
236                                         .doubleToLongBits(other.length))
237                                 return false;
238                         if (manufacturer == null) {
239                                 if (other.manufacturer != null)
240                                         return false;
241                         } else if (!manufacturer.equals(other.manufacturer))
242                                 return false;
243                         if (type != other.type)
244                                 return false;
245                         return true;
246                 }
247                 
248         }
249         
250         
251         /**
252          * An unspecified warning type.  This warning type holds a <code>String</code>
253          * describing it.  Two warnings of this type are considered equal if the strings
254          * are identical.
255          * 
256          * @author Sampo Niskanen <sampo.niskanen@iki.fi>
257          */
258         public static class Other extends Warning {
259                 private String description;
260                 
261                 public Other(String description) {
262                         this.description = description;
263                 }
264                 
265                 @Override
266                 public String toString() {
267                         return description;
268                 }
269                 
270                 @Override
271                 public boolean equals(Object other) {
272                         if (!(other instanceof Other))
273                                 return false;
274                         
275                         Other o = (Other)other;
276                         return (o.description.equals(this.description));
277                 }
278                 
279                 @Override
280                 public int hashCode() {
281                         return description.hashCode();
282                 }
283
284                 @Override
285                 public boolean replaceBy(Warning other) {
286                         return false;
287                 }
288         }
289         
290         
291         /** A <code>Warning</code> that the body diameter is discontinuous. */
292 ////Discontinuity in rocket body diameter.
293         public static final Warning DISCONTINUITY = 
294                 new Other(trans.get("Warning.DISCONTINUITY"));
295         
296         /** A <code>Warning</code> that the fins are thick compared to the rocket body. */
297 ////Thick fins may not be modeled accurately.
298         public static final Warning THICK_FIN =
299                 new Other(trans.get("Warning.THICK_FIN"));
300         
301         /** A <code>Warning</code> that the fins have jagged edges. */
302 ////Jagged-edged fin predictions may be inaccurate.
303         public static final Warning JAGGED_EDGED_FIN =
304                 new Other(trans.get("Warning.JAGGED_EDGED_FIN"));
305         
306         /** A <code>Warning</code> that simulation listeners have affected the simulation */
307 ////Listeners modified the flight simulation
308         public static final Warning LISTENERS_AFFECTED =
309                 new Other(trans.get("Warning.LISTENERS_AFFECTED"));
310         
311 ////Recovery device opened while motor still burning.
312         public static final Warning RECOVERY_DEPLOYMENT_WHILE_BURNING =
313                 new Other(trans.get("Warning.RECOVERY_DEPLOYMENT_WHILE_BURNING"));
314         
315         
316         //// Invalid parameter encountered, ignoring.
317         public static final Warning FILE_INVALID_PARAMETER =
318                 new Other(trans.get("Warning.FILE_INVALID_PARAMETER"));
319
320         public static final Warning PARALLEL_FINS =
321                 new Other(trans.get("Warning.PARALLEL_FINS"));
322         
323         public static final Warning SUPERSONIC =
324                 new Other(trans.get("Warning.SUPERSONIC"));
325
326         public static final Warning RECOVERY_LAUNCH_ROD =
327                 new Other(trans.get("Warning.RECOVERY_LAUNCH_ROD"));
328 }