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 class Graph {
027:
028: private final List<TeamCar> teamCars;
029: private final List<TurnSetup> setups;
030: private final Map<ResultsKey, Result> results;
031:
032: private final Circuit circuit;
033: private final Lap lap;
034:
035: public Graph(Result result) {
036: teamCars = new ArrayList<TeamCar>();
037: setups = new ArrayList<TurnSetup>();
038: results = new HashMap<ResultsKey, Result>();
039: circuit = result.getCircuit();
040: lap = result.getLap();
041: }
042:
043: public void addResult(TeamCar teamCar, Result result) {
044: TurnSetup setup = result.getSetup();
045: results.put(new ResultsKey(teamCar, setup), result);
046: if (!teamCars.contains(teamCar)) {
047: teamCars.add(teamCar);
048: }
049: if (!setups.contains(setup)) {
050: setups.add(setup);
051: }
052: }
053:
054: public Circuit circuit() {
055: return circuit;
056: }
057:
058: public Lap lap() {
059: return lap;
060: }
061:
062: public void compareCheckSums() {
063:
064: for (TurnSetup setup : setups()) {
065:
066: long checkSum = 0;
067: boolean first = true;
068:
069: for (TeamCar teamCar : teamCars()) {
070:
071: if (first) {
072: Result res = results.get(new ResultsKey(teamCar,
073: setup));
074: if (res != null) {
075: checkSum = res.getCheckSum();
076: first = false;
077: }
078: } else {
079: Result res = results.get(new ResultsKey(teamCar,
080: setup));
081: if (res != null) {
082: if (checkSum != res.getCheckSum()) {
083: System.err
084: .println("Inconsistent checksum for "
085: + res.getTeam().name()
086: + " in "
087: + circuit.name()
088: + ":" + lap.name());
089: }
090: }
091: }
092: }
093: }
094: }
095:
096: public List<TeamCar> teamCars() {
097: return Collections.unmodifiableList(teamCars);
098: }
099:
100: public List<TurnSetup> setups() {
101: return Collections.unmodifiableList(setups);
102: }
103:
104: public final long timeFor(TeamCar teamCar, TurnSetup setup) {
105: Result res = results.get(new ResultsKey(teamCar, setup));
106: if (res == null) {
107: return Integer.MAX_VALUE;
108: }
109: return res.getTime();
110: }
111:
112: private class ResultsKey {
113:
114: final TeamCar teamCar;
115: final TurnSetup setup;
116:
117: public ResultsKey(TeamCar teamCar, TurnSetup setup) {
118: this .teamCar = teamCar;
119: this .setup = setup;
120: }
121:
122: @Override
123: public boolean equals(Object obj) {
124: if (obj == this ) {
125: return true;
126: }
127: if (obj == null || obj.getClass() != getClass()) {
128: return false;
129: }
130: ResultsKey key = (ResultsKey) obj;
131: return teamCar.equals(key.teamCar)
132: && setup.equals(key.setup);
133: }
134:
135: @Override
136: public int hashCode() {
137: return teamCar.hashCode() + setup.hashCode();
138: }
139: }
140: }
|