From f31a98778753379449526ca389d5b3674f76f864 Mon Sep 17 00:00:00 2001 From: cbt24 Date: Wed, 10 May 2017 16:56:21 +1200 Subject: [PATCH] Reads BoatDataSource into StreamedCourseXMLReader so the latter can function as a single source of static information for the race. - Mock.StreamedCourseXMLReader populates participant and mark list from BoatDataSource - Added CompoundMarker class to accommodate Mark data from Boat XML - Had to check for Yacht type in Visualiser.BoatXMLReader - Added a missing coordinate value to raceTest.xml - Marker class still exists due to large number of tests, which should be transitioned to CompoundMark - IMPORTANT: race is no longer functional #story[881] --- mock/src/main/java/seng302/App.java | 9 +- mock/src/main/java/seng302/Data/RaceData.java | 20 +- .../seng302/DataInput/BoatDataSource.java | 6 +- .../java/seng302/DataInput/BoatXMLReader.java | 46 +-- .../seng302/DataInput/RaceDataSource.java | 7 +- .../java/seng302/DataInput/RaceXMLReader.java | 38 +-- mock/src/main/java/seng302/Model/Boat.java | 4 +- .../main/java/seng302/Model/CompoundMark.java | 71 +++++ mock/src/main/java/seng302/Model/Event.java | 2 +- mock/src/main/java/seng302/Model/Leg.java | 30 +- mock/src/main/java/seng302/Model/Mark.java | 14 +- .../{CompoundMarker.java => Marker.java} | 10 +- mock/src/main/java/seng302/Model/Race.java | 27 +- .../Model/StreamedCourseXMLException.java | 7 + .../Model/StreamedCourseXMLReader.java | 274 ++++++++++++++++++ mock/src/main/resources/mockXML/raceTest.xml | 2 +- .../seng302/DataInput/BoatXMLReaderTest.java | 5 +- .../src/test/java/seng302/Model/BoatTest.java | 48 +-- ...dMarkerTest.java => CompoundMarkTest.java} | 12 +- mock/src/test/java/seng302/Model/LegTest.java | 22 +- .../src/test/java/seng302/Model/RaceTest.java | 4 +- .../main/java/seng302/Mock/BoatXMLReader.java | 2 +- 22 files changed, 518 insertions(+), 142 deletions(-) create mode 100644 mock/src/main/java/seng302/Model/CompoundMark.java rename mock/src/main/java/seng302/Model/{CompoundMarker.java => Marker.java} (88%) create mode 100644 mock/src/main/java/seng302/Model/StreamedCourseXMLException.java create mode 100644 mock/src/main/java/seng302/Model/StreamedCourseXMLReader.java rename mock/src/test/java/seng302/Model/{CompoundMarkerTest.java => CompoundMarkTest.java} (76%) diff --git a/mock/src/main/java/seng302/App.java b/mock/src/main/java/seng302/App.java index de74be36..40077276 100644 --- a/mock/src/main/java/seng302/App.java +++ b/mock/src/main/java/seng302/App.java @@ -6,6 +6,8 @@ import javafx.stage.Stage; import org.xml.sax.SAXException; import seng302.DataInput.*; import seng302.Model.Event; +import seng302.Model.StreamedCourseXMLException; +import seng302.Model.StreamedCourseXMLReader; import javax.xml.parsers.ParserConfigurationException; @@ -13,6 +15,7 @@ import java.io.IOException; import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Paths; +import java.text.ParseException; public class App extends Application { @@ -35,9 +38,9 @@ public class App extends Application { @Override public void start(Stage primaryStage) { try { - RaceDataSource raceData = new RaceXMLReader("mockXML/raceTest.xml"); RegattaDataSource regattaData = new RegattaXMLReader("mockXML/regattaTest.xml"); BoatDataSource boatData = new BoatXMLReader("mockXML/boatTest.xml"); + RaceDataSource raceData = new StreamedCourseXMLReader("mockXML/raceTest.xml", boatData); Event raceEvent = new Event(raceData, regattaData, boatData); raceEvent.start(); } catch (IOException e) { @@ -46,6 +49,10 @@ public class App extends Application { e.printStackTrace(); } catch (ParserConfigurationException e) { e.printStackTrace(); + } catch (ParseException e) { + e.printStackTrace(); + } catch (StreamedCourseXMLException e) { + e.printStackTrace(); } } } diff --git a/mock/src/main/java/seng302/Data/RaceData.java b/mock/src/main/java/seng302/Data/RaceData.java index bc502d44..cabc5471 100644 --- a/mock/src/main/java/seng302/Data/RaceData.java +++ b/mock/src/main/java/seng302/Data/RaceData.java @@ -5,7 +5,7 @@ import org.w3c.dom.Element; import seng302.DataInput.RaceDataSource; import seng302.Exceptions.InvalidRaceDataException; import seng302.Model.Boat; -import seng302.Model.CompoundMarker; +import seng302.Model.CompoundMark; import seng302.Model.GPSCoordinate; import javax.xml.parsers.DocumentBuilder; @@ -151,9 +151,9 @@ public class RaceData { Element compoundMarkSeqElement = doc.createElement("CompoundMarkSequence"); int i = 1; - for (CompoundMarker compoundMarker : dataSource.getCompoundMarkers()) { + for (CompoundMark compoundMark : dataSource.getCompoundMarks()) { - courseElement.appendChild(createCompoundMarker(compoundMarker, i)); + courseElement.appendChild(createCompoundMarker(compoundMark, i)); compoundMarkSeqElement.appendChild(createCornerElement(i)); i++; } @@ -177,21 +177,21 @@ public class RaceData { } /** - * Creates a compound compoundMarker holding one or two marks,and a sequence number + * Creates a compound compoundMark holding one or two marks,and a sequence number * - * @param compoundMarker compoundMarker + * @param compoundMark compoundMark * @param i sequence number * @return Element compound mark element */ - private Element createCompoundMarker(CompoundMarker compoundMarker, int i) { + private Element createCompoundMarker(CompoundMark compoundMark, int i) { Element compoundMarkElement = doc.createElement("CompoundMark"); compoundMarkElement.setAttribute("CompoundMarkID", i + ""); - compoundMarkElement.setAttribute("Name", compoundMarker.getName()); + compoundMarkElement.setAttribute("Name", compoundMark.getName()); - compoundMarkElement.appendChild(createMark(compoundMarker.getMark1())); + compoundMarkElement.appendChild(createMark(compoundMark.getMark1())); - if (!(compoundMarker.getMark1().equals(compoundMarker.getMark2()))) { - compoundMarkElement.appendChild(createMark(compoundMarker.getMark2())); + if (!(compoundMark.getMark1().equals(compoundMark.getMark2()))) { + compoundMarkElement.appendChild(createMark(compoundMark.getMark2())); } return compoundMarkElement; diff --git a/mock/src/main/java/seng302/DataInput/BoatDataSource.java b/mock/src/main/java/seng302/DataInput/BoatDataSource.java index 73b0a0cc..d8ecfaf2 100644 --- a/mock/src/main/java/seng302/DataInput/BoatDataSource.java +++ b/mock/src/main/java/seng302/DataInput/BoatDataSource.java @@ -3,12 +3,12 @@ package seng302.DataInput; import seng302.Model.Boat; import seng302.Model.Mark; -import java.util.List; +import java.util.Map; /** * Created by cbt24 on 10/05/17. */ public interface BoatDataSource { - List getBoats(); - List getMarkerBoats(); + Map getBoats(); + Map getMarkerBoats(); } diff --git a/mock/src/main/java/seng302/DataInput/BoatXMLReader.java b/mock/src/main/java/seng302/DataInput/BoatXMLReader.java index 5d9524c6..39f6b13e 100644 --- a/mock/src/main/java/seng302/DataInput/BoatXMLReader.java +++ b/mock/src/main/java/seng302/DataInput/BoatXMLReader.java @@ -4,13 +4,12 @@ import org.w3c.dom.Element; import org.w3c.dom.Node; import org.xml.sax.SAXException; import seng302.Model.Boat; +import seng302.Model.GPSCoordinate; import seng302.Model.Mark; import javax.xml.parsers.ParserConfigurationException; import java.io.IOException; -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import java.util.Map; /** @@ -51,7 +50,7 @@ public class BoatXMLReader extends XMLReader implements BoatDataSource { for (int i = 0; i < nBoats.getChildNodes().getLength(); i++) { Node boat = nBoats.getChildNodes().item(i); if (boat.getNodeName().equals("Boat")) { - readSingleBoat(boat); + readBoatNode(boat); } } } @@ -78,34 +77,39 @@ public class BoatXMLReader extends XMLReader implements BoatDataSource { * Reads the information about one boat * Ignored values: ShapeID, StoweName, HullNum, Skipper, Type */ - private void readSingleBoat(Node boatNode) { - Boat boat; - + private void readBoatNode(Node boatNode) { int sourceID = Integer.parseInt(boatNode.getAttributes().getNamedItem("SourceID").getTextContent()); String name = boatNode.getAttributes().getNamedItem("BoatName").getTextContent(); - if (isYachtNode(boatNode)) { - String shortName = boatNode.getAttributes().getNamedItem("ShortName").getTextContent(); - if (exists(boatNode, "Country")) { - String country = boatNode.getAttributes().getNamedItem("Country").getTextContent(); - boat = new Boat(sourceID, name, country); - } else { - boat = new Boat(sourceID, name, shortName); - } - boatMap.put(sourceID, boat); + if (isYachtNode(boatNode)) readYacht(boatNode, sourceID, name); + else readMark(boatNode, sourceID, name); + } + + private void readYacht(Node boatNode, int sourceID, String name) { + String shortName = boatNode.getAttributes().getNamedItem("ShortName").getTextContent(); + if (exists(boatNode, "Country")) { + String country = boatNode.getAttributes().getNamedItem("Country").getTextContent(); + boatMap.put(sourceID, new Boat(sourceID, name, country)); } else { - Mark mark = new Mark(name); - markerMap.put(sourceID, mark); + boatMap.put(sourceID, new Boat(sourceID, name, shortName)); } } + private void readMark(Node boatNode, int sourceID, String name) { + Node nCoord = ((Element)boatNode).getElementsByTagName("GPSposition").item(0); + double x = Double.parseDouble(nCoord.getAttributes().getNamedItem("X").getTextContent()); + double y = Double.parseDouble(nCoord.getAttributes().getNamedItem("Y").getTextContent()); + Mark mark = new Mark(sourceID, name, new GPSCoordinate(x,y)); + markerMap.put(sourceID, mark); + } + @Override - public List getBoats() { - return new ArrayList<>(boatMap.values()); + public Map getBoats() { + return boatMap; } @Override - public List getMarkerBoats() { - return new ArrayList<>(markerMap.values()); + public Map getMarkerBoats() { + return markerMap; } } diff --git a/mock/src/main/java/seng302/DataInput/RaceDataSource.java b/mock/src/main/java/seng302/DataInput/RaceDataSource.java index a58e2543..fac5c15c 100644 --- a/mock/src/main/java/seng302/DataInput/RaceDataSource.java +++ b/mock/src/main/java/seng302/DataInput/RaceDataSource.java @@ -2,10 +2,11 @@ package seng302.DataInput; ; import seng302.Model.Boat; +import seng302.Model.CompoundMark; import seng302.Model.GPSCoordinate; import seng302.Model.Leg; -import seng302.Model.CompoundMarker; +import java.time.ZonedDateTime; import java.util.List; /** @@ -18,13 +19,13 @@ public interface RaceDataSource { List getBoundary(); - List getCompoundMarkers(); + List getCompoundMarks(); int getRaceId(); String getRaceType(); - GPSCoordinate getMark(); + ZonedDateTime getZonedDateTime(); GPSCoordinate getMapTopLeft(); diff --git a/mock/src/main/java/seng302/DataInput/RaceXMLReader.java b/mock/src/main/java/seng302/DataInput/RaceXMLReader.java index 05de160c..e751aad8 100644 --- a/mock/src/main/java/seng302/DataInput/RaceXMLReader.java +++ b/mock/src/main/java/seng302/DataInput/RaceXMLReader.java @@ -5,18 +5,17 @@ import org.w3c.dom.Element; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; -import seng302.Model.Boat; -import seng302.Model.CompoundMarker; -import seng302.Model.GPSCoordinate; -import seng302.Model.Leg; +import seng302.Model.*; import javax.xml.parsers.ParserConfigurationException; import java.io.IOException; +import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.List; /** * Created by fwy13 on 26/03/2017. + * @deprecated please use {@link seng302.Model.StreamedCourseXMLReader} */ public class RaceXMLReader extends XMLReader implements RaceDataSource { private static double COORDINATEPADDING = 0.0005; @@ -27,7 +26,7 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource { private GPSCoordinate mark, startPt1, startPt2, finishPt1, finishPt2, leewardPt1, leewardPt2, windwardPt1, windwardPt2; private GPSCoordinate mapTopLeft, mapBottomRight; private List boundary = new ArrayList<>(); - private List compoundMarkers = new ArrayList<>(); + private List compoundMarks = new ArrayList<>(); /** * Constractor for Race XML @@ -106,8 +105,8 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource { NodeList nMarkers = doc.getElementsByTagName("marker"); for (int i = 0; i < nMarkers.getLength(); i++) { - CompoundMarker compoundMarker = getMarker((Element) nMarkers.item(i)); - if (compoundMarker.getName() != null) compoundMarkers.add(compoundMarker); + CompoundMark compoundMark = getMarker((Element) nMarkers.item(i)); + if (compoundMark.getName() != null) compoundMarks.add(compoundMark); } } @@ -121,10 +120,10 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource { for (int i = 0; i < nLegs.getLength(); i++) { String label = getTextValueOfNode((Element) nLegs.item(i), "name"); NodeList start = ((Element) nLegs.item(i)).getElementsByTagName("start"); - CompoundMarker startCompoundMarker = getMarker(start); + CompoundMark startCompoundMark = getMarker(start); NodeList finish = ((Element) nLegs.item(i)).getElementsByTagName("finish"); - CompoundMarker finishCompoundMarker = getMarker(finish); - legs.add(new Leg(label, startCompoundMarker, finishCompoundMarker, i)); + CompoundMark finishCompoundMark = getMarker(finish); + legs.add(new Leg(label, startCompoundMark, finishCompoundMark, i)); } } @@ -204,7 +203,7 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource { * @param start base nodelist this should be the tag that contains * @return */ - private CompoundMarker getMarker(NodeList start) { + private CompoundMark getMarker(NodeList start) { return getMarker(start, 0); } @@ -215,7 +214,7 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource { * @param startIndex index in the node that has the coordinate tag * @return */ - private CompoundMarker getMarker(NodeList start, int startIndex) { + private CompoundMark getMarker(NodeList start, int startIndex) { return getMarker(start, startIndex, 0); } @@ -227,7 +226,7 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource { * @param nodeIndex coordinate index * @return */ - private CompoundMarker getMarker(NodeList start, int startIndex, int nodeIndex) { + private CompoundMark getMarker(NodeList start, int startIndex, int nodeIndex) { NodeList nodeList = ((Element) start.item(startIndex)).getElementsByTagName("marker"); Element marker = (Element) nodeList.item(nodeIndex); return getMarker(marker); @@ -239,7 +238,7 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource { * @param markerNode marker to turn into coordinates * @return */ - private CompoundMarker getMarker(Element markerNode) { + private CompoundMark getMarker(Element markerNode) { NodeList nCoordinates = markerNode.getElementsByTagName("coordinate"); @@ -251,7 +250,7 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource { side2 = side1; } NodeList name = markerNode.getElementsByTagName("name"); - return name.getLength() == 1 ? new CompoundMarker(getTextValueOfNode((Element) markerNode, "name"), side1, side2) : new CompoundMarker(side1, side2); + return null;//name.getLength() == 1 ? new CompoundMark(getTextValueOfNode((Element) markerNode, "name"), side1, side2) : new CompoundMark(side1, side2); } /** @@ -362,11 +361,16 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource { return raceID; } - public List getCompoundMarkers() { - return compoundMarkers; + public List getCompoundMarks() { + return compoundMarks; } public String getRaceType() { return "FLEET"; } + + @Override + public ZonedDateTime getZonedDateTime() { + return null; + } } diff --git a/mock/src/main/java/seng302/Model/Boat.java b/mock/src/main/java/seng302/Model/Boat.java index 67ba71b1..a53e6626 100644 --- a/mock/src/main/java/seng302/Model/Boat.java +++ b/mock/src/main/java/seng302/Model/Boat.java @@ -41,8 +41,8 @@ public class Boat { public double calculateAzimuth() { GeodeticCalculator calc = new GeodeticCalculator(); - GPSCoordinate start = currentLeg.getStartCompoundMarker().getAverageGPSCoordinate(); - GPSCoordinate end = currentLeg.getEndCompoundMarker().getAverageGPSCoordinate(); + GPSCoordinate start = currentLeg.getStartCompoundMark().getAverageGPSCoordinate(); + GPSCoordinate end = currentLeg.getEndCompoundMark().getAverageGPSCoordinate(); calc.setStartingGeographicPoint(start.getLongitude(), start.getLatitude()); calc.setDestinationGeographicPoint(end.getLongitude(), end.getLatitude()); diff --git a/mock/src/main/java/seng302/Model/CompoundMark.java b/mock/src/main/java/seng302/Model/CompoundMark.java new file mode 100644 index 00000000..d4524a20 --- /dev/null +++ b/mock/src/main/java/seng302/Model/CompoundMark.java @@ -0,0 +1,71 @@ +package seng302.Model; + +import org.geotools.referencing.GeodeticCalculator; +import java.awt.geom.Point2D; + +/** + * Created by esa46 on 29/03/17. + */ +public class CompoundMark extends Marker{ + + private GPSCoordinate averageGPSCoordinate; + private Mark mark1; + private Mark mark2 = null; + private String name; + + public CompoundMark(Mark mark1) { + super(mark1.getPosition()); + this.mark1 = mark1; + this.averageGPSCoordinate = calculateAverage(); + + } + + public CompoundMark(Mark mark1, Mark mark2) { + super(mark1.getPosition(), mark2.getPosition()); + this.mark1 = mark1; + this.mark2 = mark2; + this.averageGPSCoordinate = calculateAverage(); + + } + + public CompoundMark(String name, Mark mark1, Mark mark2) { + super(name, mark1.getPosition(), mark2.getPosition()); + this.name = name; + this.mark1 = mark1; + this.mark2 = mark2; + this.averageGPSCoordinate = calculateAverage(); + + } + + public GPSCoordinate getMark1() { + return mark1.getPosition(); + } + + public GPSCoordinate getMark2() { + return mark2.getPosition(); + } + + public GPSCoordinate getAverageGPSCoordinate() { + return averageGPSCoordinate; + } + + public String getName() { + return name; + } + + private GPSCoordinate calculateAverage() { + if(mark2 != null) { + GeodeticCalculator calc = new GeodeticCalculator(); + calc.setStartingGeographicPoint(mark1.getPosition().getLongitude(), mark1.getPosition().getLatitude()); + calc.setDestinationGeographicPoint(mark2.getPosition().getLongitude(), mark2.getPosition().getLatitude()); + double azimuth = calc.getAzimuth(); + double distance = calc.getOrthodromicDistance(); + + GeodeticCalculator middleCalc = new GeodeticCalculator(); + middleCalc.setStartingGeographicPoint(mark1.getPosition().getLongitude(), mark1.getPosition().getLatitude()); + middleCalc.setDirection(azimuth, distance / 2); + Point2D middlePoint = middleCalc.getDestinationGeographicPoint(); + return new GPSCoordinate(middlePoint.getY(), middlePoint.getX()); + } else return mark1.getPosition(); + } +} diff --git a/mock/src/main/java/seng302/Model/Event.java b/mock/src/main/java/seng302/Model/Event.java index f819ef9d..25a303d6 100644 --- a/mock/src/main/java/seng302/Model/Event.java +++ b/mock/src/main/java/seng302/Model/Event.java @@ -62,7 +62,7 @@ public class Event { mockOutput.parseXMLString(regattaData, 26); System.out.println("Sending Race"); - String raceData = readFile("mock/src/main/resources//mockXML/raceTest.xml", StandardCharsets.UTF_8); + String raceData = readFile("mock/src/main/resources/mockXML/raceTest.xml", StandardCharsets.UTF_8); mockOutput.setRaceXml(raceData); mockOutput.parseXMLString(raceData, 26); diff --git a/mock/src/main/java/seng302/Model/Leg.java b/mock/src/main/java/seng302/Model/Leg.java index b791627a..22c5adce 100644 --- a/mock/src/main/java/seng302/Model/Leg.java +++ b/mock/src/main/java/seng302/Model/Leg.java @@ -10,8 +10,8 @@ import seng302.Constants; public class Leg { private String name; //nautical miles private double distance; - private CompoundMarker startCompoundMarker; - private CompoundMarker endCompoundMarker; + private Marker startCompoundMark; + private Marker endCompoundMark; private int legNumber; /** @@ -22,10 +22,10 @@ public class Leg { * @param end marker * @param number Leg's position in race */ - public Leg(String name, CompoundMarker start, CompoundMarker end, int number) { + public Leg(String name, Marker start, Marker end, int number) { this.name = name; - this.startCompoundMarker = start; - this.endCompoundMarker = end; + this.startCompoundMark = start; + this.endCompoundMark = end; this.legNumber = number; calculateDistance(); } @@ -69,20 +69,20 @@ public class Leg { } - public CompoundMarker getStartCompoundMarker() { - return startCompoundMarker; + public Marker getStartCompoundMark() { + return startCompoundMark; } - public void setStartCompoundMarker(CompoundMarker startCompoundMarker) { - this.startCompoundMarker = startCompoundMarker; + public void setStartCompoundMark(Marker startCompoundMark) { + this.startCompoundMark = startCompoundMark; } - public CompoundMarker getEndCompoundMarker() { - return endCompoundMarker; + public Marker getEndCompoundMark() { + return endCompoundMark; } - public void setEndCompoundMarker(CompoundMarker endCompoundMarker) { - this.endCompoundMarker = endCompoundMarker; + public void setEndCompoundMark(Marker endCompoundMark) { + this.endCompoundMark = endCompoundMark; } /** @@ -92,8 +92,8 @@ public class Leg { GeodeticCalculator calc = new GeodeticCalculator(); //Load start and end of leg - GPSCoordinate startMarker = this.startCompoundMarker.getAverageGPSCoordinate(); - GPSCoordinate endMarker = this.endCompoundMarker.getAverageGPSCoordinate(); + GPSCoordinate startMarker = this.startCompoundMark.getAverageGPSCoordinate(); + GPSCoordinate endMarker = this.endCompoundMark.getAverageGPSCoordinate(); calc.setStartingGeographicPoint(startMarker.getLongitude(), startMarker.getLatitude()); calc.setDestinationGeographicPoint(endMarker.getLongitude(), endMarker.getLatitude()); this.distance = calc.getOrthodromicDistance() / Constants.NMToMetersConversion; diff --git a/mock/src/main/java/seng302/Model/Mark.java b/mock/src/main/java/seng302/Model/Mark.java index 36d7bdf2..8a09493d 100644 --- a/mock/src/main/java/seng302/Model/Mark.java +++ b/mock/src/main/java/seng302/Model/Mark.java @@ -4,13 +4,25 @@ package seng302.Model; * Created by cbt24 on 10/05/17. */ public class Mark { + private int sourceID; private String name; + private GPSCoordinate position; - public Mark(String name) { + public Mark(int sourceID, String name, GPSCoordinate position) { + this.sourceID = sourceID; this.name = name; + this.position = position; } public String getName() { return name; } + + public int getSourceID() { + return sourceID; + } + + public GPSCoordinate getPosition() { + return position; + } } diff --git a/mock/src/main/java/seng302/Model/CompoundMarker.java b/mock/src/main/java/seng302/Model/Marker.java similarity index 88% rename from mock/src/main/java/seng302/Model/CompoundMarker.java rename to mock/src/main/java/seng302/Model/Marker.java index cbe5fdf5..2887f9fc 100644 --- a/mock/src/main/java/seng302/Model/CompoundMarker.java +++ b/mock/src/main/java/seng302/Model/Marker.java @@ -6,7 +6,7 @@ import java.awt.geom.Point2D; /** * Created by esa46 on 29/03/17. */ -public class CompoundMarker { +public class Marker { private GPSCoordinate averageGPSCoordinate; private GPSCoordinate mark1; @@ -14,7 +14,7 @@ public class CompoundMarker { private String name; private boolean doubleMarker = false; - public CompoundMarker(GPSCoordinate mark1) { + public Marker(GPSCoordinate mark1) { this.mark1 = mark1; this.mark2 = mark1; @@ -22,7 +22,7 @@ public class CompoundMarker { } - public CompoundMarker(GPSCoordinate mark1, GPSCoordinate mark2) { + public Marker(GPSCoordinate mark1, GPSCoordinate mark2) { this.mark1 = mark1; this.mark2 = mark2; @@ -30,7 +30,7 @@ public class CompoundMarker { } - public CompoundMarker(String name, GPSCoordinate mark1, GPSCoordinate mark2) { + public Marker(String name, GPSCoordinate mark1, GPSCoordinate mark2) { this.name = name; this.mark1 = mark1; @@ -71,4 +71,4 @@ public class CompoundMarker { } -} +} \ No newline at end of file diff --git a/mock/src/main/java/seng302/Model/Race.java b/mock/src/main/java/seng302/Model/Race.java index c58eae49..05f0d7f7 100644 --- a/mock/src/main/java/seng302/Model/Race.java +++ b/mock/src/main/java/seng302/Model/Race.java @@ -216,19 +216,14 @@ public class Race implements Runnable { public void initialiseBoats() { Leg officialStart = legs.get(0); String name = officialStart.getName(); - CompoundMarker endCompoundMarker = officialStart.getEndCompoundMarker(); - ArrayList startCompoundMarkers = getSpreadStartingPositions(); + ArrayList startingPositions = getSpreadStartingPositions(); for (int i = 0; i < startingBoats.size(); i++) { Boat boat = startingBoats.get(i); if (boat != null) { boat.setScaledVelocity(boat.getVelocity() * scaleFactor); - Leg startLeg = new Leg(name, 0); - boat.setCurrentPosition(startCompoundMarkers.get(i).getAverageGPSCoordinate()); - startLeg.setStartCompoundMarker(startCompoundMarkers.get(i)); - startLeg.setEndCompoundMarker(endCompoundMarker); - startLeg.calculateDistance(); - boat.setCurrentLeg(startLeg); + boat.setCurrentPosition(startingPositions.get(i)); + boat.setCurrentLeg(officialStart); boat.setHeading(boat.calculateHeading()); } } @@ -239,27 +234,27 @@ public class Race implements Runnable { * * @return list of starting positions */ - public ArrayList getSpreadStartingPositions() { + public ArrayList getSpreadStartingPositions() { int nBoats = startingBoats.size(); - CompoundMarker compoundMarker = legs.get(0).getStartCompoundMarker(); + Marker compoundMark = legs.get(0).getStartCompoundMark(); GeodeticCalculator initialCalc = new GeodeticCalculator(); - initialCalc.setStartingGeographicPoint(compoundMarker.getMark1().getLongitude(), compoundMarker.getMark1().getLatitude()); - initialCalc.setDestinationGeographicPoint(compoundMarker.getMark2().getLongitude(), compoundMarker.getMark2().getLatitude()); + initialCalc.setStartingGeographicPoint(compoundMark.getMark1().getLongitude(), compoundMark.getMark1().getLatitude()); + initialCalc.setDestinationGeographicPoint(compoundMark.getMark2().getLongitude(), compoundMark.getMark2().getLatitude()); double azimuth = initialCalc.getAzimuth(); double distanceBetweenMarkers = initialCalc.getOrthodromicDistance(); double distanceBetweenBoats = distanceBetweenMarkers / (nBoats + 1); GeodeticCalculator positionCalc = new GeodeticCalculator(); - positionCalc.setStartingGeographicPoint(compoundMarker.getMark1().getLongitude(), compoundMarker.getMark1().getLatitude()); - ArrayList positions = new ArrayList<>(); + positionCalc.setStartingGeographicPoint(compoundMark.getMark1().getLongitude(), compoundMark.getMark1().getLatitude()); + ArrayList positions = new ArrayList<>(); for (int i = 0; i < nBoats; i++) { positionCalc.setDirection(azimuth, distanceBetweenBoats); Point2D position = positionCalc.getDestinationGeographicPoint(); - positions.add(new CompoundMarker(new GPSCoordinate(position.getY(), position.getX()))); + positions.add(new GPSCoordinate(position.getY(), position.getX())); positionCalc = new GeodeticCalculator(); positionCalc.setStartingGeographicPoint(position); @@ -302,7 +297,7 @@ public class Race implements Runnable { //update boat's distance travelled boat.setDistanceTravelledInLeg(totalDistanceTravelled); //Calculate boat's new position by adding the distance travelled onto the start point of the leg - boat.setCurrentPosition(calculatePosition(boat.getCurrentLeg().getStartCompoundMarker().getAverageGPSCoordinate(), + boat.setCurrentPosition(calculatePosition(boat.getCurrentLeg().getStartCompoundMark().getAverageGPSCoordinate(), totalDistanceTravelled, boat.calculateAzimuth())); } } diff --git a/mock/src/main/java/seng302/Model/StreamedCourseXMLException.java b/mock/src/main/java/seng302/Model/StreamedCourseXMLException.java new file mode 100644 index 00000000..453bacfd --- /dev/null +++ b/mock/src/main/java/seng302/Model/StreamedCourseXMLException.java @@ -0,0 +1,7 @@ +package seng302.Model; + +/** + * Created by cbt24 on 25/04/17. + */ +public class StreamedCourseXMLException extends Throwable { +} diff --git a/mock/src/main/java/seng302/Model/StreamedCourseXMLReader.java b/mock/src/main/java/seng302/Model/StreamedCourseXMLReader.java new file mode 100644 index 00000000..9a089e41 --- /dev/null +++ b/mock/src/main/java/seng302/Model/StreamedCourseXMLReader.java @@ -0,0 +1,274 @@ +package seng302.Model; + +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; +import seng302.DataInput.BoatDataSource; +import seng302.DataInput.RaceDataSource; +import seng302.DataInput.XMLReader; + +import javax.xml.parsers.ParserConfigurationException; +import java.io.IOException; +import java.text.ParseException; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; +import java.util.*; + +/** + * Created by jjg64 on 21/04/17. + */ +public class StreamedCourseXMLReader extends XMLReader implements RaceDataSource { + private static final double COORDINATEPADDING = 0.000; + private GPSCoordinate mapTopLeft, mapBottomRight; + private final List boundary = new ArrayList<>(); + private final Map compoundMarkMap = new HashMap<>(); + private final Map participants = new HashMap<>(); + private final List legs = new ArrayList<>(); + private final List compoundMarks = new ArrayList<>(); + private ZonedDateTime creationTimeDate; + private ZonedDateTime raceStartTime; + private int raceID; + private String raceType; + private boolean postpone; + + private Map boats; + private Map marks; + + /** + * Constructor for Streamed Race XML + * @param filePath path of the file + * @throws IOException error + * @throws SAXException error + * @throws ParserConfigurationException error + * @throws ParseException error + * @throws StreamedCourseXMLException error + */ + public StreamedCourseXMLReader(String filePath, BoatDataSource boatData) throws IOException, SAXException, ParserConfigurationException, ParseException, StreamedCourseXMLException { + this(filePath, boatData, true); + } + + /** + * Constructor for Streamed Race XML + * @param filePath file path to read + * @param read whether or not to read and store the files straight away. + * @throws IOException error + * @throws SAXException error + * @throws ParserConfigurationException error + * @throws ParseException error + * @throws StreamedCourseXMLException error + */ + public StreamedCourseXMLReader(String filePath, BoatDataSource boatData, boolean read) throws IOException, SAXException, ParserConfigurationException, ParseException, StreamedCourseXMLException { + super(filePath); + this.boats = boatData.getBoats(); + this.marks = boatData.getMarkerBoats(); + if (read) { + read(); + } + } + + /** + * reads + * @throws StreamedCourseXMLException error + */ + private void read() throws StreamedCourseXMLException { + readRace(); + readParticipants(); + readCourse(); + } + + /** + * reads a race + */ + private void readRace() { + DateTimeFormatter dateFormat = DateTimeFormatter.ISO_OFFSET_DATE_TIME; + Element settings = (Element) doc.getElementsByTagName("Race").item(0); + NamedNodeMap raceTimeTag = doc.getElementsByTagName("RaceStartTime").item(0).getAttributes(); + + if (raceTimeTag.getNamedItem("Time") != null) dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssZ"); + + + raceID = Integer.parseInt(getTextValueOfNode(settings, "RaceID")); + raceType = getTextValueOfNode(settings, "RaceType"); + + creationTimeDate = ZonedDateTime.parse(getTextValueOfNode(settings, "CreationTimeDate"), dateFormat); + + if (raceTimeTag.getNamedItem("Time") != null) raceStartTime = ZonedDateTime.parse(raceTimeTag.getNamedItem("Time").getTextContent(), dateFormat); + else raceStartTime = ZonedDateTime.parse(raceTimeTag.getNamedItem("Start").getTextContent(), dateFormat); + + postpone = Boolean.parseBoolean(raceTimeTag.getNamedItem("Postpone").getTextContent()); + } + + private void readParticipants() { + Element nParticipants = (Element) doc.getElementsByTagName("Participants").item(0); + nParticipants.getChildNodes().getLength(); + for (int i = 0; i < nParticipants.getChildNodes().getLength(); i++) { + int sourceID; + Node yacht = nParticipants.getChildNodes().item(i); + if (yacht.getNodeName().equals("Yacht")) { + if (exists(yacht, "SourceID")) { + sourceID = Integer.parseInt(yacht.getAttributes().getNamedItem("SourceID").getTextContent()); + participants.put(sourceID, boats.get(sourceID)); + } + } + } + } + + /** + * reads a course + * @throws StreamedCourseXMLException error + */ + private void readCourse() throws StreamedCourseXMLException { + readCompoundMarks(); + readCompoundMarkSequence(); + readCourseLimit(); + } + + /** + * Indexes CompoundMark elements by their ID for use in generating the course, and populates list of Markers. + * @see CompoundMark + */ + private void readCompoundMarks() throws StreamedCourseXMLException { + Element nCourse = (Element) doc.getElementsByTagName("Course").item(0); + for(int i = 0; i < nCourse.getChildNodes().getLength(); i++) { + Node compoundMark = nCourse.getChildNodes().item(i); + if(compoundMark.getNodeName().equals("CompoundMark")) { + int compoundMarkID = getCompoundMarkID((Element) compoundMark); + compoundMarkMap.put(compoundMarkID, (Element)compoundMark); + compoundMarks.add(getCompoundMark(compoundMarkID)); + } + } + } + + /** + * Generates a CompoundMark from the CompoundMark element with given ID. + * @param compoundMarkID index of required CompoundMark element + * @return generated CompoundMark + * @throws StreamedCourseXMLException if CompoundMark element contains unhandled number of compoundMarks + * @see CompoundMark + */ + private CompoundMark getCompoundMark(int compoundMarkID) throws StreamedCourseXMLException { + Element compoundMark = compoundMarkMap.get(compoundMarkID); + NodeList nMarks = compoundMark.getElementsByTagName("Mark"); + CompoundMark marker; + + switch(nMarks.getLength()) { + case 1: marker = new CompoundMark(getMark((Element)nMarks.item(0))); break; + case 2: marker = new CompoundMark(getMark((Element)nMarks.item(0)), getMark((Element)nMarks.item(1))); break; + default: throw new StreamedCourseXMLException(); + } + + return marker; + } + + private Mark getMark(Element mark) { + int sourceID = Integer.parseInt(mark.getAttribute("SourceID")); + System.out.println(marks.get(sourceID).getPosition()); + return marks.get(sourceID); + } + + /** + * Reads "compoundMarkID" attribute of CompoundMark or Corner element + * @param element with "compoundMarkID" attribute + * @return value of "compoundMarkID" attribute + */ + private int getCompoundMarkID(Element element) { + return Integer.parseInt(element.getAttribute("CompoundMarkID")); + } + + /** + * Reads "name" attribute of CompoundMark element with corresponding CompoundMarkID + * @param compoundMarkID unique ID for CompoundMark element + * @return value of "name" attribute + */ + private String getCompoundMarkName(int compoundMarkID) { + return compoundMarkMap.get(compoundMarkID).getAttribute("Name"); + } + + /** + * Populates list of legs given CompoundMarkSequence element and referenced CompoundMark elements. + * @throws StreamedCourseXMLException if compoundMarks cannot be resolved from CompoundMark + */ + private void readCompoundMarkSequence() throws StreamedCourseXMLException { + Element nCompoundMarkSequence = (Element) doc.getElementsByTagName("CompoundMarkSequence").item(0); + NodeList nCorners = nCompoundMarkSequence.getElementsByTagName("Corner"); + Element markXML = (Element)nCorners.item(0); + CompoundMark lastCompoundMark = getCompoundMark(getCompoundMarkID(markXML)); + String legName = getCompoundMarkName(getCompoundMarkID(markXML)); + for(int i = 1; i < nCorners.getLength(); i++) { + markXML = (Element)nCorners.item(i); + CompoundMark currentCompoundMark = getCompoundMark(getCompoundMarkID(markXML)); + legs.add(new Leg(legName, lastCompoundMark, currentCompoundMark, i-1)); + lastCompoundMark = currentCompoundMark; + legName = getCompoundMarkName(getCompoundMarkID(markXML)); + } + } + + private void readCourseLimit() { + Element nCourseLimit = (Element) doc.getElementsByTagName("CourseLimit").item(0); + for(int i = 0; i < nCourseLimit.getChildNodes().getLength(); i++) { + Node limit = nCourseLimit.getChildNodes().item(i); + if (limit.getNodeName().equals("Limit")) { + double lat = Double.parseDouble(limit.getAttributes().getNamedItem("Lat").getTextContent()); + double lon = Double.parseDouble(limit.getAttributes().getNamedItem("Lon").getTextContent()); + boundary.add(new GPSCoordinate(lat, lon)); + } + } + + + double maxLatitude = boundary.stream().max(Comparator.comparingDouble(GPSCoordinate::getLatitude)).get().getLatitude() + COORDINATEPADDING; + double maxLongitude = boundary.stream().max(Comparator.comparingDouble(GPSCoordinate::getLongitude)).get().getLongitude() + COORDINATEPADDING; + double minLatitude = boundary.stream().min(Comparator.comparingDouble(GPSCoordinate::getLatitude)).get().getLatitude() + COORDINATEPADDING; + double minLongitude = boundary.stream().min(Comparator.comparingDouble(GPSCoordinate::getLongitude)).get().getLongitude() + COORDINATEPADDING; + + mapTopLeft = new GPSCoordinate(minLatitude, minLongitude); + mapBottomRight = new GPSCoordinate(maxLatitude, maxLongitude); + } + + public List getBoundary() { + return boundary; + } + + public GPSCoordinate getMapTopLeft() { + return mapTopLeft; + } + + public GPSCoordinate getMapBottomRight() { + return mapBottomRight; + } + + public List getLegs() { + return legs; + } + + public List getCompoundMarks() { return compoundMarks; } + + public Double getPadding() { + return COORDINATEPADDING; + } + + public ZonedDateTime getCreationTimeDate() { + return creationTimeDate; + } + + public ZonedDateTime getZonedDateTime() { + return raceStartTime; + } + + public int getRaceId() { + return raceID; + } + + public String getRaceType() { + return raceType; + } + + public boolean isPostpone() { + return postpone; + } + + public List getBoats() { + return new ArrayList<>(participants.values()); + } +} diff --git a/mock/src/main/resources/mockXML/raceTest.xml b/mock/src/main/resources/mockXML/raceTest.xml index 2cdb66e9..40a509a2 100644 --- a/mock/src/main/resources/mockXML/raceTest.xml +++ b/mock/src/main/resources/mockXML/raceTest.xml @@ -29,7 +29,7 @@ - + diff --git a/mock/src/test/java/seng302/DataInput/BoatXMLReaderTest.java b/mock/src/test/java/seng302/DataInput/BoatXMLReaderTest.java index 53689e38..5bf8b7b2 100644 --- a/mock/src/test/java/seng302/DataInput/BoatXMLReaderTest.java +++ b/mock/src/test/java/seng302/DataInput/BoatXMLReaderTest.java @@ -8,6 +8,7 @@ import seng302.Model.Mark; import javax.xml.parsers.ParserConfigurationException; import java.io.IOException; +import java.util.ArrayList; import java.util.List; import static org.testng.Assert.*; @@ -24,8 +25,8 @@ public class BoatXMLReaderTest { public void setUp() { try { boatData = new BoatXMLReader("mockXML/boatTest.xml"); - boats = boatData.getBoats(); - marks = boatData.getMarkerBoats(); + boats = new ArrayList<>(boatData.getBoats().values()); + marks = new ArrayList<>(boatData.getMarkerBoats().values()); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { diff --git a/mock/src/test/java/seng302/Model/BoatTest.java b/mock/src/test/java/seng302/Model/BoatTest.java index 2d112aad..8bdcb069 100644 --- a/mock/src/test/java/seng302/Model/BoatTest.java +++ b/mock/src/test/java/seng302/Model/BoatTest.java @@ -18,18 +18,18 @@ public class BoatTest { @Test public void calculateDueNorthAzimuthReturns0() { - CompoundMarker startCompoundMarker = new CompoundMarker(ORIGIN_COORDS); - CompoundMarker endCompoundMarker = new CompoundMarker(new GPSCoordinate(50, 0)); - Leg start = new Leg("Start", startCompoundMarker, endCompoundMarker, 0); + Marker startMarker = new Marker(ORIGIN_COORDS); + Marker endMarker = new Marker(new GPSCoordinate(50, 0)); + Leg start = new Leg("Start", startMarker, endMarker, 0); TEST_BOAT.setCurrentLeg(start); assertEquals(TEST_BOAT.calculateAzimuth(), 0, 1e-8); } @Test public void calculateDueSouthAzimuthReturns180() { - CompoundMarker startCompoundMarker = new CompoundMarker(ORIGIN_COORDS); - CompoundMarker endCompoundMarker = new CompoundMarker(new GPSCoordinate(-50, 0)); - Leg start = new Leg("Start", startCompoundMarker, endCompoundMarker, 0); + Marker startMarker = new Marker(ORIGIN_COORDS); + Marker endMarker = new Marker(new GPSCoordinate(-50, 0)); + Leg start = new Leg("Start", startMarker, endMarker, 0); TEST_BOAT.setCurrentLeg(start); assertEquals(TEST_BOAT.calculateAzimuth(), 180, 1e-8); } @@ -38,9 +38,9 @@ public class BoatTest { @Test public void calculateDueEastAzimuthReturns90() { - CompoundMarker startCompoundMarker = new CompoundMarker(ORIGIN_COORDS); - CompoundMarker endCompoundMarker = new CompoundMarker(new GPSCoordinate(0, 50)); - Leg start = new Leg("Start", startCompoundMarker, endCompoundMarker, 0); + Marker startMarker = new Marker(ORIGIN_COORDS); + Marker endMarker = new Marker(new GPSCoordinate(0, 50)); + Leg start = new Leg("Start", startMarker, endMarker, 0); TEST_BOAT.setCurrentLeg(start); assertEquals(TEST_BOAT.calculateAzimuth(), 90, 1e-8); } @@ -48,9 +48,9 @@ public class BoatTest { @Test public void calculateDueWestAzimuthReturnsNegative90() { - CompoundMarker startCompoundMarker = new CompoundMarker(ORIGIN_COORDS); - CompoundMarker endCompoundMarker = new CompoundMarker(new GPSCoordinate(0, -50)); - Leg start = new Leg("Start", startCompoundMarker, endCompoundMarker, 0); + Marker startMarker = new Marker(ORIGIN_COORDS); + Marker endMarker = new Marker(new GPSCoordinate(0, -50)); + Leg start = new Leg("Start", startMarker, endMarker, 0); TEST_BOAT.setCurrentLeg(start); assertEquals(TEST_BOAT.calculateAzimuth(), -90, 1e-8); @@ -59,9 +59,9 @@ public class BoatTest { @Test public void calculateDueNorthHeadingReturns0() { - CompoundMarker startCompoundMarker = new CompoundMarker(ORIGIN_COORDS); - CompoundMarker endCompoundMarker = new CompoundMarker(new GPSCoordinate(50, 0)); - Leg start = new Leg("Start", startCompoundMarker, endCompoundMarker, 0); + Marker startMarker = new Marker(ORIGIN_COORDS); + Marker endMarker = new Marker(new GPSCoordinate(50, 0)); + Leg start = new Leg("Start", startMarker, endMarker, 0); TEST_BOAT.setCurrentLeg(start); assertEquals(TEST_BOAT.calculateHeading(), 0, 1e-8); } @@ -69,27 +69,27 @@ public class BoatTest { @Test public void calculateDueEastHeadingReturns90() { - CompoundMarker startCompoundMarker = new CompoundMarker(ORIGIN_COORDS); - CompoundMarker endCompoundMarker = new CompoundMarker(new GPSCoordinate(0, 50)); - Leg start = new Leg("Start", startCompoundMarker, endCompoundMarker, 0); + Marker startMarker = new Marker(ORIGIN_COORDS); + Marker endMarker = new Marker(new GPSCoordinate(0, 50)); + Leg start = new Leg("Start", startMarker, endMarker, 0); TEST_BOAT.setCurrentLeg(start); assertEquals(TEST_BOAT.calculateHeading(), 90, 1e-8); } @Test public void calculateDueSouthHeadingReturns180() { - CompoundMarker startCompoundMarker = new CompoundMarker(ORIGIN_COORDS); - CompoundMarker endCompoundMarker = new CompoundMarker(new GPSCoordinate(-50, 0)); - Leg start = new Leg("Start", startCompoundMarker, endCompoundMarker, 0); + Marker startMarker = new Marker(ORIGIN_COORDS); + Marker endMarker = new Marker(new GPSCoordinate(-50, 0)); + Leg start = new Leg("Start", startMarker, endMarker, 0); TEST_BOAT.setCurrentLeg(start); assertEquals(TEST_BOAT.calculateHeading(), 180, 1e-8); } @Test public void calculateDueWestHeadingReturns270() { - CompoundMarker startCompoundMarker = new CompoundMarker(ORIGIN_COORDS); - CompoundMarker endCompoundMarker = new CompoundMarker(new GPSCoordinate(0, -50)); - Leg start = new Leg("Start", startCompoundMarker, endCompoundMarker, 0); + Marker startMarker = new Marker(ORIGIN_COORDS); + Marker endMarker = new Marker(new GPSCoordinate(0, -50)); + Leg start = new Leg("Start", startMarker, endMarker, 0); TEST_BOAT.setCurrentLeg(start); assertEquals(TEST_BOAT.calculateHeading(), 270, 1e-8); } diff --git a/mock/src/test/java/seng302/Model/CompoundMarkerTest.java b/mock/src/test/java/seng302/Model/CompoundMarkTest.java similarity index 76% rename from mock/src/test/java/seng302/Model/CompoundMarkerTest.java rename to mock/src/test/java/seng302/Model/CompoundMarkTest.java index ef46de2c..29b542b5 100644 --- a/mock/src/test/java/seng302/Model/CompoundMarkerTest.java +++ b/mock/src/test/java/seng302/Model/CompoundMarkTest.java @@ -8,14 +8,14 @@ import static org.junit.Assert.assertTrue; /** * Created by esa46 on 29/03/17. */ -public class CompoundMarkerTest { +public class CompoundMarkTest { GPSCoordinate ORIGIN_COORD = new GPSCoordinate(0, 0); @Test public void averageOfSingleMarkAtOriginIsSingleMark() { - CompoundMarker testMark = new CompoundMarker(ORIGIN_COORD); + Marker testMark = new Marker(ORIGIN_COORD); assertTrue(testMark.getAverageGPSCoordinate().equals(ORIGIN_COORD)); } @@ -24,7 +24,7 @@ public class CompoundMarkerTest { public void averageOfSingleMarkIsSingleMark() { GPSCoordinate testCoord = new GPSCoordinate(20, 25); - CompoundMarker testMark = new CompoundMarker(testCoord); + Marker testMark = new Marker(testCoord); assertTrue(testMark.getAverageGPSCoordinate().equals(testCoord)); } @@ -34,7 +34,7 @@ public class CompoundMarkerTest { public void averageLatOfTwoMarksIsAccurate() { GPSCoordinate testCoord = new GPSCoordinate(10, 0); - CompoundMarker testMark = new CompoundMarker(ORIGIN_COORD, testCoord); + Marker testMark = new Marker(ORIGIN_COORD, testCoord); assertTrue(testMark.getAverageGPSCoordinate().equals(new GPSCoordinate(5, 0))); } @@ -42,7 +42,7 @@ public class CompoundMarkerTest { public void averageLongOfTwoMarksIsAccurate() { GPSCoordinate testCoord = new GPSCoordinate(0, 10); - CompoundMarker testMark = new CompoundMarker(ORIGIN_COORD, testCoord); + Marker testMark = new Marker(ORIGIN_COORD, testCoord); assertTrue(testMark.getAverageGPSCoordinate().equals(new GPSCoordinate(0, 5))); } @@ -52,7 +52,7 @@ public class CompoundMarkerTest { GPSCoordinate testCoord1 = new GPSCoordinate(10, 30); GPSCoordinate testCoord2 = new GPSCoordinate(30, 60); - CompoundMarker testMark = new CompoundMarker(testCoord1, testCoord2); + Marker testMark = new Marker(testCoord1, testCoord2); assertTrue(testMark.getAverageGPSCoordinate().equals(new GPSCoordinate(020.644102, 44.014817))); } diff --git a/mock/src/test/java/seng302/Model/LegTest.java b/mock/src/test/java/seng302/Model/LegTest.java index feccb9d3..cae7b203 100644 --- a/mock/src/test/java/seng302/Model/LegTest.java +++ b/mock/src/test/java/seng302/Model/LegTest.java @@ -14,7 +14,7 @@ import static junit.framework.TestCase.assertEquals; */ public class LegTest { - private CompoundMarker ORIGIN_Compound_MARKER = new CompoundMarker(new GPSCoordinate(0, 0)); + private Marker ORIGIN_Compound_MARKER = new Marker(new GPSCoordinate(0, 0)); @Test public void calculateDistanceHandles5nmNorth() { @@ -22,8 +22,8 @@ public class LegTest { calc.setStartingGeographicPoint(0, 0); calc.setDirection(0, 5 * Constants.NMToMetersConversion); - CompoundMarker endCompoundMarker = getEndMarker(calc.getDestinationGeographicPoint()); - Leg test = new Leg("Test", ORIGIN_Compound_MARKER, endCompoundMarker, 0); + Marker endMarker = getEndMarker(calc.getDestinationGeographicPoint()); + Leg test = new Leg("Test", ORIGIN_Compound_MARKER, endMarker, 0); assertEquals(test.getDistance(), 5, 1e-8); } @@ -33,8 +33,8 @@ public class LegTest { calc.setStartingGeographicPoint(0, 0); calc.setDirection(90, 12 * Constants.NMToMetersConversion); - CompoundMarker endCompoundMarker = getEndMarker(calc.getDestinationGeographicPoint()); - Leg test = new Leg("Test", ORIGIN_Compound_MARKER, endCompoundMarker, 0); + Marker endMarker = getEndMarker(calc.getDestinationGeographicPoint()); + Leg test = new Leg("Test", ORIGIN_Compound_MARKER, endMarker, 0); assertEquals(test.getDistance(), 12, 1e-8); } @@ -44,8 +44,8 @@ public class LegTest { calc.setStartingGeographicPoint(0, 0); calc.setDirection(180, 0.5 * Constants.NMToMetersConversion); - CompoundMarker endCompoundMarker = getEndMarker(calc.getDestinationGeographicPoint()); - Leg test = new Leg("Test", ORIGIN_Compound_MARKER, endCompoundMarker, 0); + Marker endMarker = getEndMarker(calc.getDestinationGeographicPoint()); + Leg test = new Leg("Test", ORIGIN_Compound_MARKER, endMarker, 0); assertEquals(test.getDistance(), 0.5, 1e-8); } @@ -55,8 +55,8 @@ public class LegTest { calc.setStartingGeographicPoint(0, 0); calc.setDirection(-90, 0.1 * Constants.NMToMetersConversion); - CompoundMarker endCompoundMarker = getEndMarker(calc.getDestinationGeographicPoint()); - Leg test = new Leg("Test", ORIGIN_Compound_MARKER, endCompoundMarker, 0); + Marker endMarker = getEndMarker(calc.getDestinationGeographicPoint()); + Leg test = new Leg("Test", ORIGIN_Compound_MARKER, endMarker, 0); assertEquals(test.getDistance(), 0.1, 1e-8); } @@ -67,11 +67,11 @@ public class LegTest { assertEquals(test.getDistance(), 0, 1e-8); } - private CompoundMarker getEndMarker(Point2D point) { + private Marker getEndMarker(Point2D point) { GPSCoordinate coords = new GPSCoordinate(point.getY(), point.getX()); - return new CompoundMarker(coords); + return new Marker(coords); } } diff --git a/mock/src/test/java/seng302/Model/RaceTest.java b/mock/src/test/java/seng302/Model/RaceTest.java index ccf41621..bbac7680 100644 --- a/mock/src/test/java/seng302/Model/RaceTest.java +++ b/mock/src/test/java/seng302/Model/RaceTest.java @@ -28,8 +28,8 @@ //public class RaceTest{ // // private static MockOutput mockOutput; -// SharedModel.Leg START_LEG = new SharedModel.Leg("Start", new SharedModel.CompoundMarker(new SharedModel.GPSCoordinate(0, 0)), new SharedModel.CompoundMarker(new SharedModel.GPSCoordinate(1, 1)), 0); -// SharedModel.Leg FINISH_LEG = new SharedModel.Leg("Finish", new SharedModel.CompoundMarker(new SharedModel.GPSCoordinate(1, 1)), new SharedModel.CompoundMarker(new SharedModel.GPSCoordinate(2, 2)), 0); +// SharedModel.Leg START_LEG = new SharedModel.Leg("Start", new SharedModel.Marker(new SharedModel.GPSCoordinate(0, 0)), new SharedModel.Marker(new SharedModel.GPSCoordinate(1, 1)), 0); +// SharedModel.Leg FINISH_LEG = new SharedModel.Leg("Finish", new SharedModel.Marker(new SharedModel.GPSCoordinate(1, 1)), new SharedModel.Marker(new SharedModel.GPSCoordinate(2, 2)), 0); // //// @Override //// public void start(Stage primaryStage) throws Exception{} diff --git a/visualiser/src/main/java/seng302/Mock/BoatXMLReader.java b/visualiser/src/main/java/seng302/Mock/BoatXMLReader.java index 8992c019..45050bda 100644 --- a/visualiser/src/main/java/seng302/Mock/BoatXMLReader.java +++ b/visualiser/src/main/java/seng302/Mock/BoatXMLReader.java @@ -88,7 +88,7 @@ public class BoatXMLReader extends XMLReader { Element nBoats = (Element) doc.getElementsByTagName("Boats").item(0); for (int i = 0; i < nBoats.getChildNodes().getLength(); i++) { Node boat = nBoats.getChildNodes().item(i); - if (boat.getNodeName().equals("Boat")) { + if (boat.getNodeName().equals("Boat") && boat.getAttributes().getNamedItem("Type").getTextContent().equals("Yacht")) { readSingleBoat(boat); } }