--- /dev/null
+package no.uio.ifi.refaktor.prefix;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.Map;
+
+import no.uio.ifi.refaktor.analyze.analyzers.ExtractAndMoveMethodAnalyzer;
+
+import org.eclipse.jdt.core.dom.IBinding;
+
+/**
+ * A set for collecting prefixes (see {@link Prefix}}).
+ *
+ * It can increment a counter in a prefix each time an equal
+ * prefix is registered with the set. In addition
+ * it can produce the set that is this set, minus the
+ * prefixes from another set that are enclosed by the
+ * prefixes in this set.
+ */
+public class PrefixSet implements Iterable<Prefix> {
+
+ final Map<Prefix, Prefix> prefixes = new HashMap<Prefix, Prefix>();
+
+ public PrefixSet() {
+ }
+
+ private PrefixSet(PrefixSet initialElements) {
+ initialElements.generated_6159305087095010416(this);
+ }
+
+ public void add(Prefix prefix) {
+ assert prefix != null: "A " + this.getClass().getName() + " will not accept a null value";
+
+ prefix.generated_7681675865424797515(this);
+ }
+
+ void remove(Prefix prefix) {
+ prefixes.remove(prefix);
+ }
+
+ public boolean contains(Prefix prefix) {
+ boolean res = prefixes.containsKey(prefix);
+ // TODO: Show prefixes in debugging output as well?
+ if (res)
+ prefix.generated_1397335264344119528(this);
+ else
+ assert get(prefix) == null : prefix;
+ return res;
+ }
+
+ @Override
+ public Iterator<Prefix> iterator() {
+ return prefixes.values().iterator();
+ }
+
+ public boolean isEmpty() {
+ return prefixes.isEmpty();
+ }
+
+ public LinkedList<Prefix> toList() {
+ return new LinkedList<Prefix>(prefixes.values());
+ }
+
+ public Prefix get(Prefix prefix) {
+ return prefixes.get(prefix);
+ }
+
+ public void registerAllSubPrefixesOf(Prefix prefix) {
+ for (Prefix p: prefix.getSubPrefixes())
+ register(p);
+ }
+
+ private void register(Prefix prefix) {
+ prefix.generated_57330167832506990(this);
+ }
+
+ @Override
+ public String toString() {
+ String str = "";
+ for (Prefix p: this) {
+ str = p.generated_797445745298232673(str);
+ }
+ return str;
+ }
+
+ /**
+ * Creates a set of prefixes that are the prefixes of this set,
+ * minus the prefixes that are enclosing the prefixes of the
+ * other set. A prefix is enclosing another if the other prefix
+ * is a sub-prefix of the first prefix.
+ *
+ * @param other The set of prefixes that are to be checked against this one.
+ * @return The set of prefixes that are not enclosing the ones in the other set.
+ */
+ public PrefixSet minusEnclosedPrefixesFrom(PrefixSet other) {
+ PrefixSet prefixSet = shallowCopy();
+ return prefixSet.generated_2595563403172319290(other, this);
+ }
+
+ private PrefixSet shallowCopy() {
+ return new PrefixSet(this);
+ }
+
+ private void removeEnclosingPrefixesFromPrefixSet(PrefixSet prefixSet, PrefixSet other) {
+ for (Prefix p: other) {
+ for (Prefix prefix: this) {
+ prefix.generated_9031955363082597180(prefixSet, p);
+ }
+ }
+ }
+
+ public void clear() {
+ prefixes.clear();
+ }
+
+ public int size() {
+ return prefixes.size();
+ }
+
+ public boolean generated_1969731573483763072() {
+ IBinding binding = toList().getFirst().getVariableBindingOfFirstExpression();
+ for (Prefix prefix: this) {
+ if (!prefix.getVariableBindingOfFirstExpression().isEqualTo(binding))
+ return true;
+ }
+ return false;
+ }
+
+ public PrefixSet generated_4055185070511117122(ExtractAndMoveMethodAnalyzer extractandmovemethodanalyzer) {
+ extractandmovemethodanalyzer.removeUnusablePrefixes(this);
+ return this;
+ }
+
+ public void generated_6159305087095010416(PrefixSet prefixset) {
+ prefixset.prefixes.putAll(prefixes);
+ }
+
+ public PrefixSet generated_2595563403172319290(PrefixSet other, PrefixSet prefixset) {
+ prefixset.removeEnclosingPrefixesFromPrefixSet(this, other);
+ return this;
+ }
+}