-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSumTreeDemo.java
More file actions
58 lines (50 loc) · 1.94 KB
/
SumTreeDemo.java
File metadata and controls
58 lines (50 loc) · 1.94 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import java.util.ArrayList;
import java.util.List;
public class SumTreeDemo {
public static void main(String[] args){
/*
* Testing data
*/
List<Object[]> testList = new ArrayList<Object[]>();
testList.add(new Object[]{"CompanyA", "DepartmentA", "TeamA", 3});
testList.add(new Object[]{"CompanyA", "DepartmentA", "TeamB", 2});
testList.add(new Object[]{"CompanyA", "DepartmentB", "TeamB", 1});
testList.add(new Object[]{"CompanyA", "DepartmentB", "TeamC", 7});
testList.add(new Object[]{"CompanyB", "DepartmentB", "TeamD", 13});
testList.add(new Object[]{"CompanyB", "DepartmentC", "TeamD", 17});
testList.add(new Object[]{"CompanyB", "DepartmentC", "TeamD", 5});
/*
* Building HierarchicalStatistic Tree
*/
IHierarchicalStatisticTree<Object> HST = new SumTree<Object>();
HST.buildTree(testList);
/*
* Print out whole tree
*/
HST.printTree();
// Output:
// [TOTAL:48]
// [TOTAL:48][CompanyA:13]
// [TOTAL:48][CompanyA:13][DepartmentA:5]
// [TOTAL:48][CompanyA:13][DepartmentA:5][TeamA:3]
// [TOTAL:48][CompanyA:13][DepartmentA:5][TeamB:2]
// [TOTAL:48][CompanyA:13][DepartmentB:8]
// [TOTAL:48][CompanyA:13][DepartmentB:8][TeamB:1]
// [TOTAL:48][CompanyA:13][DepartmentB:8][TeamC:7]
// [TOTAL:48][CompanyB:35]
// [TOTAL:48][CompanyB:35][DepartmentB:13]
// [TOTAL:48][CompanyB:35][DepartmentB:13][TeamD:13]
// [TOTAL:48][CompanyB:35][DepartmentC:22]
// [TOTAL:48][CompanyB:35][DepartmentC:22][TeamD:22]
System.out.println(HST.getResult(new Object[]{"CompanyB", "DepartmentB"}));
//Output:13
System.out.println(HST.getResult(new Object[]{"CompanyA", "DepartmentB", "TeamC"}));
//Output:7
System.out.println(HST.getResult(new Object[]{}));
//Output:48
System.out.println(HST.getResult(new Object[]{"CompanyB", "DepartmentC", null}));
//Output:0 (No Such Key)
System.out.println(HST.getResult(new Object[]{"CompanyB", null, "TeamD"}));
//Output:0 (No Such Key)
}
}