1 package net.sf.openrocket.aerodynamics;
3 import net.sf.openrocket.l10n.Translator;
4 import net.sf.openrocket.startup.Application;
5 import net.sf.openrocket.unit.UnitGroup;
7 public abstract class Warning {
9 private static final Translator trans = Application.getTranslator();
12 * Return a Warning with the specific text.
14 public static Warning fromString(String text) {
15 return new Warning.Other(text);
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.
24 * @param other the warning to compare to
25 * @return whether this warning should be replaced
27 public abstract boolean replaceBy(Warning other);
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.
37 public boolean equals(Object o) {
38 return o != null && (o.getClass() == this.getClass());
42 * A <code>hashCode</code> method compatible with the <code>equals</code> method.
45 public int hashCode() {
46 return this.getClass().hashCode();
52 ///////////// Specific warning classes /////////////
56 * A <code>Warning</code> indicating a large angle of attack was encountered.
58 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
60 public static class LargeAOA extends Warning {
64 * Sole constructor. The argument is the AOA that caused this warning.
66 * @param aoa the angle of attack that caused this warning
68 public LargeAOA(double aoa) {
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) + ").");
83 public boolean replaceBy(Warning other) {
84 if (!(other instanceof LargeAOA))
87 LargeAOA o = (LargeAOA)other;
88 if (Double.isNaN(this.aoa)) // If this has value NaN then replace
90 return (o.aoa > this.aoa);
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
101 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
103 public static class Other extends Warning {
104 private String description;
106 public Other(String description) {
107 this.description = description;
111 public String toString() {
116 public boolean equals(Object other) {
117 if (!(other instanceof Other))
120 Other o = (Other)other;
121 return (o.description.equals(this.description));
125 public int hashCode() {
126 return description.hashCode();
130 public boolean replaceBy(Warning other) {
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"));
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"));
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"));
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"));
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"));
161 //// Invalid parameter encountered, ignoring.
162 public static final Warning FILE_INVALID_PARAMETER =
163 new Other(trans.get("Warning.FILE_INVALID_PARAMETER"));