1 package net.sf.openrocket.aerodynamics;
3 import java.util.AbstractSet;
4 import java.util.ArrayList;
5 import java.util.Iterator;
7 import net.sf.openrocket.util.BugException;
10 * A set that contains multiple <code>Warning</code>s. When adding a
11 * {@link Warning} to this set, the contents is checked for a warning of the
12 * same type. If one is found, then the warning left in the set is determined
13 * by the method {@link #Warning.replaceBy(Warning)}.
15 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
17 public class WarningSet extends AbstractSet<Warning> implements Cloneable {
19 private ArrayList<Warning> warnings = new ArrayList<Warning>();
23 * Add a <code>Warning</code> to the set. If a warning of the same type
24 * exists in the set, the warning that is left in the set is defined by the
25 * method {@link Warning#replaceBy(Warning)}.
28 public boolean add(Warning w) {
29 int index = warnings.indexOf(w);
36 Warning old = warnings.get(index);
37 if (old.replaceBy(w)) {
38 warnings.set(index, w);
45 * Add a <code>Warning</code> with the specified text to the set. The Warning object
46 * is created using the {@link Warning#fromString(String)} method. If a warning of the
47 * same type exists in the set, the warning that is left in the set is defined by the
48 * method {@link Warning#replaceBy(Warning)}.
50 * @param s the warning text.
52 public boolean add(String s) {
53 return add(Warning.fromString(s));
58 public Iterator<Warning> iterator() {
59 return warnings.iterator();
64 return warnings.size();
67 @SuppressWarnings("unchecked")
69 public WarningSet clone() {
72 WarningSet newSet = (WarningSet) super.clone();
73 newSet.warnings = (ArrayList<Warning>) this.warnings.clone();
76 } catch (CloneNotSupportedException e) {
77 throw new BugException("CloneNotSupportedException occurred, report bug!",e);
83 public String toString() {
86 for (Warning w: warnings) {
91 return "WarningSet[" + s + "]";