KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > polepos > reporters > GraphReporter


1 /*
2 This file is part of the PolePosition database benchmark
3 http://www.polepos.org
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public
16 License along with this program; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18 MA 02111-1307, USA. */

19
20 package org.polepos.reporters;
21
22 import java.util.*;
23
24 import org.polepos.framework.*;
25
26
27 public abstract class GraphReporter extends Reporter{
28     
29     
30     private Map<CircuitLap,Graph> mGraphs;
31     private List<Circuit> mCircuits;
32     
33     
34     @Override JavaDoc
35     public void startSeason() {
36     }
37     
38     @Override JavaDoc
39     public boolean append() {
40         return false;
41     }
42     
43     @Override JavaDoc
44     public String JavaDoc file() {
45         return "F1Results.txt";
46     }
47     
48     @Override JavaDoc
49     public void reportTaskName(int number, String JavaDoc name){
50         // do nothing
51
}
52
53     @Override JavaDoc
54     public void reportTeam(Team team) {
55         // do nothing
56
}
57
58     @Override JavaDoc
59     public void reportCar(Car car) {
60         // do nothing
61
}
62     
63     @Override JavaDoc
64     public void beginResults() {
65     }
66     
67     @Override JavaDoc
68     public void reportResult(Result result) {
69         
70         if(mGraphs == null){
71             mGraphs = new HashMap<CircuitLap,Graph>();
72         }
73         
74         if(mCircuits == null){
75             mCircuits = new ArrayList <Circuit>();
76         }
77         
78         Circuit circuit = result.getCircuit();
79         
80         if(! mCircuits.contains(circuit)){
81             mCircuits.add(circuit);
82         }
83         
84         CircuitLap cl = new CircuitLap(circuit, result.getLap());
85         Graph graph = mGraphs.get(cl);
86         if(graph == null){
87             graph = new Graph(result);
88             mGraphs.put(cl, graph);
89         }
90         graph.addResult(mTeamCar, result);
91         
92     }
93     
94     @Override JavaDoc
95     public void endSeason() {
96         if(mGraphs != null){
97             System.out.println("Checking checksums for " + getClass().getName());
98             for(Circuit circuit : mCircuits){
99                 for(Lap lap : circuit.laps()){
100                     Graph graph =mGraphs.get(new CircuitLap(circuit, lap));
101                     if(graph != null){
102                         graph.compareCheckSums();
103                         report(graph);
104                     }
105                 }
106             }
107             finish();
108         }
109     }
110
111     protected abstract void report(Graph graph);
112     protected abstract void finish();
113 }
114
Popular Tags