Linked raceData from new xml formats to current program. Current app now shows the starting list and course boundary. #story[782]

This commit is contained in:
Joseph Gardner
2017-04-25 16:06:24 +12:00
parent cb40302c13
commit c328c4f3bc
9 changed files with 435 additions and 15 deletions
@@ -1,5 +1,7 @@
package seng302.Mock;
import seng302.GPSCoordinate;
/**
* Created by jjg64 on 19/04/17.
*/
@@ -96,4 +98,8 @@ public class Regatta {
public void setMagneticVariation(float magneticVariation) {
this.magneticVariation = magneticVariation;
}
public GPSCoordinate getGPSCoordinate() {
return new GPSCoordinate(centralLatitude, centralLongitude);
}
}
@@ -3,26 +3,55 @@ package seng302.Mock;
import seng302.GPSCoordinate;
import seng302.Model.BoatInRace;
import seng302.Model.Leg;
import seng302.Model.RaceClock;
import seng302.RaceDataSource;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.*;
/**
* Created by jjg64 on 21/04/17.
*/
public class StreamedCourse implements RaceDataSource {
StreamedCourseXMLReader streamedCourseXMLReader;
StreamedCourseXMLReader streamedCourseXMLReader = null;
BoatXMLReader boatXMLReader = null;
RegattaXMLReader regattaXMLReader = null;
List<GPSCoordinate> boundary = new ArrayList<>();
public StreamedCourse(StreamedCourseXMLReader streamedCourseXMLReader) {
this.streamedCourseXMLReader = streamedCourseXMLReader;
}
public StreamedCourse(BoatXMLReader boatXMLReader) {
this.boatXMLReader = boatXMLReader;
}
public void setBoatXMLReader(BoatXMLReader boatXMLReader) {
this.boatXMLReader = boatXMLReader;
if (streamedCourseXMLReader != null) {
boatXMLReader.setParticipants(streamedCourseXMLReader.getParticipants());
boatXMLReader.read();
}
}
public void setStreamedCourseXMLReader(StreamedCourseXMLReader streamedCourseXMLReader) {
this.streamedCourseXMLReader = streamedCourseXMLReader;
if (streamedCourseXMLReader != null) {
boatXMLReader.setParticipants(streamedCourseXMLReader.getParticipants());
boatXMLReader.read();
}
}
public void setRegattaXMLReader(RegattaXMLReader regattaXMLReader) {
this.regattaXMLReader = regattaXMLReader;
}
public RegattaXMLReader getRegattaXMLReader() {
return regattaXMLReader;
}
public List<BoatInRace> getBoats() {
return null;
return new ArrayList<>(boatXMLReader.getStreamedBoatMap().values());
}
public List<Leg> getLegs() {
@@ -34,7 +63,7 @@ public class StreamedCourse implements RaceDataSource {
}
public ZonedDateTime getZonedDateTime() {
return null;
return RaceClock.getCurrentZonedDateTime(regattaXMLReader.getRegatta().getGPSCoordinate());
}
public GPSCoordinate getMapTopLeft() {
@@ -44,7 +73,4 @@ public class StreamedCourse implements RaceDataSource {
public GPSCoordinate getMapBottomRight() {
return streamedCourseXMLReader.getMapBottomRight();
}
}
@@ -25,6 +25,7 @@ public class StreamedCourseXMLReader extends XMLReader {
private GPSCoordinate mapTopLeft, mapBottomRight;
private List<GPSCoordinate> boundary = new ArrayList<>();
private Map<Integer,Element> marks = new HashMap<>();
private Map<Integer, StreamedBoat> participants = new HashMap<>();
private List<Leg> legs = new ArrayList<>();
Date creationTimeDate;
Date raceStartTime;
@@ -77,8 +78,17 @@ public class StreamedCourseXMLReader extends XMLReader {
}
private void readParticipants() {
//TODO Modify BoatInRace to take in a sourceID
//TODO Produce list of BoatInRace
Element nParticipants = (Element) doc.getElementsByTagName("Participants").item(0);
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, new StreamedBoat(sourceID));
}
}
}
}
private void readCourse() throws StreamedCourseXMLException {
@@ -222,4 +232,8 @@ public class StreamedCourseXMLReader extends XMLReader {
public boolean isPostpone() {
return postpone;
}
public Map<Integer, StreamedBoat> getParticipants() {
return participants;
}
}