1 package org.catacomb.numeric.data;
2
3
4 import java.util.HashMap;
5
6 import org.catacomb.interlish.reflect.Narrower;
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 public class DataExtractor {
28
29 HashMap<String, NumDataSet> sources;
30
31
32 public DataExtractor() {
33 sources = new HashMap<String, NumDataSet>();
34 }
35
36
37 public NumDataSet getDataSet(String s) {
38 return (sources.get(s));
39 }
40
41
42
43 public void addDataSet(NumDataSet dset) {
44 sources.put(dset.getName(), dset);
45 }
46
47
48
49
50 public double getScalar(String path) {
51 DataSlice ds = get(path);
52 return ds.getScalar();
53 }
54
55
56 public double[] getVector(String path) {
57 double[] ret = null;
58 if (path.startsWith("{")) {
59 ret = getExplicitVector(path);
60 } else {
61 DataSlice ds = get(path);
62 ret = ds.getVector();
63 }
64 return ret;
65 }
66
67
68 public int[] getIntVector(String path) {
69 DataSlice ds = get(path);
70 int[] ret = ds.getIntVector();
71 return ret;
72 }
73
74
75
76 public void mark(String path) {
77 DataSlice dsret = constructSlice(path);
78 dsret.mark(sources);
79
80 }
81
82
83
84 private DataSlice get(String path) {
85 DataSlice dsret = constructSlice(path);
86 dsret.resolve(sources);
87
88 return dsret;
89 }
90
91
92
93 private DataSlice constructSlice(String path) {
94
95 String[] bits = path.split("\\.");
96 DataSlice dsret = new DataSlice(bits[0]);
97
98 DataSlice dscur = dsret;
99 for (int i = 1; i < bits.length; i++) {
100 DataSlice dssub = new DataSlice(bits[i]);
101 dscur.setSubslice(dssub);
102 dscur = dssub;
103 }
104 return dsret;
105 }
106
107
108
109 public double[] getExplicitVector(String stxt) {
110 double[] ret = Narrower.readDoubleArray(stxt);
111 return ret;
112 }
113
114 }
115
116