You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
2.6 KiB
83 lines
2.6 KiB
package seng302.Model;
|
|
|
|
import seng302.Data.BoatData;
|
|
import seng302.Data.RaceData;
|
|
import seng302.Data.RegattaData;
|
|
import seng302.DataInput.BoatDataSource;
|
|
import seng302.DataInput.RaceDataSource;
|
|
import seng302.DataInput.RegattaDataSource;
|
|
import seng302.Exceptions.InvalidBoatDataException;
|
|
import seng302.Exceptions.InvalidRaceDataException;
|
|
import seng302.Exceptions.InvalidRegattaDataException;
|
|
import seng302.MockOutput;
|
|
|
|
import java.io.*;
|
|
import java.nio.charset.Charset;
|
|
import java.nio.charset.StandardCharsets;
|
|
import java.nio.file.Files;
|
|
import java.nio.file.Paths;
|
|
|
|
|
|
/**
|
|
* Created by esa46 on 21/04/17.
|
|
*/
|
|
public class Event {
|
|
|
|
RaceDataSource raceDataSource;
|
|
RegattaDataSource regattaDataSource;
|
|
BoatDataSource boatDataSource;
|
|
|
|
MockOutput mockOutput;
|
|
|
|
public Event(RaceDataSource raceData, RegattaDataSource regattaData, BoatDataSource boatDataSource) {
|
|
this.raceDataSource = raceData;
|
|
this.regattaDataSource = regattaData;
|
|
this.boatDataSource = boatDataSource;
|
|
try {
|
|
mockOutput = new MockOutput();
|
|
new Thread(mockOutput).start();
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Send the initial race data and then begin race simulation
|
|
*/
|
|
public void start() {
|
|
|
|
sendXMLs();
|
|
int scaleFactor = 5;//TEMP - was 15.
|
|
Race newRace = new Race(raceDataSource, scaleFactor, mockOutput);
|
|
new Thread((newRace)).start();
|
|
}
|
|
|
|
|
|
private void sendXMLs() {
|
|
try {
|
|
|
|
System.out.println("Sending Regatta");
|
|
String regattaData = readFile("mock/src/main/resources/mockXML/regattaTest.xml", StandardCharsets.UTF_8);
|
|
mockOutput.setRegattaXml(regattaData);
|
|
mockOutput.parseXMLString(regattaData, 26);
|
|
|
|
System.out.println("Sending Race");
|
|
String raceData = readFile("mock/src/main/resources/mockXML/raceTest.xml", StandardCharsets.UTF_8);
|
|
mockOutput.setRaceXml(raceData);
|
|
mockOutput.parseXMLString(raceData, 26);
|
|
|
|
System.out.println("Sending Boat");
|
|
String boatData = readFile("mock/src/main/resources/mockXML/boatTest.xml", StandardCharsets.UTF_8);
|
|
mockOutput.setBoatsXml(boatData);
|
|
mockOutput.parseXMLString(boatData, 26);
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
static String readFile(String path, Charset encoding) throws IOException {
|
|
byte[] encoded = Files.readAllBytes(Paths.get(path));
|
|
return new String(encoded, encoding);
|
|
}
|
|
}
|