diff --git a/core/src/net/sf/openrocket/logging/Message.java b/core/src/net/sf/openrocket/logging/Message.java
new file mode 100644
index 000000000..9b813c1a8
--- /dev/null
+++ b/core/src/net/sf/openrocket/logging/Message.java
@@ -0,0 +1,43 @@
+package net.sf.openrocket.logging;
+
+/**
+ * Baseclass for logging messages (warnings, errors...)
+ */
+public abstract class Message {
+ /**
+ * @return a Message with the specific text.
+ */
+ public static Message fromString(String text) {
+ return new Warning.Other(text);
+ }
+
+ /**
+ * Return true
if the other
warning should replace
+ * this message. The method should return true
if the other
+ * indicates a "worse" condition than the current warning.
+ *
+ * @param other the message to compare to
+ * @return whether this message should be replaced
+ */
+ public abstract boolean replaceBy(Message other);
+
+
+ /**
+ * Two Message
s are by default considered equal if they are of
+ * the same class. Therefore only one instance of a particular message type
+ * is stored in a {@link MessageSet}. Subclasses may override this method for
+ * more specific functionality.
+ */
+ @Override
+ public boolean equals(Object o) {
+ return o != null && (o.getClass() == this.getClass());
+ }
+
+ /**
+ * A hashCode
method compatible with the equals
method.
+ */
+ @Override
+ public int hashCode() {
+ return this.getClass().hashCode();
+ }
+}
diff --git a/core/src/net/sf/openrocket/logging/MessageSet.java b/core/src/net/sf/openrocket/logging/MessageSet.java
new file mode 100644
index 000000000..98642d1aa
--- /dev/null
+++ b/core/src/net/sf/openrocket/logging/MessageSet.java
@@ -0,0 +1,123 @@
+package net.sf.openrocket.logging;
+
+import net.sf.openrocket.util.ArrayList;
+import net.sf.openrocket.util.BugException;
+import net.sf.openrocket.util.Monitorable;
+import net.sf.openrocket.util.Mutable;
+
+import java.util.AbstractSet;
+import java.util.Iterator;
+
+/**
+ * A set that contains multiple Message
s. When adding a
+ * {@link Message} to this set, the contents is checked for a message of the
+ * same type. If one is found, then the message left in the set is determined
+ * by the method {@link Message#replaceBy(Message)}.
+ *
+ * A MessageSet can be made immutable by calling {@link #immute()}.
+ *
+ * @author Sampo Niskanen
* A WarningSet can be made immutable by calling {@link #immute()}.
*
* @author Sampo Niskanen Message
to the set. If a message of the same type
+ * exists in the set, the message that is left in the set is defined by the
+ * method {@link Message#replaceBy(Message)}.
+ *
+ * @throws IllegalStateException if this message set has been made immutable.
+ */
+ @Override
+ public boolean add(E m) {
+ mutable.check();
+
+ modID++;
+ int index = messages.indexOf(m);
+
+ if (index < 0) {
+ messages.add(m);
+ return false;
+ }
+
+ E old = messages.get(index);
+ if (old.replaceBy(m)) {
+ messages.set(index, m);
+ }
+
+ return true;
+ }
+
+ /**
+ * Add a Message
with the specified text to the set.
+ *
+ * @param s the message text.
+ * @throws IllegalStateException if this message set has been made immutable.
+ */
+ public abstract boolean add(String s);
+
+ /**
+ * Add a Message
of the specified type with the specified discriminator to the
+ * set.
+ * @param m the message
+ * @param d the extra discriminator
+ *
+ */
+ public boolean add (E m, String d) {
+ return this.add(m.toString() + ": \"" + d + "\"");
+ }
+
+ @Override
+ public Iteratortrue
if the other
warning should replace
- * this warning. The method should return true
if the other
- * warning indicates a "worse" condition than the current warning.
- *
- * @param other the warning to compare to
- * @return whether this warning should be replaced
- */
- public abstract boolean replaceBy(Warning other);
-
-
- /**
- * Two Warning
s are by default considered equal if they are of
- * the same class. Therefore only one instance of a particular warning type
- * is stored in a {@link WarningSet}. Subclasses may override this method for
- * more specific functionality.
- */
- @Override
- public boolean equals(Object o) {
- return o != null && (o.getClass() == this.getClass());
- }
-
- /**
- * A hashCode
method compatible with the equals
method.
- */
- @Override
- public int hashCode() {
- return this.getClass().hashCode();
- }
-
-
-
+
+
///////////// Specific warning classes /////////////
@@ -80,9 +52,9 @@ public abstract class Warning {
return (trans.get("Warning.LargeAOA.str2") +
UnitGroup.UNITS_ANGLE.getDefaultUnit().toString(aoa) + ").");
}
-
+
@Override
- public boolean replaceBy(Warning other) {
+ public boolean replaceBy(Message other) {
if (!(other instanceof LargeAOA))
return false;
@@ -119,7 +91,7 @@ public abstract class Warning {
}
@Override
- public boolean replaceBy(Warning other) {
+ public boolean replaceBy(Message other) {
return false;
}
}
@@ -134,7 +106,7 @@ public abstract class Warning {
/**
* Sole constructor. The argument is an event which has occurred after landing
*
- * @param event the event that caused this warning
+ * @param _event the event that caused this warning
*/
public EventAfterLanding(FlightEvent _event) {
this.event = _event;
@@ -154,7 +126,7 @@ public abstract class Warning {
}
@Override
- public boolean replaceBy(Warning other) {
+ public boolean replaceBy(Message other) {
return false;
}
}
@@ -249,7 +221,7 @@ public abstract class Warning {
@Override
- public boolean replaceBy(Warning other) {
+ public boolean replaceBy(Message other) {
return false;
}
@@ -349,7 +321,7 @@ public abstract class Warning {
}
@Override
- public boolean replaceBy(Warning other) {
+ public boolean replaceBy(Message other) {
return false;
}
}
diff --git a/core/src/net/sf/openrocket/logging/WarningSet.java b/core/src/net/sf/openrocket/logging/WarningSet.java
index 2c248786b..2220904ba 100644
--- a/core/src/net/sf/openrocket/logging/WarningSet.java
+++ b/core/src/net/sf/openrocket/logging/WarningSet.java
@@ -12,136 +12,37 @@ import net.sf.openrocket.util.Mutable;
* A set that contains multiple Warning
s. When adding a
* {@link Warning} to this set, the contents is checked for a warning of the
* same type. If one is found, then the warning left in the set is determined
- * by the method {@link Warning#replaceBy(Warning)}.
+ * by the method {@link Warning#replaceBy(Message)}.
* Warning
to the set. If a warning of the same type
- * exists in the set, the warning that is left in the set is defined by the
- * method {@link Warning#replaceBy(Warning)}.
- *
- * @throws IllegalStateException if this warning set has been made immutable.
- */
- @Override
- public boolean add(Warning w) {
- mutable.check();
-
- modID++;
- int index = warnings.indexOf(w);
-
- if (index < 0) {
- warnings.add(w);
- return false;
- }
-
- Warning old = warnings.get(index);
- if (old.replaceBy(w)) {
- warnings.set(index, w);
- }
-
- return true;
- }
-
- /**
- * Add a Warning
with the specified text to the set. The Warning object
- * is created using the {@link Warning#fromString(String)} method. If a warning of the
- * same type exists in the set, the warning that is left in the set is defined by the
- * method {@link Warning#replaceBy(Warning)}.
- *
- * @param s the warning text.
- * @throws IllegalStateException if this warning set has been made immutable.
- */
- public boolean add(String s) {
- mutable.check();
- return add(Warning.fromString(s));
- }
+public class WarningSet extends MessageSetWarning
with the specified text to the set. The Warning object
+ * is created using the {@link Message#fromString(String)} method. If a warning of the
+ * same type exists in the set, the warning that is left in the set is defined by the
+ * method {@link Warning#replaceBy(Message)}.
+ *
+ * @param s the message text.
+ * @throws IllegalStateException if this message set has been made immutable.
+ */
+ public boolean add(String s) {
+ mutable.check();
+ return add(Warning.fromString(s));
+ }
- /**
- * Add a Warning
of the specified type with the specified discriminator to the
- * set.
- * @param w the warning
- * @param d the extra discriminator
- *
- */
- public boolean add (Warning w, String d) {
- return this.add(w.toString() + ": \"" + d + "\"");
- }
-
- @Override
- public Iterator