1 package org.catacomb.numeric.data;
2
3 import org.catacomb.report.E;
4
5 import java.util.ArrayList;
6
7
8
9 public class DataSetArray extends DataItem {
10
11 NumDataSet first;
12
13 ArrayList<NumDataSet> items;
14
15 NumDataSet[] bufdsa;
16
17
18
19 public DataSetArray() {
20 this("error");
21 }
22
23
24 public DataSetArray(String s) {
25 super(s);
26 items = new ArrayList<NumDataSet>();
27 }
28
29
30
31 public DataSetArray(String s, NumDataSet[] dsa) {
32 super(s);
33 items = new ArrayList<NumDataSet>();
34 name = s;
35 for (int i = 0; i < dsa.length; i++) {
36 items.add(dsa[i]);
37 }
38 }
39
40
41
42 public void add(NumDataSet ds) {
43 if (first == null) {
44 first = ds;
45
46 } else {
47 if (first.matches(ds)) {
48
49 } else {
50 E.error("mismatched sets in data set array " + first + " " + ds);
51 }
52 }
53 bufdsa = null;
54 items.add(ds);
55 }
56
57
58 public int length() {
59 return items.size();
60 }
61
62
63 public NumDataSet[] getDataSets() {
64 if (bufdsa == null) {
65 bufdsa = (items.toArray(new NumDataSet[0]));
66 }
67 return bufdsa;
68 }
69
70 public NumDataSet firstElement() {
71 NumDataSet[] dsa = getDataSets();
72 return dsa[0];
73 }
74
75
76
77 public DataSetArray slice(String cond) {
78 DataSetArray ret = null;
79 if (cond.equals("*")) {
80 ret = this;
81
82 } else {
83 NumDataSet[] dsa = getDataSets();
84
85 int index = 0;
86 try {
87 index = Integer.parseInt(cond);
88
89 } catch (Exception ex) {
90 E.error(" cant slice dat aset array with " + cond + " " + ex);
91 }
92 ret = new DataSetArray();
93 ret.add(dsa[index]);
94
95 }
96 return ret;
97 }
98
99
100 public DataItem getMarked() {
101 DataSetArray ret = new DataSetArray(getName());
102 NumDataSet[] sds = getDataSets();
103 for (int i = 0; i < sds.length; i++) {
104 if (sds[i].isMarked()) {
105 ret.add(sds[i].copyMarked());
106 }
107 }
108 return ret;
109 }
110
111
112 }