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 package org.ximtec.igesture.core;
28
29 import java.util.ArrayList;
30 import java.util.List;
31
32
33
34
35
36
37
38
39
40 public class TestSet extends DefaultDataObject {
41
42 public static final String PROPERTY_NAME = "name";
43 public static final String PROPERTY_TEST_CLASSES = "testClasses";
44
45 public static final String NOISE = "None";
46
47 private List<TestClass> testClasses;
48
49 private String name;
50
51
52
53
54
55
56
57 public TestSet(String name) {
58 super();
59 testClasses = new ArrayList<TestClass>();
60 setName(name);
61
62 }
63
64
65
66
67
68
69
70 public void add(Gesture<?> sample) {
71 if (sample == null) {
72 return;
73 }
74
75 TestClass testClass = getTestClass(sample.getName());
76 if (testClass == null) {
77 testClass = new TestClass(sample.getName());
78 addTestClass(testClass);
79
80 }
81 testClass.add(sample);
82 }
83
84
85 public TestClass getTestClass(String name){
86 for(TestClass testClass:testClasses){
87 if(testClass.getName().equals(name)){
88 return testClass;
89 }
90 }
91 return null;
92 }
93
94 public void addTestClass(TestClass testClass) {
95 if (testClass != null) {
96 if (getTestClass(testClass.getName()) == null) {
97 testClasses.add(testClass);
98
99 propertyChangeSupport.fireIndexedPropertyChange(
100 PROPERTY_TEST_CLASSES, 0, null, testClass);
101 }
102 else {
103 addAll(testClass.getGestures());
104 }
105 }
106 }
107
108
109 public void addTestClasses(List<TestClass> testClasses) {
110 if (testClasses == null) {
111 return;
112 }
113 for (TestClass testClass : testClasses) {
114 addTestClass(testClass);
115 }
116 }
117
118
119
120
121
122
123
124 public void addAll(List<Gesture<?>> samples) {
125 for (Gesture<?> sample : samples) {
126 add(sample);
127 }
128
129 for (Gesture< ? > sample : samples) {
130 propertyChangeSupport.fireIndexedPropertyChange(PROPERTY_TEST_CLASSES,
131 samples.indexOf(sample), null, sample);
132 }
133
134 }
135
136
137
138
139
140
141
142 public void remove(TestClass testClass) {
143 testClasses.remove(testClass);
144 propertyChangeSupport.fireIndexedPropertyChange(PROPERTY_TEST_CLASSES, 0,
145 testClass, null);
146 }
147
148
149
150
151
152
153
154 public List<TestClass> getTestClasses() {
155 return new ArrayList<TestClass>(testClasses);
156 }
157
158
159
160
161
162
163
164
165 public int getNoiseSize() {
166
167 TestClass testClass = getTestClass(TestSet.NOISE);
168 return testClass == null ? 0 : testClass.size();
169
170 }
171
172
173
174
175
176
177
178 public void setName(String name) {
179 String oldValue = this.name;
180 this.name = name;
181 propertyChangeSupport.firePropertyChange(PROPERTY_NAME, oldValue, name);
182 }
183
184
185
186
187
188
189
190 public String getName() {
191 if (name == null) {
192 name = String.valueOf(System.currentTimeMillis());
193 }
194
195 return name;
196 }
197
198
199
200
201
202
203
204 public int size() {
205 return testClasses.size();
206 }
207
208
209
210
211
212
213
214 public int getNumberOfSamples() {
215 int result = 0;
216
217 for (TestClass testClass : testClasses) {
218 result += testClass.size();
219 }
220
221 return result;
222 }
223
224
225
226
227
228
229
230 public boolean isEmpty() {
231 return testClasses.isEmpty();
232 }
233
234
235
236
237
238 @Override
239 public void accept(Visitor visitor) {
240 visitor.visit(this);
241
242 for (TestClass testClass : testClasses) {
243 testClass.accept(visitor);
244 }
245
246 }
247
248
249 @Override
250 public String toString() {
251 return name;
252 }
253
254 }