Create an error message & set
This commit is contained in:
parent
2bc93530bc
commit
c5a2fc44df
59
core/src/net/sf/openrocket/logging/Error.java
Normal file
59
core/src/net/sf/openrocket/logging/Error.java
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
package net.sf.openrocket.logging;
|
||||||
|
|
||||||
|
import net.sf.openrocket.l10n.Translator;
|
||||||
|
import net.sf.openrocket.startup.Application;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An error message wrapper.
|
||||||
|
*/
|
||||||
|
public abstract class Error extends Message {
|
||||||
|
private static final Translator trans = Application.getTranslator();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return an Error with the specific text.
|
||||||
|
*/
|
||||||
|
public static Error fromString(String text) {
|
||||||
|
return new Error.Other(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
///////////// Specific Error classes /////////////
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An unspecified error type. This error type holds a <code>String</code>
|
||||||
|
* describing it. Two errors of this type are considered equal if the strings
|
||||||
|
* are identical.
|
||||||
|
*/
|
||||||
|
public static class Other extends Error {
|
||||||
|
private final String description;
|
||||||
|
|
||||||
|
public Other(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object other) {
|
||||||
|
if (!(other instanceof Other))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
Other o = (Other) other;
|
||||||
|
return (o.description.equals(this.description));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return description.hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean replaceBy(Message other) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
32
core/src/net/sf/openrocket/logging/ErrorSet.java
Normal file
32
core/src/net/sf/openrocket/logging/ErrorSet.java
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
package net.sf.openrocket.logging;
|
||||||
|
|
||||||
|
import net.sf.openrocket.util.BugException;
|
||||||
|
|
||||||
|
public class ErrorSet extends MessageSet<Error> {
|
||||||
|
/**
|
||||||
|
* Add an <code>Error</code> with the specified text to the set. The Error object
|
||||||
|
* is created using the {@link Error#fromString(String)} method. If an error of the
|
||||||
|
* same type exists in the set, the error that is left in the set is defined by the
|
||||||
|
* method {@link Error#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(Error.fromString(s));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ErrorSet clone() {
|
||||||
|
try {
|
||||||
|
ErrorSet newSet = (ErrorSet) super.clone();
|
||||||
|
newSet.messages = this.messages.clone();
|
||||||
|
newSet.mutable = this.mutable.clone();
|
||||||
|
return newSet;
|
||||||
|
|
||||||
|
} catch (CloneNotSupportedException e) {
|
||||||
|
throw new BugException("CloneNotSupportedException occurred, report bug!", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user