1 package net.sf.openrocket.aerodynamics;
3 import net.sf.openrocket.unit.UnitGroup;
5 public abstract class Warning {
9 * Return a Warning with the specific text.
11 public static Warning fromString(String text) {
12 return new Warning.Other(text);
17 * Return <code>true</code> if the <code>other</code> warning should replace
18 * this warning. The method should return <code>true</code> if the other
19 * warning indicates a "worse" condition than the current warning.
21 * @param other the warning to compare to
22 * @return whether this warning should be replaced
24 public abstract boolean replaceBy(Warning other);
28 * Two <code>Warning</code>s are by default considered equal if they are of
29 * the same class. Therefore only one instance of a particular warning type
30 * is stored in a {@link WarningSet}. Subclasses may override this method for
31 * more specific functionality.
34 public boolean equals(Object o) {
35 return (o.getClass() == this.getClass());
39 * A <code>hashCode</code> method compatible with the <code>equals</code> method.
42 public int hashCode() {
43 return this.getClass().hashCode();
49 ///////////// Specific warning classes /////////////
53 * A <code>Warning</code> indicating a large angle of attack was encountered.
55 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
57 public static class LargeAOA extends Warning {
61 * Sole constructor. The argument is the AOA that caused this warning.
63 * @param aoa the angle of attack that caused this warning
65 public LargeAOA(double aoa) {
70 public String toString() {
71 if (Double.isNaN(aoa))
72 return "Large angle of attack encountered.";
73 return ("Large angle of attack encountered (" +
74 UnitGroup.UNITS_ANGLE.getDefaultUnit().toString(aoa) + ").");
78 public boolean replaceBy(Warning other) {
79 if (!(other instanceof LargeAOA))
82 LargeAOA o = (LargeAOA)other;
83 if (Double.isNaN(this.aoa)) // If this has value NaN then replace
85 return (o.aoa > this.aoa);
92 * An unspecified warning type. This warning type holds a <code>String</code>
93 * describing it. Two warnings of this type are considered equal if the strings
96 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
98 public static class Other extends Warning {
99 private String description;
101 public Other(String description) {
102 this.description = description;
106 public String toString() {
111 public boolean equals(Object other) {
112 if (!(other instanceof Other))
115 Other o = (Other)other;
116 return (o.description.equals(this.description));
120 public int hashCode() {
121 return description.hashCode();
125 public boolean replaceBy(Warning other) {
131 /** A <code>Warning</code> that the body diameter is discontinuous. */
132 public static final Warning DISCONTINUITY =
133 new Other("Discontinuity in rocket body diameter.");
135 /** A <code>Warning</code> that the fins are thick compared to the rocket body. */
136 public static final Warning THICK_FIN =
137 new Other("Thick fins may not be modeled accurately.");
139 /** A <code>Warning</code> that the fins have jagged edges. */
140 public static final Warning JAGGED_EDGED_FIN =
141 new Other("Jagged-edged fin predictions may be inaccurate.");
143 /** A <code>Warning</code> that simulation listeners have affected the simulation */
144 public static final Warning LISTENERS_AFFECTED =
145 new Other("Listeners modified the flight simulation");
147 public static final Warning RECOVERY_DEPLOYMENT_WHILE_BURNING =
148 new Other("Recovery device opened while motor still burning.");
152 public static final Warning FILE_INVALID_PARAMETER =
153 new Other("Invalid parameter encountered, ignoring.");