Removed output stream, started refactoring BoatDataClass
#story[778]
This commit is contained in:
@@ -11,7 +11,6 @@ import seng302.Model.Event;
|
|||||||
|
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
|
||||||
|
|
||||||
public class App extends Application {
|
public class App extends Application {
|
||||||
|
|
||||||
@@ -27,10 +26,9 @@ public class App extends Application {
|
|||||||
@Override
|
@Override
|
||||||
public void start(Stage primaryStage) {
|
public void start(Stage primaryStage) {
|
||||||
try {
|
try {
|
||||||
OutputStream outputStream = System.out;//TEMP currently using System.out, but should replace this with tcp socket we are sending over.
|
|
||||||
RaceDataSource raceData = new RaceXMLReader("raceXML/bermuda_AC35.xml");
|
RaceDataSource raceData = new RaceXMLReader("raceXML/bermuda_AC35.xml");
|
||||||
RegattaDataSource regattaData = new RegattaXMLReader("mockXML/regattaTest.xml");
|
RegattaDataSource regattaData = new RegattaXMLReader("mockXML/regattaTest.xml");
|
||||||
Event raceEvent = new Event(raceData, regattaData, outputStream);
|
Event raceEvent = new Event(raceData, regattaData);
|
||||||
raceEvent.start();
|
raceEvent.start();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|||||||
@@ -26,8 +26,9 @@ import java.util.List;
|
|||||||
public class RaceData {
|
public class RaceData {
|
||||||
|
|
||||||
private RaceDataSource dataSource;
|
private RaceDataSource dataSource;
|
||||||
private String raceID;
|
Document doc;
|
||||||
private String raceType;
|
Element raceElement;
|
||||||
|
|
||||||
private OffsetDateTime creationTimeDate;
|
private OffsetDateTime creationTimeDate;
|
||||||
private OffsetDateTime raceStartTime;
|
private OffsetDateTime raceStartTime;
|
||||||
private List<BoatInRace> participants;
|
private List<BoatInRace> participants;
|
||||||
@@ -36,8 +37,6 @@ public class RaceData {
|
|||||||
|
|
||||||
public RaceData(RaceDataSource dataSource) {
|
public RaceData(RaceDataSource dataSource) {
|
||||||
this.dataSource = dataSource;
|
this.dataSource = dataSource;
|
||||||
this.raceID = dataSource.getRaceId();
|
|
||||||
this.raceType = "Fleet";
|
|
||||||
creationTimeDate = OffsetDateTime.now();
|
creationTimeDate = OffsetDateTime.now();
|
||||||
raceStartTime = OffsetDateTime.now().plusMinutes(3);
|
raceStartTime = OffsetDateTime.now().plusMinutes(3);
|
||||||
participants = dataSource.getBoats();
|
participants = dataSource.getBoats();
|
||||||
@@ -51,19 +50,15 @@ public class RaceData {
|
|||||||
try {
|
try {
|
||||||
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
|
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
|
||||||
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
|
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
|
||||||
|
doc = docBuilder.newDocument();
|
||||||
|
|
||||||
// root elements
|
|
||||||
Document doc = docBuilder.newDocument();
|
//root element;
|
||||||
Element raceElement = doc.createElement("Race");
|
raceElement = doc.createElement("Race");
|
||||||
doc.appendChild(raceElement);
|
doc.appendChild(raceElement);
|
||||||
|
|
||||||
Element raceIdElement = doc.createElement("RaceID");
|
appendRaceId();
|
||||||
raceIdElement.appendChild(doc.createTextNode(raceID));
|
appendRaceType();
|
||||||
raceElement.appendChild(raceIdElement);
|
|
||||||
|
|
||||||
Element raceTypeElement = doc.createElement("RaceType");
|
|
||||||
raceTypeElement.appendChild(doc.createTextNode(raceType));
|
|
||||||
raceElement.appendChild(raceTypeElement);
|
|
||||||
|
|
||||||
Element creationTimeElement = doc.createElement("CreationTimeDate");
|
Element creationTimeElement = doc.createElement("CreationTimeDate");
|
||||||
creationTimeElement.appendChild(doc.createTextNode(creationTimeDate.toString()));
|
creationTimeElement.appendChild(doc.createTextNode(creationTimeDate.toString()));
|
||||||
@@ -164,4 +159,19 @@ public class RaceData {
|
|||||||
throw new InvalidRaceDataException();
|
throw new InvalidRaceDataException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void appendRaceId() {
|
||||||
|
Element raceIdElement = doc.createElement("RaceID");
|
||||||
|
raceIdElement.appendChild(doc.createTextNode(dataSource.getRaceId()));
|
||||||
|
raceElement.appendChild(raceIdElement);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void appendRaceType() {
|
||||||
|
Element raceTypeElement = doc.createElement("RaceType");
|
||||||
|
raceTypeElement.appendChild(doc.createTextNode(dataSource.getRaceType()));
|
||||||
|
raceElement.appendChild(raceTypeElement);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ public interface RaceDataSource {
|
|||||||
List<Marker> getMarkers();
|
List<Marker> getMarkers();
|
||||||
|
|
||||||
String getRaceId();
|
String getRaceId();
|
||||||
|
String getRaceType();
|
||||||
|
|
||||||
GPSCoordinate getMark();
|
GPSCoordinate getMark();
|
||||||
GPSCoordinate getMapTopLeft();
|
GPSCoordinate getMapTopLeft();
|
||||||
|
|||||||
@@ -11,10 +11,6 @@ import seng302.Exceptions.InvalidRegattaDataException;
|
|||||||
import seng302.Mock.RaceDataSource;
|
import seng302.Mock.RaceDataSource;
|
||||||
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by esa46 on 21/04/17.
|
* Created by esa46 on 21/04/17.
|
||||||
*/
|
*/
|
||||||
@@ -22,13 +18,10 @@ public class Event {
|
|||||||
|
|
||||||
RaceDataSource raceDataSource;
|
RaceDataSource raceDataSource;
|
||||||
RegattaDataSource regattaDataSource;
|
RegattaDataSource regattaDataSource;
|
||||||
///The stream to which we send all data.
|
|
||||||
private OutputStream outputStream;
|
|
||||||
|
|
||||||
public Event(RaceDataSource raceData, RegattaDataSource regattaData, OutputStream outputStream) {
|
public Event(RaceDataSource raceData, RegattaDataSource regattaData) {
|
||||||
this.raceDataSource = raceData;
|
this.raceDataSource = raceData;
|
||||||
this.regattaDataSource = regattaData;
|
this.regattaDataSource = regattaData;
|
||||||
this.outputStream = outputStream;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start()
|
public void start()
|
||||||
@@ -42,7 +35,7 @@ public class Event {
|
|||||||
|
|
||||||
System.out.println("RACE STARTING!!\n\n");//TEMP REMOVE debug
|
System.out.println("RACE STARTING!!\n\n");//TEMP REMOVE debug
|
||||||
|
|
||||||
Race newRace = new Race(raceDataSource, 15, this.outputStream);
|
Race newRace = new Race(raceDataSource, 15);
|
||||||
new Thread((newRace)).start();
|
new Thread((newRace)).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,19 +45,7 @@ public class Event {
|
|||||||
RegattaData regattaData = new RegattaData(regattaDataSource);
|
RegattaData regattaData = new RegattaData(regattaDataSource);
|
||||||
String xmlString = regattaData.createXML();
|
String xmlString = regattaData.createXML();
|
||||||
|
|
||||||
//TODO now we should place in XML message object.
|
System.out.println(xmlString); // to be replaced by TCPClient.send(xmlString) type function call
|
||||||
//TODO now we should serialize xml message object.
|
|
||||||
//TODO now we should write serialized xml message over this.outputStream.
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
this.outputStream.write(xmlString.toString().getBytes());//TEMP currently we output the XML doc, not the serialized message.
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
throw new InvalidRegattaDataException();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,18 +55,7 @@ public class Event {
|
|||||||
//Serialize race data to an XML as a string.
|
//Serialize race data to an XML as a string.
|
||||||
String xmlString = raceData.createXML();
|
String xmlString = raceData.createXML();
|
||||||
|
|
||||||
//TODO now we should place in XML message object.
|
System.out.println(xmlString); // to be replaced by TCPClient.send(xmlString) type function call
|
||||||
//TODO now we should serialize xml message object.
|
|
||||||
//TODO now we should write serialized xml message over this.outputStream.
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
this.outputStream.write(xmlString.getBytes());//TEMP currently we output the XML doc, not the serialized message.
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
throw new InvalidRaceDataException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendBoatData() throws InvalidBoatDataException
|
public void sendBoatData() throws InvalidBoatDataException
|
||||||
@@ -94,19 +64,7 @@ public class Event {
|
|||||||
//Serialize race data to an XML as a string.
|
//Serialize race data to an XML as a string.
|
||||||
String xmlString = boatData.createXML();
|
String xmlString = boatData.createXML();
|
||||||
|
|
||||||
//TODO now we should place in XML message object.
|
System.out.println(xmlString); // to be replaced by TCPClient.send(xmlString) type function call
|
||||||
//TODO now we should serialize xml message object.
|
|
||||||
//TODO now we should write serialized xml message over this.outputStream.
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
this.outputStream.write(xmlString.getBytes());//TEMP currently we output the XML doc, not the serialized message.
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
throw new InvalidBoatDataException();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,8 +14,6 @@ import seng302.RaceEventMessages.BoatLocationMessage;
|
|||||||
|
|
||||||
|
|
||||||
import java.awt.geom.Point2D;
|
import java.awt.geom.Point2D;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
@@ -34,29 +32,23 @@ public class Race implements Runnable {
|
|||||||
private int lastFPS = 20;
|
private int lastFPS = 20;
|
||||||
private int dnfChance = 0; //percentage chance a boat fails at each checkpoint
|
private int dnfChance = 0; //percentage chance a boat fails at each checkpoint
|
||||||
protected int heartbeat = 0;
|
protected int heartbeat = 0;
|
||||||
protected boolean raceFinish = false;
|
|
||||||
protected int scaleFactor;
|
protected int scaleFactor;
|
||||||
|
|
||||||
protected int PRERACE_TIME = 120000; //time in milliseconds to pause during pre-race
|
protected int PRERACE_TIME = 120000; //time in milliseconds to pause during pre-race
|
||||||
|
|
||||||
//Outputstream to write messages to.
|
|
||||||
private OutputStream outputStream;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initailiser for Race
|
* Initailiser for Race
|
||||||
*
|
*
|
||||||
* @param boats Takes in an array of boats that are participating in the race.
|
* @param boats Takes in an array of boats that are participating in the race.
|
||||||
* @param legs Number of marks in order that the boats pass in order to complete the race.
|
* @param legs Number of marks in order that the boats pass in order to complete the race.
|
||||||
* @param scaleFactor for race
|
* @param scaleFactor for race
|
||||||
* @param outputStream Outputstream to write messages to.
|
|
||||||
*/
|
*/
|
||||||
public Race(List<BoatInRace> boats, List<Leg> legs, int scaleFactor, OutputStream outputStream) {
|
public Race(List<BoatInRace> boats, List<Leg> legs, int scaleFactor) {
|
||||||
|
|
||||||
this.startingBoats = FXCollections.observableArrayList(boats);
|
this.startingBoats = FXCollections.observableArrayList(boats);
|
||||||
this.legs = legs;
|
this.legs = legs;
|
||||||
this.legs.add(new Leg("Finish", this.legs.size()));
|
this.legs.add(new Leg("Finish", this.legs.size()));
|
||||||
this.scaleFactor = scaleFactor;
|
this.scaleFactor = scaleFactor;
|
||||||
this.outputStream = outputStream;
|
|
||||||
|
|
||||||
if (startingBoats != null && startingBoats.size() > 0) {
|
if (startingBoats != null && startingBoats.size() > 0) {
|
||||||
initialiseBoats();
|
initialiseBoats();
|
||||||
@@ -64,13 +56,8 @@ public class Race implements Runnable {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Constructor used in testing
|
public Race(RaceDataSource raceData, int scaleFactor) {
|
||||||
public Race(List<BoatInRace> boats, List<Leg> legs, int scaleFactor) {
|
this(raceData.getBoats(), raceData.getLegs(), scaleFactor);
|
||||||
this(boats, legs, scaleFactor, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Race(RaceDataSource raceData, int scaleFactor, OutputStream outputStream) {
|
|
||||||
this(raceData.getBoats(), raceData.getLegs(), scaleFactor, outputStream);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -222,15 +209,6 @@ public class Race implements Runnable {
|
|||||||
//We have finished creating the message.
|
//We have finished creating the message.
|
||||||
//TODO at this point, we need to send the event to the visualiser.
|
//TODO at this point, we need to send the event to the visualiser.
|
||||||
//System.out.println(boatLocationMessage);//TEMP debug print
|
//System.out.println(boatLocationMessage);//TEMP debug print
|
||||||
try
|
|
||||||
{
|
|
||||||
//TODO we should actually serialize the boat message before writing to output.
|
|
||||||
outputStream.write(boatLocationMessage.toString().getBytes());
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -351,4 +351,8 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
|
|||||||
public String getRaceId() { return raceID; }
|
public String getRaceId() { return raceID; }
|
||||||
|
|
||||||
public List<Marker> getMarkers() { return markers; }
|
public List<Marker> getMarkers() { return markers; }
|
||||||
|
|
||||||
|
public String getRaceType() {
|
||||||
|
return "FLEET";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user