X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;f=case-study%2Frefaktor-after%2Fsrc%2Fno%2Fuio%2Fifi%2Frefaktor%2Fprefix%2FPrefixSet.java;fp=case-study%2Frefaktor-after%2Fsrc%2Fno%2Fuio%2Fifi%2Frefaktor%2Fprefix%2FPrefixSet.java;h=1d037fb91b546edc287331a138b14a52c42fd07d;hb=1b2798f607d741df30e5197f427381cbff326adc;hp=0000000000000000000000000000000000000000;hpb=246231e4bd9b24345490f369747c0549ca308c4d;p=ifi-stolz-refaktor.git diff --git a/case-study/refaktor-after/src/no/uio/ifi/refaktor/prefix/PrefixSet.java b/case-study/refaktor-after/src/no/uio/ifi/refaktor/prefix/PrefixSet.java new file mode 100644 index 00000000..1d037fb9 --- /dev/null +++ b/case-study/refaktor-after/src/no/uio/ifi/refaktor/prefix/PrefixSet.java @@ -0,0 +1,143 @@ +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 { + + final Map prefixes = new HashMap(); + + 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 iterator() { + return prefixes.values().iterator(); + } + + public boolean isEmpty() { + return prefixes.isEmpty(); + } + + public LinkedList toList() { + return new LinkedList(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; + } +}