01: package com.calipso.reportgenerator.common;
02:
03: import com.calipso.reportgenerator.reportcalculator.*;
04:
05: import java.util.*;
06:
07: /**
08: *
09: * User: soliveri
10: * Date: Dec 16, 2003
11: * Time: 2:13:10 PM
12: *
13: */
14:
15: public class StaticReportResult extends ReportResult {
16:
17: private DataTree dataTree;
18: private ReportTableModel reportTable = null;
19:
20: public StaticReportResult(ReportSpec reportSpec,
21: ReportQuery reportQuery, DataTree dataTree) {
22: super (reportSpec, reportQuery);
23: this .dataTree = dataTree;
24: }
25:
26: public DataTree getDataTree() {
27: return dataTree;
28: }
29:
30: public ReportTableModel getReportTableModel() throws InfoException {
31: if (reportTable == null) {
32: reportTable = new StaticReportTableModel(this );
33: }
34: return reportTable;
35: }
36:
37: public void resetReportTableModel() {
38: reportTable = null;
39: }
40:
41: public Collection getValuesCollection(boolean ascending) {
42: TreeMap set = new TreeMap(getComparator(ascending));
43: Iterator iterator = getDataTree().getRoot().getSubNodes()
44: .entrySet().iterator();
45: while (iterator.hasNext()) {
46: Map.Entry entry = (Map.Entry) iterator.next();
47: DataTreeNode node = (DataTreeNode) entry.getValue();
48: set.put(node.getMetrics()[0], entry);
49: }
50: return set.entrySet();
51: }
52:
53: private Comparator getComparator(boolean ascending) {
54: if (ascending) {
55: return new Comparator() {
56: public int compare(Object o1, Object o2) {
57: return ((SharedFloat) o1).compareTo(o2);
58: }
59: };
60: } else {
61: return new Comparator() {
62: public int compare(Object o1, Object o2) {
63: return -((SharedFloat) o1).compareTo(o2);
64: }
65: };
66: }
67: }
68:
69: public ReportSpec getReportSpec() {
70: return super .getReportSpec();
71: }
72:
73: public ReportQuery getReportQuery() {
74: return super.getReportQuery();
75: }
76:
77: }
|