-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sum.java
36 lines (32 loc) · 811 Bytes
/
Sum.java
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
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
public class Sum {
Table t;
String[] toSum;
Iterator<int[][]> inputIter;
public Sum(IterableWithTable inputI, String[] sums) {
toSum = sums;
System.err.println("NEW SUM:"+inputI.toString()+" OVER:"+toString());
inputIter = inputI.iterator();
t = inputI.getTable();
}
public int[] doSum() {
int[] result = new int[toSum.length];
while (inputIter.hasNext()) {
int[][] arrayList = inputIter.next();
for (int[] inRow : arrayList) {
if (inRow != null) {
for (int i = 0; i < result.length; i++) {
result[i] += inRow[t.colNames.get(toSum[i])];// get the actual row # from map
}
}
}
}
return result;
}
@Override
public String toString() {
return Arrays.toString(toSum);
}
}