01: package jimm.datavision.testdata;
02:
03: import java.io.*;
04: import java.util.ArrayList;
05: import java.util.Iterator;
06:
07: public class AggregateTestData {
08:
09: protected String col1;
10: protected String col2;
11: protected int value;
12:
13: public static Iterator aggregateTestData(String filePath) {
14: ArrayList data = new ArrayList();
15: try {
16: BufferedReader in = new BufferedReader(new FileReader(
17: filePath));
18: String line;
19: while ((line = in.readLine()) != null) {
20: int pos1 = line.indexOf(',');
21: int pos2 = line.indexOf(',', pos1 + 1);
22: String col1 = line.substring(0, pos1);
23: String col2 = line.substring(pos1 + 1, pos2);
24: int value = Integer.parseInt(line.substring(pos2 + 1));
25: data.add(new AggregateTestData(col1, col2, value));
26: }
27: } catch (IOException ioe) {
28: System.err.println(ioe);
29: }
30: return data.iterator();
31: }
32:
33: public AggregateTestData(String c1, String c2, int v) {
34: col1 = c1;
35: col2 = c2;
36: value = v;
37: }
38:
39: public String col1() {
40: return col1;
41: }
42:
43: public String col2() {
44: return col2;
45: }
46:
47: public int value() {
48: return value;
49: }
50:
51: public static void main(String[] args) {
52: Iterator iter = AggregateTestData
53: .aggregateTestData("aggregate_test.dat");
54: while (iter.hasNext()) {
55: AggregateTestData data = (AggregateTestData) iter.next();
56: System.out.println(data.col1 + ", " + data.col2 + ", "
57: + data.value);
58: }
59: }
60:
61: }
|