1 19 20 package org.polepos.framework; 21 22 import java.util.*; 23 24 import org.polepos.reporters.*; 25 26 public class Racer implements Runnable { 27 28 29 34 private static final boolean XSS_THREAD = false; 35 36 private final List<Circuit> circuits; 37 private final List<Team> teams; 38 39 public Racer(List<Circuit> circuits, List<Team> teams) { 40 this.circuits = circuits; 41 this.teams = teams; 42 43 if(! XSS_THREAD){ 44 run(); 45 return; 46 } 47 48 new Thread (this).start(); 49 50 synchronized (this) { 51 try { 52 this.wait(Integer.MAX_VALUE); 53 } catch (InterruptedException e) { 54 e.printStackTrace(); 55 } 56 } 57 } 58 59 public void run() { 60 61 synchronized (this) { 62 63 long start = System.currentTimeMillis(); 64 65 Reporter[] reporters = new Reporter[] { new PlainTextReporter(), new PDFReporter(), 66 new CSVReporter(), new HTMLReporter()}; 67 68 for (Reporter reporter : reporters) { 69 reporter.startSeason(); 70 } 71 72 for (Circuit circuit : circuits) { 73 74 System.out.println("* Racing on " + circuit.name()); 75 76 for (Reporter reporter : reporters) { 77 reporter.sendToCircuit(circuit); 78 } 79 80 for (Team team : teams) { 81 82 Driver[] drivers = team.nominate(circuit); 83 84 if (drivers == null || drivers.length == 0) { 85 86 for (Reporter reporter : reporters) { 87 reporter.noDriver(team, circuit); 88 } 89 90 } else { 91 for (Driver driver : drivers) { 92 93 for (Car car : team.cars()) { 94 95 if (car != null) { 96 97 System.out.println("** On track: " + team.name() + "/" 98 + car.name()); 99 100 TurnSetup[] setups = circuit.lapSetups(); 101 TurnResult[] results = circuit.race(team, car, driver); 102 103 for (Reporter reporter : reporters) { 104 reporter.report(team, car, setups, results); 105 } 106 } 107 } 108 } 109 } 110 } 111 } 112 113 for (Reporter reporter : reporters) { 114 reporter.endSeason(); 115 } 116 117 long stop = System.currentTimeMillis(); 118 long duration = stop - start; 119 120 System.out.println("\n****************************************************"); 121 System.out.println("The F1 season was run O.K. without lethal accidents."); 122 System.out.println("****************************************************\n"); 123 System.out.println("Overall time taken: " + duration + "ms\n"); 124 System.out.println("All output from this benchmark run can be found in:"); 125 System.out.println(reporters[0].path()); 126 this.notify(); 127 } 128 129 } 130 } 131 | Popular Tags |