1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 package junitx.ddtunit.data.processing;
39
40 import java.util.List;
41 import java.util.Vector;
42
43 import junitx.ddtunit.data.IDataSet;
44
45 class ReferenceProcessor implements IReferenceListener {
46 private List refList;
47
48 private IDataSet clusterDataSet;
49
50 private String groupId;
51
52 private String testId;
53
54
55
56
57
58 public ReferenceProcessor(IDataSet clusterDataSet, String groupId,
59 String testId) {
60 this.refList = new Vector();
61 this.clusterDataSet = clusterDataSet;
62 setGroupId(groupId);
63 setTestId(testId);
64 }
65
66 public ReferenceProcessor(IDataSet clusterDataSet) {
67 this(clusterDataSet, ParserConstants.UNKNOWN, ParserConstants.UNKNOWN);
68 }
69
70 public void add(IReferenceInfo info) {
71 this.refList.add(info);
72 }
73
74 public void resolve() {
75 checkRankingOrder();
76 sortRefList();
77 for (int pos = 0; pos < this.refList.size(); pos++) {
78 IReferenceInfo info = (IReferenceInfo) this.refList.get(pos);
79 info.resolve(this.clusterDataSet, this.getGroupId(), this
80 .getTestId());
81 }
82 clear();
83 }
84
85 private void checkRankingOrder() {
86 for (int countA = 0; countA < this.refList.size(); countA++) {
87 IReferenceInfo infoA = (IReferenceInfo) this.refList.get(countA);
88 for (int countB = countA + 1; countB < this.refList.size(); countB++) {
89 IReferenceInfo infoB = (IReferenceInfo) this.refList
90 .get(countB);
91 infoA.raiseRankOf(infoB);
92 infoB.raiseRankOf(infoA);
93 }
94 }
95 }
96
97 private void sortRefList() {
98 boolean hasChanged = true;
99 while (hasChanged) {
100 hasChanged = false;
101 for (int countA = 0; countA < this.refList.size(); countA++) {
102 IReferenceInfo infoA = (IReferenceInfo) this.refList
103 .get(countA);
104 int aPos = countA;
105 for (int countB = countA + 1; countB < this.refList.size(); countB++) {
106 IReferenceInfo infoB = (IReferenceInfo) this.refList
107 .get(countB);
108 if (infoA.getRank() < infoB.getRank()) {
109 hasChanged = true;
110 this.refList.set(countB, infoA);
111 this.refList.set(aPos, infoB);
112 aPos = countB;
113 }
114 }
115 if (hasChanged) {
116 countA = -1;
117 hasChanged = false;
118 }
119 }
120 }
121 }
122
123 private void clear() {
124 this.refList.clear();
125 }
126
127 public String getGroupId() {
128 return this.groupId;
129 }
130
131 public void setGroupId(String groupId) {
132 if (groupId == null) {
133 this.groupId = ParserConstants.UNKNOWN;
134 } else {
135 this.groupId = groupId;
136 }
137 }
138
139 public String getTestId() {
140 return this.testId;
141 }
142
143 public void setTestId(String testId) {
144 if (testId == null) {
145 this.testId = ParserConstants.UNKNOWN;
146 } else {
147 this.testId = testId;
148 }
149 }
150 }