X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=core%2Fsrc%2Fde%2Fcongrace%2Fexp4j%2FVariableSet.java;fp=core%2Fsrc%2Fde%2Fcongrace%2Fexp4j%2FVariableSet.java;h=f567006fe228ab5937c0505092340ac866d147bc;hb=9349577cdfdff682b2aabd6daa24fdc3a7449b58;hp=0000000000000000000000000000000000000000;hpb=30ba0a882f0c061176ba14dbf86d3d6fad096c02;p=debian%2Fopenrocket diff --git a/core/src/de/congrace/exp4j/VariableSet.java b/core/src/de/congrace/exp4j/VariableSet.java new file mode 100644 index 00000000..f567006f --- /dev/null +++ b/core/src/de/congrace/exp4j/VariableSet.java @@ -0,0 +1,42 @@ +package de.congrace.exp4j; + +import java.util.HashSet; + +public class VariableSet extends HashSet { + + /** + * + */ + 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; + } +}