Added some doc strings
- Added doc strings to RaceXML - Added a few minor changes to bermuda_AC35.xml - Changes to the RaceXMLReader Unit Test
This commit is contained in:
@@ -24,11 +24,25 @@ public class RaceXMLReader extends XMLReader {
|
||||
private ArrayList<GPSCoordinate> 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 <coordinate></coordinate>
|
||||
* @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 <coordinate></coordinate>
|
||||
* @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 <coordinate></coordinate>
|
||||
* @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 <coordinate></coordinate>
|
||||
* @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 <coordinate></coordinate>
|
||||
* @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 <coordinate></coordinate>
|
||||
* @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);
|
||||
|
||||
@@ -173,16 +173,16 @@
|
||||
<longitude>-64.837168</longitude>
|
||||
</coordinate>
|
||||
<coordinate>
|
||||
<latitude>32.317403</latitude>
|
||||
<longitude>-64.838627</longitude>
|
||||
<latitude>32.317379</latitude>
|
||||
<longitude>-64.839291</longitude>
|
||||
</coordinate>
|
||||
<coordinate>
|
||||
<latitude>32.317911</latitude>
|
||||
<longitude>-64.836996</longitude>
|
||||
</coordinate>
|
||||
<coordinate>
|
||||
<latitude>32.317548</latitude>
|
||||
<longitude>-64.835022</longitude>
|
||||
<latitude>32.317257</latitude>
|
||||
<longitude>-64.836260</longitude>
|
||||
</coordinate>
|
||||
<coordinate>
|
||||
<latitude>32.304273</latitude>
|
||||
|
||||
@@ -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<BoatInRace> 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");
|
||||
|
||||
@@ -0,0 +1,268 @@
|
||||
<race>
|
||||
<boats>
|
||||
<boat>
|
||||
<name>ORACLE TEAM USA</name>
|
||||
<speed>20</speed>
|
||||
<abbr>USA</abbr>
|
||||
<colour>BLUEVIOLET</colour>
|
||||
</boat>
|
||||
<boat>
|
||||
<name>Land Rover BAR</name>
|
||||
<speed>30</speed>
|
||||
<abbr>GBR</abbr>
|
||||
<colour>BLACK</colour>
|
||||
</boat>
|
||||
<boat>
|
||||
<name>SoftBank Team Japan</name>
|
||||
<speed>25</speed>
|
||||
<abbr>JPN</abbr>
|
||||
<colour>RED</colour>
|
||||
</boat>
|
||||
<boat>
|
||||
<name>Groupama Team France</name>
|
||||
<speed>20</speed>
|
||||
<abbr>FRA</abbr>
|
||||
<colour>ORANGE</colour>
|
||||
</boat>
|
||||
<boat>
|
||||
<name>Artemis Racing</name>
|
||||
<speed>29</speed>
|
||||
<abbr>SWE</abbr>
|
||||
<colour>DARKOLIVEGREEN</colour>
|
||||
</boat>
|
||||
<boat>
|
||||
<name>Emirates Team New Zealand</name>
|
||||
<speed>62</speed>
|
||||
<abbr>NZL</abbr>
|
||||
<colour>LIMEGREEN</colour>
|
||||
</boat>
|
||||
</boats>
|
||||
<legs>
|
||||
<leg>
|
||||
<name>Start to Mark 1</name>
|
||||
<start>
|
||||
<marker>
|
||||
<coordinate>
|
||||
<latitude>32.296577</latitude>
|
||||
<longitude>-64.854304</longitude>
|
||||
</coordinate>
|
||||
<coordinate>
|
||||
<latitude>32.293771</latitude>
|
||||
<longitude>-64.855242</longitude>
|
||||
</coordinate>
|
||||
</marker>
|
||||
</start>
|
||||
<finish>
|
||||
<marker>
|
||||
<coordinate>
|
||||
<latitude>32.293039</latitude>
|
||||
<longitude>-64.843983</longitude>
|
||||
</coordinate>
|
||||
</marker>
|
||||
</finish>
|
||||
</leg>
|
||||
<leg>
|
||||
<name>Mark 1 to Leeward Gate</name>
|
||||
<start>
|
||||
<marker>
|
||||
<coordinate>
|
||||
<latitude>32.293039</latitude>
|
||||
<longitude>-64.843983</longitude>
|
||||
</coordinate>
|
||||
</marker>
|
||||
</start>
|
||||
<finish>
|
||||
<marker>
|
||||
<coordinate>
|
||||
<latitude>32.309693</latitude>
|
||||
<longitude>-64.835249</longitude>
|
||||
</coordinate>
|
||||
<coordinate>
|
||||
<latitude>32.308046</latitude>
|
||||
<longitude>-64.831785</longitude>
|
||||
</coordinate>
|
||||
</marker>
|
||||
</finish>
|
||||
</leg>
|
||||
<leg>
|
||||
<name>Leeward Gate to Windward Gate</name>
|
||||
<start>
|
||||
<marker>
|
||||
<coordinate>
|
||||
<latitude>32.309693</latitude>
|
||||
<longitude>-64.835249</longitude>
|
||||
</coordinate>
|
||||
<coordinate>
|
||||
<latitude>32.308046</latitude>
|
||||
<longitude>-64.831785</longitude>
|
||||
</coordinate>
|
||||
</marker>
|
||||
</start>
|
||||
<finish>
|
||||
<marker>
|
||||
<coordinate>
|
||||
<latitude>32.284680</latitude>
|
||||
<longitude>-64.850045</longitude>
|
||||
</coordinate>
|
||||
<coordinate>
|
||||
<latitude>32.280164</latitude>
|
||||
<longitude>-64.847591</longitude>
|
||||
</coordinate>
|
||||
</marker>
|
||||
</finish>
|
||||
</leg>
|
||||
<leg>
|
||||
<name>Windward Gate to Leeward Gate</name>
|
||||
<start>
|
||||
<marker>
|
||||
<coordinate>
|
||||
<latitude>32.284680</latitude>
|
||||
<longitude>-64.850045</longitude>
|
||||
</coordinate>
|
||||
<coordinate>
|
||||
<latitude>32.280164</latitude>
|
||||
<longitude>-64.847591</longitude>
|
||||
</coordinate>
|
||||
</marker>
|
||||
</start>
|
||||
<finish>
|
||||
<marker>
|
||||
<coordinate>
|
||||
<latitude>32.309693</latitude>
|
||||
<longitude>-64.835249</longitude>
|
||||
</coordinate>
|
||||
<coordinate>
|
||||
<latitude>32.308046</latitude>
|
||||
<longitude>-64.831785</longitude>
|
||||
</coordinate>
|
||||
</marker>
|
||||
</finish>
|
||||
</leg>
|
||||
<leg>
|
||||
<name>Leeward Gate to Finish</name>
|
||||
<start>
|
||||
<marker>
|
||||
<coordinate>
|
||||
<latitude>32.309693</latitude>
|
||||
<longitude>-64.835249</longitude>
|
||||
</coordinate>
|
||||
<coordinate>
|
||||
<latitude>32.308046</latitude>
|
||||
<longitude>-64.831785</longitude>
|
||||
</coordinate>
|
||||
</marker>
|
||||
</start>
|
||||
<finish>
|
||||
<marker>
|
||||
<coordinate>
|
||||
<latitude>32.317379</latitude>
|
||||
<longitude>-64.839291</longitude>
|
||||
</coordinate>
|
||||
<coordinate>
|
||||
<latitude>32.317257</latitude>
|
||||
<longitude>-64.836260</longitude>
|
||||
</coordinate>
|
||||
</marker>
|
||||
</finish>
|
||||
</leg>
|
||||
</legs>
|
||||
<course>
|
||||
<boundaries>
|
||||
<coordinate>
|
||||
<latitude>32.313922</latitude>
|
||||
<longitude>-64.837168</longitude>
|
||||
</coordinate>
|
||||
<coordinate>
|
||||
<latitude>32.317379</latitude>
|
||||
<longitude>-64.839291</longitude>
|
||||
</coordinate>
|
||||
<coordinate>
|
||||
<latitude>32.317911</latitude>
|
||||
<longitude>-64.836996</longitude>
|
||||
</coordinate>
|
||||
<coordinate>
|
||||
<latitude>32.317257</latitude>
|
||||
<longitude>-64.836260</longitude>
|
||||
</coordinate>
|
||||
<coordinate>
|
||||
<latitude>32.304273</latitude>
|
||||
<longitude>-64.822834</longitude>
|
||||
</coordinate>
|
||||
<coordinate>
|
||||
<latitude>32.279097</latitude>
|
||||
<longitude>-64.841545</longitude>
|
||||
</coordinate>
|
||||
<coordinate>
|
||||
<latitude>32.279604</latitude>
|
||||
<longitude>-64.849871</longitude>
|
||||
</coordinate>
|
||||
<coordinate>
|
||||
<latitude>32.289545</latitude>
|
||||
<longitude>-64.854162</longitude>
|
||||
</coordinate>
|
||||
<coordinate>
|
||||
<latitude>32.290198</latitude>
|
||||
<longitude>-64.858711</longitude>
|
||||
</coordinate>
|
||||
<coordinate>
|
||||
<latitude>32.297164</latitude>
|
||||
<longitude>-64.856394</longitude>
|
||||
</coordinate>
|
||||
<coordinate>
|
||||
<latitude>32.296148</latitude>
|
||||
<longitude>-64.849184</longitude>
|
||||
</coordinate>
|
||||
</boundaries>
|
||||
<marker>
|
||||
<name>Start Line</name>
|
||||
<coordinate>
|
||||
<latitude>32.296577</latitude>
|
||||
<longitude>-64.854304</longitude>
|
||||
</coordinate>
|
||||
<coordinate>
|
||||
<latitude>32.293771</latitude>
|
||||
<longitude>-64.855242</longitude>
|
||||
</coordinate>
|
||||
</marker>
|
||||
<marker>
|
||||
<name>Mark</name>
|
||||
<coordinate>
|
||||
<latitude>32.293039</latitude>
|
||||
<longitude>-64.843983</longitude>
|
||||
</coordinate>
|
||||
</marker>
|
||||
<marker>
|
||||
<name>Windward Gate</name>
|
||||
<coordinate>
|
||||
<latitude>32.284680</latitude>
|
||||
<longitude>-64.850045</longitude>
|
||||
</coordinate>
|
||||
<coordinate>
|
||||
<latitude>32.280164</latitude>
|
||||
<longitude>-64.847591</longitude>
|
||||
</coordinate>
|
||||
</marker>
|
||||
<marker>
|
||||
<name>Leeward Gate</name>
|
||||
<coordinate>
|
||||
<latitude>32.309693</latitude>
|
||||
<longitude>-64.835249</longitude>
|
||||
</coordinate>
|
||||
<coordinate>
|
||||
<latitude>32.308046</latitude>
|
||||
<longitude>-64.831785</longitude>
|
||||
</coordinate>
|
||||
</marker>
|
||||
<marker>
|
||||
<name>Finish Line</name>
|
||||
<coordinate>
|
||||
<latitude>32.317379</latitude>
|
||||
<longitude>-64.839291</longitude>
|
||||
</coordinate>
|
||||
<coordinate>
|
||||
<latitude>32.317257</latitude>
|
||||
<longitude>-64.836260</longitude>
|
||||
</coordinate>
|
||||
</marker>
|
||||
</course>
|
||||
</race>
|
||||
Reference in New Issue
Block a user