mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Merged with develop. Fixed many bugs in Visualiser.
#bugs
This commit is contained in:
@@ -9,7 +9,7 @@ import java.net.Socket;
|
||||
public class Player {
|
||||
|
||||
private Socket socket;
|
||||
private Boat boat;
|
||||
private Yacht yacht;
|
||||
private Integer lastMarkPassed;
|
||||
|
||||
|
||||
@@ -30,8 +30,8 @@ public class Player {
|
||||
this.lastMarkPassed = lastMarkPassed;
|
||||
}
|
||||
|
||||
public Boat getYacht() {
|
||||
return boat;
|
||||
public Yacht getYacht() {
|
||||
return yacht;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -3,8 +3,8 @@ package seng302.model;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.TimeZone;
|
||||
import seng302.model.stream.parsers.RaceStartData;
|
||||
import seng302.model.stream.parsers.RaceStatusData;
|
||||
import seng302.model.stream.parser.RaceStartData;
|
||||
import seng302.model.stream.parser.RaceStatusData;
|
||||
|
||||
/**
|
||||
* Class for storing race data that does not relate to specific vessels or marks such as time or wind.
|
||||
@@ -19,7 +19,7 @@ public class RaceState {
|
||||
private double windDirection;
|
||||
private long raceTime;
|
||||
private long expectedStartTime;
|
||||
private boolean isRaceStarted;
|
||||
private boolean isRaceStarted = false;
|
||||
// long timeTillStart;
|
||||
|
||||
public RaceState() {
|
||||
|
||||
@@ -5,17 +5,13 @@ import javafx.beans.property.ReadOnlyDoubleWrapper;
|
||||
import javafx.beans.property.ReadOnlyLongProperty;
|
||||
import javafx.beans.property.ReadOnlyLongWrapper;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.paint.Paint;
|
||||
import seng302.model.mark.Mark;
|
||||
import static seng302.utilities.GeoUtility.getGeoCoordinate;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
import javafx.scene.paint.Color;
|
||||
import seng302.client.ClientPacketParser;
|
||||
import seng302.controllers.RaceViewController;
|
||||
import seng302.gameServer.GameState;
|
||||
import seng302.models.mark.Mark;
|
||||
import seng302.utilities.GeoPoint;
|
||||
|
||||
/**
|
||||
@@ -24,17 +20,8 @@ import seng302.utilities.GeoPoint;
|
||||
* Class created to store more variables (eg. boat statuses) compared to the XMLParser boat class,
|
||||
* also done outside Boat class because some old variables are not used anymore.
|
||||
*/
|
||||
public class Boat {
|
||||
|
||||
private final Double TURN_STEP = 5.0;
|
||||
|
||||
private Double lastHeading;
|
||||
private Boolean sailIn;
|
||||
|
||||
|
||||
// Used in boat group
|
||||
private Color colour = Color.BLACK;
|
||||
|
||||
public class Yacht {
|
||||
//BOTH AFAIK
|
||||
private String boatType;
|
||||
private Integer sourceId;
|
||||
private String hullID; //matches HullNum in the XML spec.
|
||||
@@ -42,28 +29,32 @@ public class Boat {
|
||||
private String boatName;
|
||||
private String country;
|
||||
|
||||
// Boat status
|
||||
private Integer boatStatus;
|
||||
private Integer legNumber = 0;
|
||||
private Integer position = 0;
|
||||
private Long estimateTimeAtFinish;
|
||||
private Long markRoundTime;
|
||||
private Double lat;
|
||||
private Double lon;
|
||||
private Double heading;
|
||||
private ReadOnlyDoubleWrapper velocity = new ReadOnlyDoubleWrapper();
|
||||
private ReadOnlyLongWrapper timeTillNext = new ReadOnlyLongWrapper();
|
||||
private ReadOnlyLongWrapper timeSinceLastMark = new ReadOnlyLongWrapper();
|
||||
private String position;
|
||||
private GeoPoint location;
|
||||
private Double heading;
|
||||
private Double velocity;
|
||||
private Long timeTillNext;
|
||||
private Long markRoundTime;
|
||||
private Double heading;
|
||||
private Double lat;
|
||||
private Double lon;
|
||||
private Integer legNumber = 0;
|
||||
|
||||
// Mark rounding
|
||||
//SERVER SIDE
|
||||
private final Double TURN_STEP = 5.0;
|
||||
private Double lastHeading;
|
||||
private Boolean sailIn;
|
||||
private String position;
|
||||
private GeoPoint location;
|
||||
private Integer boatStatus;
|
||||
private Double velocity;
|
||||
|
||||
//CLIENT SIDE
|
||||
private ReadOnlyDoubleWrapper velocityProperty = new ReadOnlyDoubleWrapper();
|
||||
private ReadOnlyLongWrapper timeTillNextProperty = new ReadOnlyLongWrapper();
|
||||
private ReadOnlyLongWrapper timeSinceLastMarkProperty = new ReadOnlyLongWrapper();
|
||||
private ReadOnlyDoubleProperty headingProperty = new ReadOnlyDoubleWrapper();
|
||||
private Mark lastMarkRounded;
|
||||
private Mark nextMark;
|
||||
private Integer positionInt = 0;
|
||||
private Color colour;
|
||||
|
||||
|
||||
/**
|
||||
@@ -110,8 +101,6 @@ public class Boat {
|
||||
|
||||
public Yacht(String boatType, Integer sourceId, String hullID, String shortName,
|
||||
String boatName, String country) {
|
||||
public Boat(String boatType, Integer sourceID, String hullID, String shortName,
|
||||
String boatName, String country) {
|
||||
this.boatType = boatType;
|
||||
this.sourceId = sourceId;
|
||||
this.hullID = hullID;
|
||||
@@ -134,18 +123,13 @@ public class Boat {
|
||||
Double thisHeading = ((double) Math.floorMod(heading.longValue(), 360L));
|
||||
Double windSpeedKnots = 0d;
|
||||
Double boatSpeedInKnots = PolarTable.getBoatSpeed(windSpeedKnots, thisHeading);
|
||||
velocity = boatSpeedInKnots / ClientPacketParser.MS_TO_KNOTS * 3000;
|
||||
velocity = boatSpeedInKnots / 1.94384449 * 3000; // TODO: 25/07/17 cir27 - remove magic numbers
|
||||
//System.out.println("velocity = " + velocity);
|
||||
Double metersCovered = velocity * secondsElapsed;
|
||||
location = getGeoCoordinate(location, heading, metersCovered);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Double getHeading() {
|
||||
return heading;
|
||||
}
|
||||
|
||||
public void adjustHeading(Double amount) {
|
||||
lastHeading = heading;
|
||||
// TODO: 24/07/17 wmu16 - '%' in java does remainder, we need modulo. All this must be changed here, this is why we have neg values!
|
||||
@@ -244,15 +228,14 @@ public class Boat {
|
||||
}
|
||||
|
||||
public void setLegNumber(Integer legNumber) {
|
||||
if (colour != null && position != "-" && legNumber != this.legNumber&& RaceViewController.sparkLineStatus(
|
||||
sourceId)) {
|
||||
RaceViewController.updateYachtPositionSparkline(this, legNumber);
|
||||
}
|
||||
// if (colour != null && position != "-" && legNumber != this.legNumber) {
|
||||
// RaceViewController.updateYachtPositionSparkline(this, legNumber);
|
||||
// }
|
||||
this.legNumber = legNumber;
|
||||
}
|
||||
|
||||
public void setEstimateTimeTillNextMark(Long estimateTimeAtNextMark) {
|
||||
timeTillNext.set(estimateTimeAtNextMark);
|
||||
public void setEstimateTimeTillNextMark(Long estimateTimeTillNextMark) {
|
||||
timeTillNext = estimateTimeTillNextMark;
|
||||
}
|
||||
|
||||
public String getEstimateTimeAtFinish() {
|
||||
@@ -264,37 +247,28 @@ public class Boat {
|
||||
this.estimateTimeAtFinish = estimateTimeAtFinish;
|
||||
}
|
||||
|
||||
public Integer getPosition() {
|
||||
return position;
|
||||
public Integer getPositionInteger() {
|
||||
return positionInt;
|
||||
}
|
||||
|
||||
public void setPosition(Integer position) {
|
||||
this.position = position;
|
||||
public void setPositionInteger(Integer position) {
|
||||
this.positionInt = position;
|
||||
}
|
||||
|
||||
public Color getColour() {
|
||||
return colour;
|
||||
public void setVelocityProperty(double velocity) {
|
||||
this.velocityProperty.set(velocity);
|
||||
}
|
||||
|
||||
public void setColour(Color colour) {
|
||||
this.colour = colour;
|
||||
}
|
||||
|
||||
public void setVelocity(double velocity) {
|
||||
this.velocity.set(velocity);
|
||||
}
|
||||
|
||||
|
||||
public void setMarkRoundingTime(Long markRoundingTime) {
|
||||
this.markRoundTime = markRoundingTime;
|
||||
}
|
||||
|
||||
public ReadOnlyDoubleProperty getVelocityProperty() {
|
||||
return velocity.getReadOnlyProperty();
|
||||
return velocityProperty.getReadOnlyProperty();
|
||||
}
|
||||
|
||||
public ReadOnlyLongProperty timeTillNextProperty() {
|
||||
return timeTillNext.getReadOnlyProperty();
|
||||
return timeTillNextProperty.getReadOnlyProperty();
|
||||
}
|
||||
|
||||
public Long getMarkRoundTime() {
|
||||
@@ -339,6 +313,8 @@ public class Boat {
|
||||
|
||||
public void setHeading(Double heading) {
|
||||
this.heading = heading;
|
||||
}
|
||||
|
||||
public Boolean getSailIn() {
|
||||
return sailIn;
|
||||
}
|
||||
@@ -352,12 +328,37 @@ public class Boat {
|
||||
return location;
|
||||
}
|
||||
|
||||
public void setTimeSinceLastMark (long timeSinceLastMark) {
|
||||
this.timeSinceLastMark.set(timeSinceLastMark);
|
||||
public void updateTimeSinceLastMarkProperty(long timeSinceLastMark) {
|
||||
this.timeSinceLastMarkProperty.set(timeSinceLastMark);
|
||||
}
|
||||
|
||||
public ReadOnlyLongProperty timeSinceLastMarkProperty () {
|
||||
return timeSinceLastMark.getReadOnlyProperty();
|
||||
return timeSinceLastMarkProperty.getReadOnlyProperty();
|
||||
}
|
||||
|
||||
public Long getTimeTillNext() {
|
||||
return timeTillNext;
|
||||
}
|
||||
|
||||
public void setTimeTillNext(Long timeTillNext) {
|
||||
this.timeTillNext = timeTillNext;
|
||||
}
|
||||
|
||||
|
||||
public Color getColour() {
|
||||
return colour;
|
||||
}
|
||||
|
||||
public void setColour(Color colour) {
|
||||
this.colour = colour;
|
||||
}
|
||||
|
||||
|
||||
public Double getVelocity() {
|
||||
return velocity;
|
||||
}
|
||||
|
||||
public void setVelocity(Double velocity) {
|
||||
this.velocity = velocity;
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
package seng302.model.stream.parsers;
|
||||
package seng302.model.stream.parser;
|
||||
|
||||
|
||||
/**
|
||||
@@ -11,7 +11,7 @@ public class MarkRoundingData {
|
||||
private int roundingSide;
|
||||
private long timeStamp;
|
||||
|
||||
public MarkRoundingData(int boatId, int markId, int roundingSide, long timeStamp) {
|
||||
MarkRoundingData(int boatId, int markId, int roundingSide, long timeStamp) {
|
||||
this.boatId = boatId;
|
||||
this.markId = markId;
|
||||
this.roundingSide = roundingSide;
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
package seng302.model.stream.parsers;
|
||||
package seng302.model.stream.parser;
|
||||
|
||||
public class PositionUpdateData {
|
||||
|
||||
@@ -14,7 +14,7 @@ public class PositionUpdateData {
|
||||
private double heading;
|
||||
private double groundSpeed;
|
||||
|
||||
public PositionUpdateData(int deviceId, DeviceType type, double lat, double lon,
|
||||
PositionUpdateData(int deviceId, DeviceType type, double lat, double lon,
|
||||
double heading, double groundSpeed) {
|
||||
this.deviceId = deviceId;
|
||||
this.type = type;
|
||||
+6
-6
@@ -1,16 +1,16 @@
|
||||
package seng302.model.stream.parsers;
|
||||
package seng302.model.stream.parser;
|
||||
|
||||
/**
|
||||
* Class for storing data parsed from race start status packet
|
||||
*/
|
||||
public class RaceStartData {
|
||||
|
||||
long raceId;
|
||||
long raceStartTime;
|
||||
int notificationType;
|
||||
long timeStamp;
|
||||
private long raceId;
|
||||
private long raceStartTime;
|
||||
private int notificationType;
|
||||
private long timeStamp;
|
||||
|
||||
public RaceStartData (long raceId, long raceStartTime, int notificationType, long timeStamp) {
|
||||
RaceStartData (long raceId, long raceStartTime, int notificationType, long timeStamp) {
|
||||
this.raceId = raceId;
|
||||
this.raceStartTime = raceStartTime;
|
||||
this.notificationType = notificationType;
|
||||
+4
-4
@@ -1,4 +1,4 @@
|
||||
package seng302.model.stream.parsers;
|
||||
package seng302.model.stream.parser;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -17,9 +17,9 @@ public class RaceStatusData {
|
||||
private boolean raceStarted = false;
|
||||
private long currentTime;
|
||||
private long expectedStartTime;
|
||||
List<long[]> boatData = new ArrayList<>();
|
||||
private List<long[]> boatData = new ArrayList<>();
|
||||
|
||||
public RaceStatusData(
|
||||
RaceStatusData(
|
||||
long windDir, long rawWindSpeed, int raceStatus, long currentTime, long expectedStartTime) {
|
||||
|
||||
windDirection = windDir / WIND_DIR_FACTOR;
|
||||
@@ -29,7 +29,7 @@ public class RaceStatusData {
|
||||
this.expectedStartTime = expectedStartTime;
|
||||
}
|
||||
|
||||
public void addBoatData (long boatID, long estTimeToNextMark, long estTimeToFinish, int leg) {
|
||||
void addBoatData (long boatID, long estTimeToNextMark, long estTimeToFinish, int leg) {
|
||||
boatData.add(new long[] {boatID, estTimeToNextMark, estTimeToFinish, leg});
|
||||
}
|
||||
|
||||
+2
-3
@@ -1,6 +1,6 @@
|
||||
package seng302.model.stream.parsers;
|
||||
package seng302.model.stream.parser;
|
||||
|
||||
import seng302.model.stream.parsers.PositionUpdateData.DeviceType;
|
||||
import seng302.model.stream.parser.PositionUpdateData.DeviceType;
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.util.ArrayList;
|
||||
@@ -14,7 +14,6 @@ import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
import seng302.model.stream.packets.PacketType;
|
||||
import seng302.model.stream.packets.StreamPacket;
|
||||
import seng302.model.stream.parsers.xml.RegattaXMLData;
|
||||
|
||||
/**
|
||||
* StreamParser is a utilities class for taking byte data, formatted according to the AC35
|
||||
@@ -0,0 +1,52 @@
|
||||
package seng302.model.stream.xml.generator;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import seng302.model.Yacht;
|
||||
|
||||
/**
|
||||
* A Race object that can be parsed into XML
|
||||
*/
|
||||
public class Race {
|
||||
private List<Yacht> yachts;
|
||||
private LocalDateTime startTime;
|
||||
|
||||
public Race(){
|
||||
yachts = new ArrayList<>();
|
||||
startTime = LocalDateTime.now();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a boat to the race
|
||||
* @param yacht The boat to add
|
||||
*/
|
||||
public void addBoat(Yacht yacht){
|
||||
yachts.add(yacht);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of boats in the race
|
||||
* @return A List of boats
|
||||
*/
|
||||
public List<Yacht> getBoats(){
|
||||
return Collections.unmodifiableList(yachts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the time until the race starts
|
||||
* @param seconds The time in seconds until the race starts
|
||||
*/
|
||||
public void setRaceStartDelay(Integer seconds){
|
||||
startTime = startTime.plusMinutes(seconds);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the time the race starts
|
||||
* @return The time the race starts
|
||||
*/
|
||||
public String getRaceStartTime(){
|
||||
return startTime.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package seng302.model.stream.xml.generator;
|
||||
|
||||
/**
|
||||
* A Race regatta that can be parsed into XML
|
||||
*/
|
||||
public class Regatta {
|
||||
private final Double DEFAULT_ALTITUDE = 0d;
|
||||
private final Integer DEFAULT_REGATTA_ID = 0;
|
||||
|
||||
private Integer id;
|
||||
private String name;
|
||||
private String courseName;
|
||||
|
||||
private Double latitude;
|
||||
private Double longitude;
|
||||
private Double altitude;
|
||||
|
||||
private Integer utcOffset;
|
||||
private Double magneticVariation;
|
||||
|
||||
public Regatta(String name, Double latitude, Double longitude) {
|
||||
this.name = name;
|
||||
this.id = DEFAULT_REGATTA_ID;
|
||||
this.courseName = name;
|
||||
|
||||
this.latitude = latitude;
|
||||
this.longitude = longitude;
|
||||
this.altitude = DEFAULT_ALTITUDE;
|
||||
|
||||
this.utcOffset = 0;
|
||||
this.magneticVariation = 0d;
|
||||
}
|
||||
|
||||
public void setMagneticVariation(Double magneticVariation){
|
||||
this.magneticVariation = magneticVariation;
|
||||
}
|
||||
|
||||
public void setUtcOffset(Integer offset){
|
||||
this.utcOffset = offset;
|
||||
}
|
||||
|
||||
/*
|
||||
NOTE!! The following getters must follow the JavaBean standard (getPropertyName()), and must be public.
|
||||
*/
|
||||
|
||||
public String getName(){
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getCourseName(){
|
||||
return courseName;
|
||||
}
|
||||
|
||||
public Integer getRegattaId(){
|
||||
return id;
|
||||
}
|
||||
|
||||
public Double getLatitude() {
|
||||
return latitude;
|
||||
}
|
||||
|
||||
public Double getLongitude() {
|
||||
return longitude;
|
||||
}
|
||||
|
||||
public Double getAltitude() {
|
||||
return altitude;
|
||||
}
|
||||
|
||||
public Integer getUtcOffset(){
|
||||
return utcOffset;
|
||||
}
|
||||
|
||||
public Double getMagneticVariation(){
|
||||
return magneticVariation;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
package seng302.model.stream.xml.generator;
|
||||
|
||||
import freemarker.template.Configuration;
|
||||
import freemarker.template.Template;
|
||||
import freemarker.template.TemplateException;
|
||||
import seng302.server.messages.XMLMessageSubType;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* An XML generator to generate the Race, Boat, and Regatta XML dynamically
|
||||
*/
|
||||
public class XMLGenerator {
|
||||
private static final String XML_TEMPLATE_DIR = "/server_config/xml_templates";
|
||||
private static final String REGATTA_TEMPLATE_NAME = "regatta.ftlh";
|
||||
private static final String BOATS_TEMPLATE_NAME = "boats.ftlh";
|
||||
private static final String RACE_TEMPLATE_NAME = "race.ftlh";
|
||||
private Configuration configuration;
|
||||
private Regatta regatta;
|
||||
private Race race;
|
||||
|
||||
/**
|
||||
* Set up a configuration instance for Apache Freemake
|
||||
*/
|
||||
private void setupConfiguration() {
|
||||
configuration = new Configuration(Configuration.VERSION_2_3_26);
|
||||
|
||||
try {
|
||||
configuration.setClassForTemplateLoading(getClass(), XML_TEMPLATE_DIR);
|
||||
} catch (NullPointerException e){
|
||||
System.out.println("[FATAL] Server could not load XML Template directory, ensure this directory isn't empty");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of the XML Generator
|
||||
*/
|
||||
public XMLGenerator(){
|
||||
setupConfiguration();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the race regatta to send to players
|
||||
* Note: This must be set before a regatta message can be generated
|
||||
* @param regatta The race regatta
|
||||
*/
|
||||
public void setRegatta(Regatta regatta){
|
||||
this.regatta = regatta;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the race to send to players
|
||||
* Note: This must be set before a boat or race message can be generated
|
||||
* @param race The race
|
||||
*/
|
||||
public void setRace(Race race){
|
||||
this.race = race;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse an XML template and generate the output as a string
|
||||
* @param templateName The templates file name
|
||||
* @param type The XML message sub type
|
||||
*/
|
||||
private String parseToXmlString(String templateName, XMLMessageSubType type) throws IOException, TemplateException {
|
||||
Template template;
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
OutputStreamWriter writer = new OutputStreamWriter(os);
|
||||
|
||||
template = configuration.getTemplate(templateName);
|
||||
|
||||
switch (type) {
|
||||
case REGATTA:
|
||||
template.process(regatta, writer);
|
||||
break;
|
||||
|
||||
case BOAT:
|
||||
template.process(race, writer);
|
||||
break;
|
||||
|
||||
case RACE:
|
||||
template.process(race, writer);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
try {
|
||||
return os.toString("UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
System.out.println("[FATAL] UTF-8 Not supported");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the race regatta as a string
|
||||
* Note: Regatta must be set before calling this
|
||||
* @return String containing the regatta XML, null if there was an error
|
||||
*/
|
||||
public String getRegattaAsXml(){
|
||||
String result = null;
|
||||
|
||||
if (regatta == null) return null;
|
||||
|
||||
try {
|
||||
result = parseToXmlString(REGATTA_TEMPLATE_NAME, XMLMessageSubType.REGATTA);
|
||||
} catch (TemplateException e) {
|
||||
System.out.println("[FATAL] Error parsing regatta");
|
||||
} catch (IOException e) {
|
||||
System.out.println("[FATAL] Error reading regatta");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the boats XML as a string
|
||||
* Note: Race must be set before calling this
|
||||
* @return String containing the boats XML, null if there was an error
|
||||
*/
|
||||
public String getBoatsAsXml() {
|
||||
String result = null;
|
||||
|
||||
if (race == null) return null;
|
||||
|
||||
try {
|
||||
result = parseToXmlString(BOATS_TEMPLATE_NAME, XMLMessageSubType.BOAT);
|
||||
} catch (TemplateException e) {
|
||||
System.out.println("[FATAL] Error parsing boats");
|
||||
} catch (IOException e) {
|
||||
System.out.println("[FATAL] Error reading boats");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the race XML as a string
|
||||
* Note: Race must be set before calling this
|
||||
* @return String containing the race XML, null if there was an error
|
||||
*/
|
||||
public String getRaceAsXml() {
|
||||
String result = null;
|
||||
|
||||
if (race == null) return null;
|
||||
|
||||
try {
|
||||
result = parseToXmlString(RACE_TEMPLATE_NAME, XMLMessageSubType.RACE);
|
||||
} catch (TemplateException e) {
|
||||
System.out.println("[FATAL] Error parsing race");
|
||||
} catch (IOException e) {
|
||||
System.out.println("[FATAL] Error reading race");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package seng302.model.stream.parsers.xml;
|
||||
package seng302.model.stream.xml.parser;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package seng302.model.stream.parsers.xml;
|
||||
package seng302.model.stream.xml.parser;
|
||||
|
||||
/**
|
||||
* Stores data from regatta xml packet.
|
||||
+7
-7
@@ -1,4 +1,4 @@
|
||||
package seng302.model.stream.parsers.xml;
|
||||
package seng302.model.stream.xml.parser;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -7,7 +7,7 @@ import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import seng302.model.Boat;
|
||||
import seng302.model.Yacht;
|
||||
import seng302.model.Corner;
|
||||
import seng302.model.Limit;
|
||||
import seng302.model.mark.GateMark;
|
||||
@@ -124,8 +124,8 @@ public class XMLParser {
|
||||
* @param doc XML Document Object
|
||||
* @return Mapping of sourceIds to Boats.
|
||||
*/
|
||||
public static Map<Integer, Boat> parseBoats(Document doc){
|
||||
Map<Integer, Boat> competingBoats = new HashMap<>();
|
||||
public static Map<Integer, Yacht> parseBoats(Document doc){
|
||||
Map<Integer, Yacht> competingBoats = new HashMap<>();
|
||||
|
||||
Element docEle = doc.getDocumentElement();
|
||||
|
||||
@@ -134,14 +134,14 @@ public class XMLParser {
|
||||
Node currentBoat = boatsList.item(i);
|
||||
if (currentBoat.getNodeName().equals("Boat")) {
|
||||
// Boat boat = new Boat(currentBoat);
|
||||
Boat boat = new Boat(XMLParser.getNodeAttributeString(currentBoat, "Type"),
|
||||
Yacht yacht = new Yacht(XMLParser.getNodeAttributeString(currentBoat, "Type"),
|
||||
XMLParser.getNodeAttributeInt(currentBoat, "SourceID"),
|
||||
XMLParser.getNodeAttributeString(currentBoat, "HullNum"),
|
||||
XMLParser.getNodeAttributeString(currentBoat, "ShortName"),
|
||||
XMLParser.getNodeAttributeString(currentBoat, "BoatName"),
|
||||
XMLParser.getNodeAttributeString(currentBoat, "Country"));
|
||||
if (boat.getBoatType().equals("Yacht")) {
|
||||
competingBoats.put(boat.getSourceID(), boat);
|
||||
if (yacht.getBoatType().equals("Yacht")) {
|
||||
competingBoats.put(yacht.getSourceId(), yacht);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user