From 795b411f08cad1bf5ef7cebaf16682f68af8d441 Mon Sep 17 00:00:00 2001 From: Fan-Wu Yang Date: Fri, 31 Mar 2017 00:51:08 +1300 Subject: [PATCH] Added some doc strings - Added doc strings to RaceXML - Added a few minor changes to bermuda_AC35.xml - Changes to the RaceXMLReader Unit Test --- src/main/java/seng302/RaceXMLReader.java | 69 ++++- src/main/resources/raceXML/bermuda_AC35.xml | 8 +- src/test/java/seng302/Model/RaceXMLTest.java | 39 +++ src/test/resources/raceXML/bermuda_AC35.xml | 268 +++++++++++++++++++ 4 files changed, 379 insertions(+), 5 deletions(-) create mode 100644 src/test/resources/raceXML/bermuda_AC35.xml diff --git a/src/main/java/seng302/RaceXMLReader.java b/src/main/java/seng302/RaceXMLReader.java index 82e4471b..5faa68c7 100644 --- a/src/main/java/seng302/RaceXMLReader.java +++ b/src/main/java/seng302/RaceXMLReader.java @@ -24,11 +24,25 @@ public class RaceXMLReader extends XMLReader { private ArrayList boundary = new ArrayList<>(); private static double COORDINATEPADDING = 0.0005; - + /** + * Constractor for Race XML + * @param filePath path of the file + * @throws IOException + * @throws SAXException + * @throws ParserConfigurationException + */ public RaceXMLReader(String filePath) throws IOException, SAXException, ParserConfigurationException { this(filePath, true); } + /** + * COnstructor for Race XML + * @param filePath file path to read + * @param read whether or not to read and store the files straight away. + * @throws IOException + * @throws SAXException + * @throws ParserConfigurationException + */ public RaceXMLReader(String filePath, boolean read) throws IOException, SAXException, ParserConfigurationException { super(filePath); if (read) { @@ -36,12 +50,18 @@ public class RaceXMLReader extends XMLReader { } } + /** + * Read the files + */ private void read() { readCourse(); readLegs(); readBoats(); } + /** + * Read all the boats in the XML file + */ public void readBoats() { //get all boats NodeList nBoats = doc.getElementsByTagName("boat"); @@ -59,6 +79,9 @@ public class RaceXMLReader extends XMLReader { } } + /** + * Read all the legs in the XML file + */ public void readLegs() { //get all legs NodeList nLegs = doc.getElementsByTagName("leg"); @@ -73,6 +96,9 @@ public class RaceXMLReader extends XMLReader { } } + /** + * Read courses in XML file + */ public void readCourse() { NodeList nCourse = doc.getElementsByTagName("course"); @@ -140,20 +166,43 @@ public class RaceXMLReader extends XMLReader { finishPt2 = getCoordinates(nMarks, 4, 1); } + /** + * gets a marker from the XML file + * @param start base nodelist this should be the tag that contains + * @return + */ private Marker getMarker(NodeList start) { return getMarker(start, 0); } + /** + * gets a marker from the XML file + * @param start base nodelist this should be the tag that contains + * @param startIndex index in the node that has the coordinate tag + * @return + */ private Marker getMarker(NodeList start, int startIndex) { return getMarker(start, startIndex, 0); } + /** + * gets a marker from the XML file + * @param start base nodelist this should be the tag that contains + * @param startIndex index in the node that has the coordinate tag + * @param nodeIndex coordinate index + * @return + */ private Marker getMarker(NodeList start, int startIndex, int nodeIndex) { NodeList nodeList = ((Element) start.item(startIndex)).getElementsByTagName("marker"); Element marker = (Element) nodeList.item(nodeIndex); return getMarker(marker); } + /** + * gets a changes a marker to GPS coordinates into a marker + * @param markerNode marker to turn into coordinates + * @return + */ private Marker getMarker(Element markerNode) { NodeList nCoordinates = markerNode.getElementsByTagName("coordinate"); @@ -169,14 +218,32 @@ public class RaceXMLReader extends XMLReader { } + /** + * gets a coordinates from the XML file + * @param start base nodelist this should be the tag that contains + * @return + */ private GPSCoordinate getCoordinates(NodeList start) { return getCoordinates(start, 0); } + /** + * gets a coordinates from the XML file + * @param start base nodelist this should be the tag that contains + * @param startIndex the index the tag containing the coordinate should be in + * @return + */ private GPSCoordinate getCoordinates(NodeList start, int startIndex) { return getCoordinates(start, startIndex, 0); } + /** + * gets a coordinates from the XML file + * @param start base nodelist this should be the tag that contains + * @param startIndex the index the tag containing the coordinate should be in + * @param nodeIndex The coordinate index + * @return + */ private GPSCoordinate getCoordinates(NodeList start, int startIndex, int nodeIndex) { NodeList nodeList = ((Element) start.item(startIndex)).getElementsByTagName("coordinate"); Element coord = (Element) nodeList.item(nodeIndex); diff --git a/src/main/resources/raceXML/bermuda_AC35.xml b/src/main/resources/raceXML/bermuda_AC35.xml index 9117a83a..716f274b 100644 --- a/src/main/resources/raceXML/bermuda_AC35.xml +++ b/src/main/resources/raceXML/bermuda_AC35.xml @@ -173,16 +173,16 @@ -64.837168 - 32.317403 - -64.838627 + 32.317379 + -64.839291 32.317911 -64.836996 - 32.317548 - -64.835022 + 32.317257 + -64.836260 32.304273 diff --git a/src/test/java/seng302/Model/RaceXMLTest.java b/src/test/java/seng302/Model/RaceXMLTest.java index 21b7f8cf..ea43e6dd 100644 --- a/src/test/java/seng302/Model/RaceXMLTest.java +++ b/src/test/java/seng302/Model/RaceXMLTest.java @@ -10,6 +10,7 @@ import seng302.RaceXMLReader; import javax.xml.parsers.ParserConfigurationException; import java.io.IOException; +import java.util.ArrayList; public class RaceXMLTest { RaceXMLReader raceXMLReader; @@ -28,6 +29,31 @@ public class RaceXMLTest { try { RaceXMLReader raceXMLReader = new RaceXMLReader("raceXML/bermuda_AC35.xml", false); raceXMLReader.readBoats(); + ArrayList boats = raceXMLReader.getBoats(); + assertTrue(boats.size() == 6); + //test boat 1 + assertEquals(boats.get(0).getName().getValue(), "ORACLE TEAM USA"); + assertTrue(boats.get(0).getVelocity() == 20); + //test boat 2 + assertEquals(boats.get(1).getName().getValue(), "Land Rover BAR"); + assertTrue(boats.get(1).getVelocity() == 30); + assertEquals(boats.get(1).getAbbrev(), "GBR"); + //test boat 3 + assertEquals(boats.get(2).getName().getValue(), "SoftBank Team Japan"); + assertTrue(boats.get(2).getVelocity() == 25); + assertEquals(boats.get(2).getAbbrev(), "JPN"); + //test boat 4 + assertEquals(boats.get(3).getName().getValue(), "Groupama Team France"); + assertTrue(boats.get(3).getVelocity() == 20); + assertEquals(boats.get(3).getAbbrev(), "FRA"); + //test boat 5 + assertEquals(boats.get(4).getName().getValue(), "Artemis Racing"); + assertTrue(boats.get(4).getVelocity() == 29); + assertEquals(boats.get(4).getAbbrev(), "SWE"); + //test boat 6 + assertEquals(boats.get(5).getName().getValue(), "Emirates Team New Zealand"); + assertTrue(boats.get(5).getVelocity() == 62); + assertEquals(boats.get(5).getAbbrev(), "NZL"); } catch (Exception e) { fail("Boat Unreadable"); } @@ -38,6 +64,7 @@ public class RaceXMLTest { try { RaceXMLReader raceXMLReader = new RaceXMLReader("raceXML/bermuda_AC35.xml", false); raceXMLReader.readLegs(); + assertTrue(raceXMLReader.getLegs().size() == 5); } catch (Exception e) { fail("Legs Unreadable"); } @@ -48,6 +75,18 @@ public class RaceXMLTest { try { RaceXMLReader raceXMLReader = new RaceXMLReader("raceXML/bermuda_AC35.xml", false); raceXMLReader.readCourse(); + assertTrue(raceXMLReader.getMapTopLeft() != null); + assertTrue(raceXMLReader.getMapBottomRight() != null); + assertTrue(raceXMLReader.getFinishPt1() != null); + assertTrue(raceXMLReader.getFinishPt2() != null); + assertTrue(raceXMLReader.getStartPt1() != null); + assertTrue(raceXMLReader.getStartPt2() != null); + assertTrue(raceXMLReader.getLeewardPt1() != null); + assertTrue(raceXMLReader.getLeewardPt2() != null); + assertTrue(raceXMLReader.getWindwardPt1() != null); + assertTrue(raceXMLReader.getWindwardPt2() != null); + assertTrue(raceXMLReader.getMark() != null); + assertTrue(raceXMLReader.getBoundary().size() == 11); } catch (Exception e) { e.printStackTrace(); fail("Course Unreadable"); diff --git a/src/test/resources/raceXML/bermuda_AC35.xml b/src/test/resources/raceXML/bermuda_AC35.xml new file mode 100644 index 00000000..716f274b --- /dev/null +++ b/src/test/resources/raceXML/bermuda_AC35.xml @@ -0,0 +1,268 @@ + + + + ORACLE TEAM USA + 20 + USA + BLUEVIOLET + + + Land Rover BAR + 30 + GBR + BLACK + + + SoftBank Team Japan + 25 + JPN + RED + + + Groupama Team France + 20 + FRA + ORANGE + + + Artemis Racing + 29 + SWE + DARKOLIVEGREEN + + + Emirates Team New Zealand + 62 + NZL + LIMEGREEN + + + + + Start to Mark 1 + + + + 32.296577 + -64.854304 + + + 32.293771 + -64.855242 + + + + + + + 32.293039 + -64.843983 + + + + + + Mark 1 to Leeward Gate + + + + 32.293039 + -64.843983 + + + + + + + 32.309693 + -64.835249 + + + 32.308046 + -64.831785 + + + + + + Leeward Gate to Windward Gate + + + + 32.309693 + -64.835249 + + + 32.308046 + -64.831785 + + + + + + + 32.284680 + -64.850045 + + + 32.280164 + -64.847591 + + + + + + Windward Gate to Leeward Gate + + + + 32.284680 + -64.850045 + + + 32.280164 + -64.847591 + + + + + + + 32.309693 + -64.835249 + + + 32.308046 + -64.831785 + + + + + + Leeward Gate to Finish + + + + 32.309693 + -64.835249 + + + 32.308046 + -64.831785 + + + + + + + 32.317379 + -64.839291 + + + 32.317257 + -64.836260 + + + + + + + + + 32.313922 + -64.837168 + + + 32.317379 + -64.839291 + + + 32.317911 + -64.836996 + + + 32.317257 + -64.836260 + + + 32.304273 + -64.822834 + + + 32.279097 + -64.841545 + + + 32.279604 + -64.849871 + + + 32.289545 + -64.854162 + + + 32.290198 + -64.858711 + + + 32.297164 + -64.856394 + + + 32.296148 + -64.849184 + + + + Start Line + + 32.296577 + -64.854304 + + + 32.293771 + -64.855242 + + + + Mark + + 32.293039 + -64.843983 + + + + Windward Gate + + 32.284680 + -64.850045 + + + 32.280164 + -64.847591 + + + + Leeward Gate + + 32.309693 + -64.835249 + + + 32.308046 + -64.831785 + + + + Finish Line + + 32.317379 + -64.839291 + + + 32.317257 + -64.836260 + + + +