1 package net.sf.openrocket.aerodynamics;
3 import java.util.AbstractSet;
4 import java.util.ArrayList;
5 import java.util.Iterator;
8 * A set that contains multiple <code>Warning</code>s. When adding a
9 * {@link Warning} to this set, the contents is checked for a warning of the
10 * same type. If one is found, then the warning left in the set is determined
11 * by the method {@link #Warning.replaceBy(Warning)}.
13 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
15 public class WarningSet extends AbstractSet<Warning> implements Cloneable {
17 private ArrayList<Warning> warnings = new ArrayList<Warning>();
21 * Add a <code>Warning</code> to the set. If a warning of the same type
22 * exists in the set, the warning that is left in the set is defined by the
23 * method {@link Warning#replaceBy(Warning)}.
26 public boolean add(Warning w) {
27 int index = warnings.indexOf(w);
34 Warning old = warnings.get(index);
35 if (old.replaceBy(w)) {
36 warnings.set(index, w);
43 * Add a <code>Warning</code> with the specified text to the set. The Warning object
44 * is created using the {@link Warning#fromString(String)} method. If a warning of the
45 * same type exists in the set, the warning that is left in the set is defined by the
46 * method {@link Warning#replaceBy(Warning)}.
48 * @param s the warning text.
50 public boolean add(String s) {
51 return add(Warning.fromString(s));
56 public Iterator<Warning> iterator() {
57 return warnings.iterator();
62 return warnings.size();
65 @SuppressWarnings("unchecked")
67 public WarningSet clone() {
70 WarningSet newSet = (WarningSet) super.clone();
71 newSet.warnings = (ArrayList<Warning>) this.warnings.clone();
74 } catch (CloneNotSupportedException e) {
75 throw new RuntimeException("CloneNotSupportedException occurred, report bug!",e);
81 public String toString() {
84 for (Warning w: warnings) {
89 return "WarningSet[" + s + "]";