DGP - updated Rocksim export to support clusters
[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.startup.Application;
5 import net.sf.openrocket.unit.UnitGroup;
6
7 public abstract class Warning {
8         
9         private static final Translator trans = Application.getTranslator();
10
11         /**
12          * Return a Warning with the specific text.
13          */
14         public static Warning fromString(String text) {
15                 return new Warning.Other(text);
16         }
17         
18         
19         /**
20          * Return <code>true</code> if the <code>other</code> warning should replace
21          * this warning.  The method should return <code>true</code> if the other
22          * warning indicates a "worse" condition than the current warning.
23          * 
24          * @param other  the warning to compare to
25          * @return       whether this warning should be replaced
26          */
27         public abstract boolean replaceBy(Warning other);
28         
29         
30         /**
31          * Two <code>Warning</code>s are by default considered equal if they are of
32          * the same class.  Therefore only one instance of a particular warning type 
33          * is stored in a {@link WarningSet}.  Subclasses may override this method for
34          * more specific functionality.
35          */
36         @Override
37         public boolean equals(Object o) {
38         return o != null && (o.getClass() == this.getClass());
39     }
40         
41         /**
42          * A <code>hashCode</code> method compatible with the <code>equals</code> method.
43          */
44         @Override
45         public int hashCode() {
46                 return this.getClass().hashCode();
47         }
48         
49         
50         
51         
52         /////////////  Specific warning classes  /////////////
53         
54         
55         /**
56          * A <code>Warning</code> indicating a large angle of attack was encountered.
57          * 
58          * @author Sampo Niskanen <sampo.niskanen@iki.fi>
59          */
60         public static class LargeAOA extends Warning {
61                 private double aoa;
62                 
63                 /**
64                  * Sole constructor.  The argument is the AOA that caused this warning.
65                  * 
66                  * @param aoa  the angle of attack that caused this warning
67                  */
68                 public LargeAOA(double aoa) {
69                         this.aoa = aoa;
70                 }
71                 
72                 @Override
73                 public String toString() {
74                         if (Double.isNaN(aoa))
75                                 //// Large angle of attack encountered.
76                                 return trans.get("Warning.LargeAOA.str1");
77                         //// Large angle of attack encountered (
78                         return (trans.get("Warning.LargeAOA.str2") +
79                                         UnitGroup.UNITS_ANGLE.getDefaultUnit().toString(aoa) + ").");
80                 }
81
82                 @Override
83                 public boolean replaceBy(Warning other) {
84                         if (!(other instanceof LargeAOA))
85                                 return false;
86                         
87                         LargeAOA o = (LargeAOA)other;
88                         if (Double.isNaN(this.aoa))   // If this has value NaN then replace
89                                 return true;
90                         return (o.aoa > this.aoa);
91                 }
92         }
93         
94         
95         
96         /**
97          * An unspecified warning type.  This warning type holds a <code>String</code>
98          * describing it.  Two warnings of this type are considered equal if the strings
99          * are identical.
100          * 
101          * @author Sampo Niskanen <sampo.niskanen@iki.fi>
102          */
103         public static class Other extends Warning {
104                 private String description;
105                 
106                 public Other(String description) {
107                         this.description = description;
108                 }
109                 
110                 @Override
111                 public String toString() {
112                         return description;
113                 }
114                 
115                 @Override
116                 public boolean equals(Object other) {
117                         if (!(other instanceof Other))
118                                 return false;
119                         
120                         Other o = (Other)other;
121                         return (o.description.equals(this.description));
122                 }
123                 
124                 @Override
125                 public int hashCode() {
126                         return description.hashCode();
127                 }
128
129                 @Override
130                 public boolean replaceBy(Warning other) {
131                         return false;
132                 }
133         }
134         
135         
136         /** A <code>Warning</code> that the body diameter is discontinuous. */
137 ////Discontinuity in rocket body diameter.
138         public static final Warning DISCONTINUITY = 
139                 new Other(trans.get("Warning.DISCONTINUITY"));
140         
141         /** A <code>Warning</code> that the fins are thick compared to the rocket body. */
142 ////Thick fins may not be modeled accurately.
143         public static final Warning THICK_FIN =
144                 new Other(trans.get("Warning.THICK_FIN"));
145         
146         /** A <code>Warning</code> that the fins have jagged edges. */
147 ////Jagged-edged fin predictions may be inaccurate.
148         public static final Warning JAGGED_EDGED_FIN =
149                 new Other(trans.get("Warning.JAGGED_EDGED_FIN"));
150         
151         /** A <code>Warning</code> that simulation listeners have affected the simulation */
152 ////Listeners modified the flight simulation
153         public static final Warning LISTENERS_AFFECTED =
154                 new Other(trans.get("Warning.LISTENERS_AFFECTED"));
155         
156 ////Recovery device opened while motor still burning.
157         public static final Warning RECOVERY_DEPLOYMENT_WHILE_BURNING =
158                 new Other(trans.get("Warning.RECOVERY_DEPLOYMENT_WHILE_BURNING"));
159         
160         
161         //// Invalid parameter encountered, ignoring.
162         public static final Warning FILE_INVALID_PARAMETER =
163                 new Other(trans.get("Warning.FILE_INVALID_PARAMETER"));
164 }