|
|
|
@ -1,5 +1,6 @@
|
|
|
|
package seng302.Mock;
|
|
|
|
package seng302.Mock;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.joda.time.DateTime;
|
|
|
|
import org.w3c.dom.Element;
|
|
|
|
import org.w3c.dom.Element;
|
|
|
|
import org.w3c.dom.NamedNodeMap;
|
|
|
|
import org.w3c.dom.NamedNodeMap;
|
|
|
|
import org.w3c.dom.Node;
|
|
|
|
import org.w3c.dom.Node;
|
|
|
|
@ -15,20 +16,23 @@ import java.io.IOException;
|
|
|
|
import java.text.DateFormat;
|
|
|
|
import java.text.DateFormat;
|
|
|
|
import java.text.ParseException;
|
|
|
|
import java.text.ParseException;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
|
|
|
import java.time.ZonedDateTime;
|
|
|
|
|
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Created by jjg64 on 21/04/17.
|
|
|
|
* Created by jjg64 on 21/04/17.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public class StreamedCourseXMLReader extends XMLReader {
|
|
|
|
public class StreamedCourseXMLReader extends XMLReader {
|
|
|
|
private static double COORDINATEPADDING = 0.0005;
|
|
|
|
private static double COORDINATEPADDING = 0.000;
|
|
|
|
private GPSCoordinate mapTopLeft, mapBottomRight;
|
|
|
|
private GPSCoordinate mapTopLeft, mapBottomRight;
|
|
|
|
private List<GPSCoordinate> boundary = new ArrayList<>();
|
|
|
|
private List<GPSCoordinate> boundary = new ArrayList<>();
|
|
|
|
private Map<Integer,Element> marks = new HashMap<>();
|
|
|
|
private Map<Integer,Element> compoundMarks = new HashMap<>();
|
|
|
|
private Map<Integer, StreamedBoat> participants = new HashMap<>();
|
|
|
|
private Map<Integer, StreamedBoat> participants = new HashMap<>();
|
|
|
|
private List<Leg> legs = new ArrayList<>();
|
|
|
|
private List<Leg> legs = new ArrayList<>();
|
|
|
|
Date creationTimeDate;
|
|
|
|
private List<Marker> markers = new ArrayList<>();
|
|
|
|
Date raceStartTime;
|
|
|
|
ZonedDateTime creationTimeDate;
|
|
|
|
|
|
|
|
ZonedDateTime raceStartTime;
|
|
|
|
int raceID;
|
|
|
|
int raceID;
|
|
|
|
String raceType;
|
|
|
|
String raceType;
|
|
|
|
boolean postpone;
|
|
|
|
boolean postpone;
|
|
|
|
@ -66,14 +70,14 @@ public class StreamedCourseXMLReader extends XMLReader {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void readRace() throws ParseException {
|
|
|
|
private void readRace() throws ParseException {
|
|
|
|
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
|
|
|
|
DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssZ");
|
|
|
|
Element settings = (Element) doc.getElementsByTagName("Race").item(0);
|
|
|
|
Element settings = (Element) doc.getElementsByTagName("Race").item(0);
|
|
|
|
|
|
|
|
|
|
|
|
raceID = Integer.parseInt(getTextValueOfNode(settings, "RaceID"));
|
|
|
|
raceID = Integer.parseInt(getTextValueOfNode(settings, "RaceID"));
|
|
|
|
raceType = getTextValueOfNode(settings, "RaceType");
|
|
|
|
raceType = getTextValueOfNode(settings, "RaceType");
|
|
|
|
creationTimeDate = dateFormat.parse(getTextValueOfNode(settings, "CreationTimeDate"));
|
|
|
|
creationTimeDate = ZonedDateTime.parse(getTextValueOfNode(settings, "CreationTimeDate"), dateFormat);
|
|
|
|
NamedNodeMap raceTimeTag = doc.getElementsByTagName("RaceStartTime").item(0).getAttributes();
|
|
|
|
NamedNodeMap raceTimeTag = doc.getElementsByTagName("RaceStartTime").item(0).getAttributes();
|
|
|
|
raceStartTime = dateFormat.parse(raceTimeTag.getNamedItem("Time").getTextContent());
|
|
|
|
raceStartTime = ZonedDateTime.parse(raceTimeTag.getNamedItem("Time").getTextContent(), dateFormat);
|
|
|
|
postpone = Boolean.parseBoolean(raceTimeTag.getNamedItem("Postpone").getTextContent());
|
|
|
|
postpone = Boolean.parseBoolean(raceTimeTag.getNamedItem("Postpone").getTextContent());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -98,14 +102,17 @@ public class StreamedCourseXMLReader extends XMLReader {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Indexes CompoundMark elements by their ID for use in generating the course.
|
|
|
|
* Indexes CompoundMark elements by their ID for use in generating the course, and populates list of Markers.
|
|
|
|
|
|
|
|
* @see seng302.Model.Marker
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private void readCompoundMarks() {
|
|
|
|
private void readCompoundMarks() throws StreamedCourseXMLException {
|
|
|
|
Element nCourse = (Element) doc.getElementsByTagName("Course").item(0);
|
|
|
|
Element nCourse = (Element) doc.getElementsByTagName("Course").item(0);
|
|
|
|
for(int i = 0; i < nCourse.getChildNodes().getLength(); i++) {
|
|
|
|
for(int i = 0; i < nCourse.getChildNodes().getLength(); i++) {
|
|
|
|
Node compoundMark = nCourse.getChildNodes().item(i);
|
|
|
|
Node compoundMark = nCourse.getChildNodes().item(i);
|
|
|
|
if(compoundMark.getNodeName().equals("CompoundMark")) {
|
|
|
|
if(compoundMark.getNodeName().equals("CompoundMark")) {
|
|
|
|
marks.put(getCompoundMarkID((Element)compoundMark),(Element)compoundMark);
|
|
|
|
int compoundMarkID = getCompoundMarkID((Element) compoundMark);
|
|
|
|
|
|
|
|
compoundMarks.put(compoundMarkID, (Element)compoundMark);
|
|
|
|
|
|
|
|
markers.add(getMarker(compoundMarkID));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -114,11 +121,11 @@ public class StreamedCourseXMLReader extends XMLReader {
|
|
|
|
* Generates a Marker from the CompoundMark element with given ID.
|
|
|
|
* Generates a Marker from the CompoundMark element with given ID.
|
|
|
|
* @param compoundMarkID index of required CompoundMark element
|
|
|
|
* @param compoundMarkID index of required CompoundMark element
|
|
|
|
* @return generated Marker
|
|
|
|
* @return generated Marker
|
|
|
|
* @throws StreamedCourseXMLException if CompoundMark element contains unhandled number of marks
|
|
|
|
* @throws StreamedCourseXMLException if CompoundMark element contains unhandled number of compoundMarks
|
|
|
|
* @see seng302.Model.Marker
|
|
|
|
* @see seng302.Model.Marker
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private Marker getMarker(int compoundMarkID) throws StreamedCourseXMLException {
|
|
|
|
private Marker getMarker(int compoundMarkID) throws StreamedCourseXMLException {
|
|
|
|
Element compoundMark = marks.get(compoundMarkID);
|
|
|
|
Element compoundMark = compoundMarks.get(compoundMarkID);
|
|
|
|
NodeList nMarks = compoundMark.getElementsByTagName("Mark");
|
|
|
|
NodeList nMarks = compoundMark.getElementsByTagName("Mark");
|
|
|
|
Marker marker;
|
|
|
|
Marker marker;
|
|
|
|
|
|
|
|
|
|
|
|
@ -152,7 +159,7 @@ public class StreamedCourseXMLReader extends XMLReader {
|
|
|
|
* @return value of "name" attribute
|
|
|
|
* @return value of "name" attribute
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private String getCompoundMarkName(int compoundMarkID) {
|
|
|
|
private String getCompoundMarkName(int compoundMarkID) {
|
|
|
|
return marks.get(compoundMarkID).getAttribute("Name");
|
|
|
|
return compoundMarks.get(compoundMarkID).getAttribute("Name");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
@ -184,6 +191,7 @@ public class StreamedCourseXMLReader extends XMLReader {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
double maxLatitude = boundary.stream().max(Comparator.comparingDouble(GPSCoordinate::getLatitude)).get().getLatitude() + COORDINATEPADDING;
|
|
|
|
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 maxLongitude = boundary.stream().max(Comparator.comparingDouble(GPSCoordinate::getLongitude)).get().getLongitude() + COORDINATEPADDING;
|
|
|
|
double minLatitude = boundary.stream().min(Comparator.comparingDouble(GPSCoordinate::getLatitude)).get().getLatitude() + COORDINATEPADDING;
|
|
|
|
double minLatitude = boundary.stream().min(Comparator.comparingDouble(GPSCoordinate::getLatitude)).get().getLatitude() + COORDINATEPADDING;
|
|
|
|
@ -209,15 +217,17 @@ public class StreamedCourseXMLReader extends XMLReader {
|
|
|
|
return legs;
|
|
|
|
return legs;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public List<Marker> getMarkers() { return markers; }
|
|
|
|
|
|
|
|
|
|
|
|
public Double getPadding() {
|
|
|
|
public Double getPadding() {
|
|
|
|
return COORDINATEPADDING;
|
|
|
|
return COORDINATEPADDING;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Date getCreationTimeDate() {
|
|
|
|
public ZonedDateTime getCreationTimeDate() {
|
|
|
|
return creationTimeDate;
|
|
|
|
return creationTimeDate;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Date getRaceStartTime() {
|
|
|
|
public ZonedDateTime getRaceStartTime() {
|
|
|
|
return raceStartTime;
|
|
|
|
return raceStartTime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|