]> git.uio.no Git - ifi-stolz-refaktor.git/blame - case-study/refaktor-after/src/no/uio/ifi/refaktor/prefix/PrefixSet.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / refaktor-after / src / no / uio / ifi / refaktor / prefix / PrefixSet.java
CommitLineData
1b2798f6
EK
1package no.uio.ifi.refaktor.prefix;
2
3import java.util.HashMap;
4import java.util.Iterator;
5import java.util.LinkedList;
6import java.util.Map;
7
8import no.uio.ifi.refaktor.analyze.analyzers.ExtractAndMoveMethodAnalyzer;
9
10import org.eclipse.jdt.core.dom.IBinding;
11
12/**
13 * A set for collecting prefixes (see {@link Prefix}}).
14 *
15 * It can increment a counter in a prefix each time an equal
16 * prefix is registered with the set. In addition
17 * it can produce the set that is this set, minus the
18 * prefixes from another set that are enclosed by the
19 * prefixes in this set.
20 */
21public class PrefixSet implements Iterable<Prefix> {
22
23 final Map<Prefix, Prefix> prefixes = new HashMap<Prefix, Prefix>();
24
25 public PrefixSet() {
26 }
27
28 private PrefixSet(PrefixSet initialElements) {
29 initialElements.generated_6159305087095010416(this);
30 }
31
32 public void add(Prefix prefix) {
33 assert prefix != null: "A " + this.getClass().getName() + " will not accept a null value";
34
35 prefix.generated_7681675865424797515(this);
36 }
37
38 void remove(Prefix prefix) {
39 prefixes.remove(prefix);
40 }
41
42 public boolean contains(Prefix prefix) {
43 boolean res = prefixes.containsKey(prefix);
44 // TODO: Show prefixes in debugging output as well?
45 if (res)
46 prefix.generated_1397335264344119528(this);
47 else
48 assert get(prefix) == null : prefix;
49 return res;
50 }
51
52 @Override
53 public Iterator<Prefix> iterator() {
54 return prefixes.values().iterator();
55 }
56
57 public boolean isEmpty() {
58 return prefixes.isEmpty();
59 }
60
61 public LinkedList<Prefix> toList() {
62 return new LinkedList<Prefix>(prefixes.values());
63 }
64
65 public Prefix get(Prefix prefix) {
66 return prefixes.get(prefix);
67 }
68
69 public void registerAllSubPrefixesOf(Prefix prefix) {
70 for (Prefix p: prefix.getSubPrefixes())
71 register(p);
72 }
73
74 private void register(Prefix prefix) {
75 prefix.generated_57330167832506990(this);
76 }
77
78 @Override
79 public String toString() {
80 String str = "";
81 for (Prefix p: this) {
82 str = p.generated_797445745298232673(str);
83 }
84 return str;
85 }
86
87 /**
88 * Creates a set of prefixes that are the prefixes of this set,
89 * minus the prefixes that are enclosing the prefixes of the
90 * other set. A prefix is enclosing another if the other prefix
91 * is a sub-prefix of the first prefix.
92 *
93 * @param other The set of prefixes that are to be checked against this one.
94 * @return The set of prefixes that are not enclosing the ones in the other set.
95 */
96 public PrefixSet minusEnclosedPrefixesFrom(PrefixSet other) {
97 PrefixSet prefixSet = shallowCopy();
98 return prefixSet.generated_2595563403172319290(other, this);
99 }
100
101 private PrefixSet shallowCopy() {
102 return new PrefixSet(this);
103 }
104
105 private void removeEnclosingPrefixesFromPrefixSet(PrefixSet prefixSet, PrefixSet other) {
106 for (Prefix p: other) {
107 for (Prefix prefix: this) {
108 prefix.generated_9031955363082597180(prefixSet, p);
109 }
110 }
111 }
112
113 public void clear() {
114 prefixes.clear();
115 }
116
117 public int size() {
118 return prefixes.size();
119 }
120
121 public boolean generated_1969731573483763072() {
122 IBinding binding = toList().getFirst().getVariableBindingOfFirstExpression();
123 for (Prefix prefix: this) {
124 if (!prefix.getVariableBindingOfFirstExpression().isEqualTo(binding))
125 return true;
126 }
127 return false;
128 }
129
130 public PrefixSet generated_4055185070511117122(ExtractAndMoveMethodAnalyzer extractandmovemethodanalyzer) {
131 extractandmovemethodanalyzer.removeUnusablePrefixes(this);
132 return this;
133 }
134
135 public void generated_6159305087095010416(PrefixSet prefixset) {
136 prefixset.prefixes.putAll(prefixes);
137 }
138
139 public PrefixSet generated_2595563403172319290(PrefixSet other, PrefixSet prefixset) {
140 prefixset.removeEnclosingPrefixesFromPrefixSet(this, other);
141 return this;
142 }
143}