Added sourceID to boats in race.

-All boats in race will now have a sourceID.
-SourceID will be used in XML object for boat.

#story[778]
This commit is contained in:
David Wu
2017-04-21 16:22:23 +12:00
parent ec716058c6
commit 5397d14d3c
7 changed files with 129 additions and 13 deletions
+6 -6
View File
@@ -24,10 +24,10 @@ public class Constants {
public static final double wakeScale = 10;
public static final BoatInRace[] OFFICIAL_AC35_COMPETITORS = new BoatInRace[]
{new BoatInRace("Oracle Team USA", 30.0, Color.BLUEVIOLET, "Oracle"),
new BoatInRace("Land Rover BAR", 23.0, Color.BLACK, "BGR"),
new BoatInRace("SoftBank Team Japan", 27.0, Color.RED, "JPN"),
new BoatInRace("Groupama Team France", 25.0, Color.ORANGE, "FRA"),
new BoatInRace("Artemis Racing", 22.5, Color.DARKOLIVEGREEN, "SWE"),
new BoatInRace("Emirates Team New Zealand", 62, Color.LIMEGREEN, "ETNZ")};
{new BoatInRace("Oracle Team USA", 30.0, Color.BLUEVIOLET, "Oracle", 121),
new BoatInRace("Land Rover BAR", 23.0, Color.BLACK, "BGR", 122),
new BoatInRace("SoftBank Team Japan", 27.0, Color.RED, "JPN", 123),
new BoatInRace("Groupama Team France", 25.0, Color.ORANGE, "FRA", 124),
new BoatInRace("Artemis Racing", 22.5, Color.DARKOLIVEGREEN, "SWE", 125),
new BoatInRace("Emirates Team New Zealand", 62, Color.LIMEGREEN, "ETNZ", 126)};
}
+5 -1
View File
@@ -12,6 +12,7 @@ public class Boat {
private double velocity;
private StringProperty velocityProp;
private String abbrev;
private int sourceID;
/**
* Boat initialiser which keeps all of the information of the boat.
@@ -20,11 +21,12 @@ public class Boat {
* @param velocity Speed in m/s that the boat travels at.
* @param abbrev nam abbreviation
*/
public Boat(String name, double velocity, String abbrev) {
public Boat(String name, double velocity, String abbrev, int sourceID) {
this.velocity = velocity;
this.velocityProp = new SimpleStringProperty(String.valueOf(Math.round(velocity)));
this.abbrev = abbrev;
this.name = new SimpleStringProperty(name);
this.sourceID = sourceID;
}
/**
@@ -50,6 +52,8 @@ public class Boat {
return velocity;
}
public int getSourceID() { return sourceID; }
/**
* Sets the speed of the boat in knots.
*
@@ -39,8 +39,8 @@ public class BoatInRace extends Boat {
* @param colour Colour the boat will be displayed as on the map
* @param abbrev of boat
*/
public BoatInRace(String name, double velocity, Color colour, String abbrev) {
super(name, velocity, abbrev);
public BoatInRace(String name, double velocity, Color colour, String abbrev, int sourceID) {
super(name, velocity, abbrev, sourceID);
setColour(colour);
currentLegName = new SimpleStringProperty("");
position = new SimpleStringProperty("-");
+106 -1
View File
@@ -1,9 +1,20 @@
package seng302.Model;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import seng302.Data.RaceData;
import seng302.Model.Race;
import seng302.RaceDataSource;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import java.util.List;
/**
* Created by esa46 on 21/04/17.
*/
@@ -29,13 +40,107 @@ public class Event {
}
public void sendRaceData() {
RaceData raceData = new RaceData();
List<BoatInRace> boatData = raceData.getBoats();
try {
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
//root element
Document doc = docBuilder.newDocument();
Element rootElement = doc.createElement("BoatConfig");
doc.appendChild(rootElement);
//Boats element
Element boats = doc.createElement("Boats");
rootElement.appendChild(boats);
for (int i=0; i < boatData.size(); i++) {
//Boat element
Element boat = doc.createElement("Boat");
//Type attribute
Attr attrType = doc.createAttribute("Type");
attrType.setValue("Mark");
boat.setAttributeNode(attrType);
//SourceID attribute
Attr attrSourceID = doc.createAttribute("SourceID");
attrSourceID.setValue(Integer.toString(boatData.get(i).getSourceID()));
boat.setAttributeNode(attrSourceID);
//ShapeID attribute
Attr attrShapeID = doc.createAttribute("ShapeID");
attrShapeID.setValue("0");
boat.setAttributeNode(attrShapeID);
//HullNum attribute
Attr attrHullNum = doc.createAttribute("HullNum");
attrHullNum.setValue("RG01");
boat.setAttributeNode(attrHullNum);
//StoweName attribute
Attr attrStoweName = doc.createAttribute("StoweName");
attrStoweName.setValue(boatData.get(i).getAbbrev());
boat.setAttributeNode(attrStoweName);
//ShortName attribute
Attr attrShortName = doc.createAttribute("ShortName");
attrShortName.setValue(boatData.get(i).getAbbrev());
boat.setAttributeNode(attrShortName);
//BoatName attribute
Attr attrBoatName = doc.createAttribute("BoatName");
attrBoatName.setValue(boatData.get(i).toString());
boat.setAttributeNode(attrBoatName);
//GPSCoord for element
Element GPSCoord = doc.createElement("GPSposition");
//Z axis attribute
Attr attrZCoord = doc.createAttribute("Z");
attrZCoord.setValue("0");
GPSCoord.setAttributeNode(attrZCoord);
//Y axis attribute
Attr attrYCoord = doc.createAttribute("Y");
attrYCoord.setValue(Double.toString(boatData.get(i).getCurrentPosition().getLatitude()));
GPSCoord.setAttributeNode(attrYCoord);
//X axis attribute
Attr attrXCoord = doc.createAttribute("X");
attrXCoord.setValue(Double.toString(boatData.get(i).getCurrentPosition().getLongitude()));
GPSCoord.setAttributeNode(attrXCoord);
//Write GPSCoord to boat
boat.appendChild(GPSCoord);
//Write boat to boats
boats.appendChild(boat);
}
TransformerFactory trasformerFactory = TransformerFactory.newInstance();
Transformer transformer = trasformerFactory.newTransformer();
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(System.out);
transformer.transform(source,result);
} catch (Exception e) {}
}
public void sendBoatData() {
RaceData boatData = new RaceData();
}
@@ -71,7 +71,8 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
String name = getTextValueOfNode((Element) nBoats.item(i), "name");
String abbrev = getTextValueOfNode((Element) nBoats.item(i), "abbr");
double velo = Double.parseDouble(getTextValueOfNode((Element) nBoats.item(i), "speed"));
BoatInRace boat = new BoatInRace(name, velo, colors[i], abbrev);
int sourceID = Integer.parseInt(getTextValueOfNode((Element) nBoats.item(i), "sourceID"));
BoatInRace boat = new BoatInRace(name, velo, colors[i], abbrev, sourceID);
boat.setCurrentPosition(startPt1);
if (legs.size() > 0) {
boat.setCurrentLeg(legs.get(0));