001: /*
002: This file is part of the PolePosition database benchmark
003: http://www.polepos.org
004:
005: This program is free software; you can redistribute it and/or
006: modify it under the terms of the GNU General Public License
007: as published by the Free Software Foundation; either version 2
008: of the License, or (at your option) any later version.
009:
010: This program is distributed in the hope that it will be useful,
011: but WITHOUT ANY WARRANTY; without even the implied warranty of
012: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013: GNU General Public License for more details.
014:
015: You should have received a copy of the GNU General Public
016: License along with this program; if not, write to the Free
017: Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
018: MA 02111-1307, USA. */
019:
020: package org.polepos.reporters;
021:
022: import java.util.*;
023:
024: import org.polepos.framework.*;
025:
026: public abstract class GraphReporter extends Reporter {
027:
028: private Map<CircuitLap, Graph> mGraphs;
029: private List<Circuit> mCircuits;
030:
031: @Override
032: public void startSeason() {
033: }
034:
035: @Override
036: public boolean append() {
037: return false;
038: }
039:
040: @Override
041: public String file() {
042: return "F1Results.txt";
043: }
044:
045: @Override
046: public void reportTaskName(int number, String name) {
047: // do nothing
048: }
049:
050: @Override
051: public void reportTeam(Team team) {
052: // do nothing
053: }
054:
055: @Override
056: public void reportCar(Car car) {
057: // do nothing
058: }
059:
060: @Override
061: public void beginResults() {
062: }
063:
064: @Override
065: public void reportResult(Result result) {
066:
067: if (mGraphs == null) {
068: mGraphs = new HashMap<CircuitLap, Graph>();
069: }
070:
071: if (mCircuits == null) {
072: mCircuits = new ArrayList<Circuit>();
073: }
074:
075: Circuit circuit = result.getCircuit();
076:
077: if (!mCircuits.contains(circuit)) {
078: mCircuits.add(circuit);
079: }
080:
081: CircuitLap cl = new CircuitLap(circuit, result.getLap());
082: Graph graph = mGraphs.get(cl);
083: if (graph == null) {
084: graph = new Graph(result);
085: mGraphs.put(cl, graph);
086: }
087: graph.addResult(mTeamCar, result);
088:
089: }
090:
091: @Override
092: public void endSeason() {
093: if (mGraphs != null) {
094: System.out.println("Checking checksums for "
095: + getClass().getName());
096: for (Circuit circuit : mCircuits) {
097: for (Lap lap : circuit.laps()) {
098: Graph graph = mGraphs.get(new CircuitLap(circuit,
099: lap));
100: if (graph != null) {
101: graph.compareCheckSums();
102: report(graph);
103: }
104: }
105: }
106: finish();
107: }
108: }
109:
110: protected abstract void report(Graph graph);
111:
112: protected abstract void finish();
113: }
|