1 package net.sf.openrocket.aerodynamics;
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;
8 public abstract class Warning {
10 private static final Translator trans = Application.getTranslator();
13 * Return a Warning with the specific text.
15 public static Warning fromString(String text) {
16 return new Warning.Other(text);
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.
25 * @param other the warning to compare to
26 * @return whether this warning should be replaced
28 public abstract boolean replaceBy(Warning other);
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.
38 public boolean equals(Object o) {
39 return o != null && (o.getClass() == this.getClass());
43 * A <code>hashCode</code> method compatible with the <code>equals</code> method.
46 public int hashCode() {
47 return this.getClass().hashCode();
53 ///////////// Specific warning classes /////////////
57 * A <code>Warning</code> indicating a large angle of attack was encountered.
59 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
61 public static class LargeAOA extends Warning {
65 * Sole constructor. The argument is the AOA that caused this warning.
67 * @param aoa the angle of attack that caused this warning
69 public LargeAOA(double aoa) {
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) + ").");
84 public boolean replaceBy(Warning other) {
85 if (!(other instanceof LargeAOA))
88 LargeAOA o = (LargeAOA)other;
89 if (Double.isNaN(this.aoa)) // If this has value NaN then replace
91 return (o.aoa > this.aoa);
95 public static class MissingMotor extends Warning {
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;
105 public String toString() {
106 String str = "No motor with designation '" + designation + "'";
107 if (manufacturer != null)
108 str += " for manufacturer '" + manufacturer + "'";
113 public Motor.Type getType() {
118 public void setType(Motor.Type type) {
123 public String getManufacturer() {
128 public void setManufacturer(String manufacturer) {
129 this.manufacturer = manufacturer;
133 public String getDesignation() {
138 public void setDesignation(String designation) {
139 this.designation = designation;
143 public String getDigest() {
148 public void setDigest(String digest) {
149 this.digest = digest;
153 public double getDiameter() {
158 public void setDiameter(double diameter) {
159 this.diameter = diameter;
163 public double getLength() {
168 public void setLength(double length) {
169 this.length = length;
173 public double getDelay() {
178 public void setDelay(double delay) {
184 public boolean replaceBy(Warning other) {
189 public int hashCode() {
190 final int prime = 31;
191 int result = super.hashCode();
193 temp = Double.doubleToLongBits(delay);
194 result = prime * result + (int) (temp ^ (temp >>> 32));
195 result = prime * result
196 + ((designation == null) ? 0 : designation.hashCode());
197 temp = Double.doubleToLongBits(diameter);
198 result = prime * result + (int) (temp ^ (temp >>> 32));
199 result = prime * result
200 + ((digest == null) ? 0 : digest.hashCode());
201 temp = Double.doubleToLongBits(length);
202 result = prime * result + (int) (temp ^ (temp >>> 32));
203 result = prime * result
204 + ((manufacturer == null) ? 0 : manufacturer.hashCode());
205 result = prime * result + ((type == null) ? 0 : type.hashCode());
210 public boolean equals(Object obj) {
213 if (!super.equals(obj))
215 if (getClass() != obj.getClass())
217 MissingMotor other = (MissingMotor) obj;
218 if (Double.doubleToLongBits(delay) != Double
219 .doubleToLongBits(other.delay))
221 if (designation == null) {
222 if (other.designation != null)
224 } else if (!designation.equals(other.designation))
226 if (Double.doubleToLongBits(diameter) != Double
227 .doubleToLongBits(other.diameter))
229 if (digest == null) {
230 if (other.digest != null)
232 } else if (!digest.equals(other.digest))
234 if (Double.doubleToLongBits(length) != Double
235 .doubleToLongBits(other.length))
237 if (manufacturer == null) {
238 if (other.manufacturer != null)
240 } else if (!manufacturer.equals(other.manufacturer))
242 if (type != other.type)
251 * An unspecified warning type. This warning type holds a <code>String</code>
252 * describing it. Two warnings of this type are considered equal if the strings
255 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
257 public static class Other extends Warning {
258 private String description;
260 public Other(String description) {
261 this.description = description;
265 public String toString() {
270 public boolean equals(Object other) {
271 if (!(other instanceof Other))
274 Other o = (Other)other;
275 return (o.description.equals(this.description));
279 public int hashCode() {
280 return description.hashCode();
284 public boolean replaceBy(Warning other) {
290 /** A <code>Warning</code> that the body diameter is discontinuous. */
291 ////Discontinuity in rocket body diameter.
292 public static final Warning DISCONTINUITY =
293 new Other(trans.get("Warning.DISCONTINUITY"));
295 /** A <code>Warning</code> that the fins are thick compared to the rocket body. */
296 ////Thick fins may not be modeled accurately.
297 public static final Warning THICK_FIN =
298 new Other(trans.get("Warning.THICK_FIN"));
300 /** A <code>Warning</code> that the fins have jagged edges. */
301 ////Jagged-edged fin predictions may be inaccurate.
302 public static final Warning JAGGED_EDGED_FIN =
303 new Other(trans.get("Warning.JAGGED_EDGED_FIN"));
305 /** A <code>Warning</code> that simulation listeners have affected the simulation */
306 ////Listeners modified the flight simulation
307 public static final Warning LISTENERS_AFFECTED =
308 new Other(trans.get("Warning.LISTENERS_AFFECTED"));
310 ////Recovery device opened while motor still burning.
311 public static final Warning RECOVERY_DEPLOYMENT_WHILE_BURNING =
312 new Other(trans.get("Warning.RECOVERY_DEPLOYMENT_WHILE_BURNING"));
315 //// Invalid parameter encountered, ignoring.
316 public static final Warning FILE_INVALID_PARAMETER =
317 new Other(trans.get("Warning.FILE_INVALID_PARAMETER"));