Changed public functions in the RaceXMLReader to make a new list every time and reassign the list to avoid duplicates in a list. #story[873]

This commit is contained in:
Joseph Gardner
2017-05-11 14:55:50 +12:00
parent 8c0c03dcf2
commit 602bc0686e
2 changed files with 11 additions and 1 deletions
@@ -80,6 +80,7 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
*/
public void readBoats() {
//get all boats
List<Boat> boats = new ArrayList<>();
NodeList nBoats = doc.getElementsByTagName("boat");
for (int i = 0; i < nBoats.getLength(); i++) {
@@ -96,6 +97,7 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
}
boats.add(boat);
}
this.boats = boats;
}
@@ -104,12 +106,14 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
*/
public void readMarkers() {
//get all boats
List<Marker> markers = new ArrayList<>();
NodeList nMarkers = doc.getElementsByTagName("marker");
for (int i = 0; i < nMarkers.getLength(); i++) {
Marker marker = getMarker((Element) nMarkers.item(i));
if (marker.getName() != null) markers.add(marker);
}
this.markers = markers;
}
/**
@@ -117,6 +121,7 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
*/
public void readLegs() {
//get all legs
List<Leg> legs = new ArrayList<>();
NodeList nLegs = doc.getElementsByTagName("leg");
for (int i = 0; i < nLegs.getLength(); i++) {
@@ -127,12 +132,14 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
Marker finishMarker = getMarker(finish);
legs.add(new Leg(label, startMarker, finishMarker, i));
}
this.legs = legs;
}
/**
* Read courses in XML file
*/
public void readCourse() {
List<GPSCoordinate> boundary = new ArrayList<>();
NodeList nCourse = doc.getElementsByTagName("course");
NodeList nBounds = ((Element) nCourse.item(0)).getElementsByTagName("boundaries");
@@ -197,6 +204,7 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
leewardPt2 = getCoordinates(nMarks, 3, 1);
finishPt1 = getCoordinates(nMarks, 4);
finishPt2 = getCoordinates(nMarks, 4, 1);
this.boundary = boundary;
}
/**