Merge commit '42b2e5ca519766e37ce6941ba4faecc9691cc403' into upstream
[debian/openrocket] / core / src / de / congrace / exp4j / VariableSet.java
diff --git a/core/src/de/congrace/exp4j/VariableSet.java b/core/src/de/congrace/exp4j/VariableSet.java
new file mode 100644 (file)
index 0000000..f567006
--- /dev/null
@@ -0,0 +1,42 @@
+package de.congrace.exp4j;
+
+import java.util.HashSet;
+
+public class VariableSet extends HashSet<Variable> {
+
+       /**
+        * 
+        */
+       private static final long serialVersionUID = -4212803364398351279L;
+
+       public boolean add(Variable v){
+               Variable previous = getVariableNamed(v.getName());
+               if ( previous != null ){
+                       this.remove( previous );
+               }
+                       
+               return super.add(v);
+       }
+       
+       public Variable getVariableNamed(String name){
+               for (Variable var : this){
+                       if (var.getName().equals(name) ){
+                               return var;
+                       }
+               }
+               return null;
+       }
+       
+       public String[] getVariableNames(){
+               if (this.size() == 0){
+                       return null;
+               }
+               String names[] = new String[this.size()];
+               int i = 0;
+               for (Variable var : this){
+                       names[i] = var.getName();
+                       i++;
+               }
+               return names;
+       }       
+}