Participants can now join during the warning period as well.
Added RaceDataSourceToXML. RaceServer now create an XMLMessage when the race's RaceDataSource changes. #story[1188]
This commit is contained in:
@@ -22,4 +22,16 @@ public interface BoatDataSource {
|
||||
* @return Map between source ID and mark.
|
||||
*/
|
||||
Map<Integer, Mark> getMarkerBoats();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the sequence number associated with this data source. Used to indicate when it has changed.
|
||||
* @return Sequence number.
|
||||
*/
|
||||
int getSequenceNumber();
|
||||
|
||||
/**
|
||||
* Increments the sequence number for this data source. Used to indicate that it has changed.
|
||||
*/
|
||||
void incrementSequenceNumber();
|
||||
}
|
||||
|
||||
@@ -29,6 +29,8 @@ public class BoatXMLReader extends XMLReader implements BoatDataSource {
|
||||
private final Map<Integer, Mark> markerMap = new HashMap<>();
|
||||
|
||||
|
||||
private int sequenceNumber = 0;
|
||||
|
||||
/**
|
||||
* Constructor for Boat XML using a file.
|
||||
*
|
||||
@@ -174,4 +176,15 @@ public class BoatXMLReader extends XMLReader implements BoatDataSource {
|
||||
public Map<Integer, Mark> getMarkerBoats() {
|
||||
return markerMap;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getSequenceNumber() {
|
||||
return sequenceNumber;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void incrementSequenceNumber() {
|
||||
sequenceNumber++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@ public class EmptyBoatDataSource implements BoatDataSource {
|
||||
private final Map<Integer, Mark> markerMap = new HashMap<>();
|
||||
|
||||
|
||||
private int sequenceNumber = 0;
|
||||
|
||||
|
||||
public EmptyBoatDataSource() {
|
||||
}
|
||||
@@ -44,4 +46,15 @@ public class EmptyBoatDataSource implements BoatDataSource {
|
||||
public Map<Integer, Mark> getMarkerBoats() {
|
||||
return markerMap;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getSequenceNumber() {
|
||||
return sequenceNumber;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void incrementSequenceNumber() {
|
||||
sequenceNumber++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,10 @@ package shared.dataInput;
|
||||
|
||||
import network.Messages.Enums.RaceTypeEnum;
|
||||
import shared.model.CompoundMark;
|
||||
import shared.model.Corner;
|
||||
import shared.model.GPSCoordinate;
|
||||
import shared.model.Leg;
|
||||
import shared.xml.Race.XMLCorner;
|
||||
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.ArrayList;
|
||||
@@ -48,6 +50,12 @@ public class EmptyRaceDataSource implements RaceDataSource {
|
||||
*/
|
||||
private final List<Leg> legs = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Corners in race.
|
||||
*/
|
||||
private final List<Corner> corners = new ArrayList<>();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The time that the race.xml file was created.
|
||||
@@ -100,6 +108,11 @@ public class EmptyRaceDataSource implements RaceDataSource {
|
||||
return legs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Corner> getCorners() {
|
||||
return corners;
|
||||
}
|
||||
|
||||
public List<CompoundMark> getCompoundMarks() {
|
||||
return new ArrayList<>(compoundMarkMap.values());
|
||||
}
|
||||
|
||||
@@ -60,6 +60,8 @@ public class EmptyRegattaDataSource implements RegattaDataSource {
|
||||
|
||||
|
||||
|
||||
private int sequenceNumber = 0;
|
||||
|
||||
|
||||
public EmptyRegattaDataSource() {
|
||||
}
|
||||
@@ -119,4 +121,15 @@ public class EmptyRegattaDataSource implements RegattaDataSource {
|
||||
public GPSCoordinate getGPSCoordinate() {
|
||||
return new GPSCoordinate(centralLatitude, centralLongitude);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getSequenceNumber() {
|
||||
return sequenceNumber;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void incrementSequenceNumber() {
|
||||
sequenceNumber++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,10 @@ package shared.dataInput;
|
||||
|
||||
import network.Messages.Enums.RaceTypeEnum;
|
||||
import shared.model.CompoundMark;
|
||||
import shared.model.Corner;
|
||||
import shared.model.GPSCoordinate;
|
||||
import shared.model.Leg;
|
||||
import shared.xml.Race.XMLCorner;
|
||||
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.List;
|
||||
@@ -27,6 +29,12 @@ public interface RaceDataSource {
|
||||
*/
|
||||
List<Leg> getLegs();
|
||||
|
||||
/**
|
||||
* Returns the list of corners in the race - two adjacent corners form a leg.
|
||||
* @return List of corners in race.
|
||||
*/
|
||||
List<Corner> getCorners();
|
||||
|
||||
/**
|
||||
* Returns a list of coordinates representing the boundary of the race.
|
||||
* @return The boundary of the race.
|
||||
|
||||
@@ -345,7 +345,7 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
|
||||
|
||||
int cornerSeq = Integer.parseInt(getAttribute(cornerElement, "SeqID"));
|
||||
|
||||
cornersList.add(new Corner(cornerID, cornerSeq, "SP", 3));
|
||||
cornersList.add(new Corner(cornerID, cornerSeq, cornerRounding, 3));
|
||||
|
||||
//Gets the CompoundMark associated with this corner.
|
||||
CompoundMark lastCompoundMark = this.compoundMarkMap.get(cornerID);
|
||||
@@ -368,7 +368,7 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
|
||||
|
||||
cornerSeq = Integer.parseInt(getAttribute(cornerElement, "SeqID"));
|
||||
|
||||
cornersList.add(new Corner(cornerID, cornerSeq, "Port", 3));
|
||||
cornersList.add(new Corner(cornerID, cornerSeq, getCompoundMarkRounding(cornerElement), 3));
|
||||
//gets the Rounding of this corner element
|
||||
cornerRounding = getCompoundMarkRounding(cornerElement);
|
||||
|
||||
@@ -490,7 +490,7 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
|
||||
return participants;
|
||||
}
|
||||
|
||||
public List<Corner> getCornersList() {
|
||||
public List<Corner> getCorners() {
|
||||
return cornersList;
|
||||
}
|
||||
|
||||
|
||||
@@ -66,5 +66,15 @@ public interface RegattaDataSource {
|
||||
float getMagneticVariation();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the sequence number associated with this data source. Used to indicate when it has changed.
|
||||
* @return Sequence number.
|
||||
*/
|
||||
int getSequenceNumber();
|
||||
|
||||
/**
|
||||
* Increments the sequence number for this data source. Used to indicate that it has changed.
|
||||
*/
|
||||
void incrementSequenceNumber();
|
||||
|
||||
}
|
||||
|
||||
@@ -59,6 +59,8 @@ public class RegattaXMLReader extends XMLReader implements RegattaDataSource {
|
||||
private float magneticVariation;
|
||||
|
||||
|
||||
private int sequenceNumber = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor for Regatta XML using a file.
|
||||
@@ -209,4 +211,14 @@ public class RegattaXMLReader extends XMLReader implements RegattaDataSource {
|
||||
public GPSCoordinate getGPSCoordinate() {
|
||||
return new GPSCoordinate(centralLatitude, centralLongitude);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSequenceNumber() {
|
||||
return sequenceNumber;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void incrementSequenceNumber() {
|
||||
sequenceNumber++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,4 +46,19 @@ public enum RoundingType {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getStringOf(RoundingType value) {
|
||||
switch (value) {
|
||||
case Port:
|
||||
return "Port";
|
||||
case Starboard:
|
||||
return "Starboard";
|
||||
case SP:
|
||||
return "SP";
|
||||
case PS:
|
||||
return "PS";
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
package shared.xml.Race;
|
||||
|
||||
import shared.dataInput.RaceDataSource;
|
||||
import shared.enums.RoundingType;
|
||||
import shared.model.CompoundMark;
|
||||
import shared.model.Corner;
|
||||
import shared.model.GPSCoordinate;
|
||||
import shared.model.Leg;
|
||||
import shared.xml.XMLUtilities;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Has functions to convert a {@link shared.dataInput.RaceDataSource} to an {@link XMLRace} object.
|
||||
*/
|
||||
public class RaceDataSourceToXML {
|
||||
|
||||
|
||||
/**
|
||||
* Converts a race data source to an XMLRace object.
|
||||
* @param raceDataSource The data source to convert.
|
||||
* @return The XMLRace file.
|
||||
*/
|
||||
public static XMLRace toXML(RaceDataSource raceDataSource) {
|
||||
|
||||
//Kind of ugly. Could be refactored/split up a bit.
|
||||
|
||||
|
||||
XMLRace race = new XMLRace();
|
||||
|
||||
|
||||
race.setRaceID(raceDataSource.getRaceId());
|
||||
race.setRaceType(raceDataSource.getRaceType().toString());
|
||||
|
||||
|
||||
race.setCreationTimeDate(raceDataSource.getCreationDateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssZ")));
|
||||
|
||||
|
||||
XMLRaceStartTime startTime = new XMLRaceStartTime();
|
||||
startTime.setPostpone(String.valueOf(raceDataSource.getPostponed()));
|
||||
startTime.setTime(raceDataSource.getStartDateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssZ")));
|
||||
race.setRaceStartTime(startTime);
|
||||
|
||||
|
||||
XMLParticipants participants = new XMLParticipants();
|
||||
participants.yacht = new ArrayList<>();
|
||||
for (int i : raceDataSource.getParticipants()) {
|
||||
XMLYacht yacht = new XMLYacht();
|
||||
yacht.setSourceID(i);
|
||||
participants.yacht.add(yacht);
|
||||
}
|
||||
race.setParticipants(participants);
|
||||
|
||||
|
||||
XMLCourseLimit courseLimit = new XMLCourseLimit();
|
||||
courseLimit.limit = new ArrayList<>();
|
||||
for (int i = 0; i < raceDataSource.getBoundary().size(); i++) {
|
||||
XMLLimit limit = new XMLLimit();
|
||||
limit.setLat(raceDataSource.getBoundary().get(i).getLatitude());
|
||||
limit.setLon(raceDataSource.getBoundary().get(i).getLongitude());
|
||||
limit.setSeqID(i + 1);
|
||||
courseLimit.limit.add(limit);
|
||||
}
|
||||
race.setCourseLimit(courseLimit);
|
||||
|
||||
|
||||
XMLCourse course = new XMLCourse();
|
||||
course.compoundMark = new ArrayList<>();
|
||||
for (CompoundMark compoundMark : raceDataSource.getCompoundMarks()) {
|
||||
XMLCompoundMark xmlCompoundMark = new XMLCompoundMark();
|
||||
xmlCompoundMark.setCompoundMarkID(compoundMark.getCompoundMarkID());
|
||||
xmlCompoundMark.setName(compoundMark.getName());
|
||||
|
||||
if (compoundMark.getMark1() != null) {
|
||||
XMLMark xmlMark = new XMLMark();
|
||||
xmlMark.setName(compoundMark.getMark1().getName());
|
||||
xmlMark.setSourceID(compoundMark.getMark1().getSourceID());
|
||||
xmlMark.setSeqId(1);
|
||||
xmlMark.setTargetLat(compoundMark.getMark1().getPosition().getLatitude());
|
||||
xmlMark.setTargetLng(compoundMark.getMark1().getPosition().getLongitude());
|
||||
|
||||
xmlCompoundMark.getMark().add(xmlMark);
|
||||
}
|
||||
if (compoundMark.getMark2() != null) {
|
||||
XMLMark xmlMark = new XMLMark();
|
||||
xmlMark.setName(compoundMark.getMark2().getName());
|
||||
xmlMark.setSourceID(compoundMark.getMark2().getSourceID());
|
||||
xmlMark.setSeqId(2);
|
||||
xmlMark.setTargetLat(compoundMark.getMark2().getPosition().getLatitude());
|
||||
xmlMark.setTargetLng(compoundMark.getMark2().getPosition().getLongitude());
|
||||
|
||||
xmlCompoundMark.getMark().add(xmlMark);
|
||||
}
|
||||
|
||||
course.compoundMark.add(xmlCompoundMark);
|
||||
}
|
||||
race.setCourse(course);
|
||||
|
||||
XMLCompoundMarkSequence compoundMarkSequence = new XMLCompoundMarkSequence();
|
||||
compoundMarkSequence.corner = new ArrayList<>();
|
||||
for (Corner corner : raceDataSource.getCorners()) {
|
||||
XMLCorner xmlCorner = new XMLCorner();
|
||||
xmlCorner.setZoneSize(corner.getZoneSize());
|
||||
xmlCorner.setSeqID(corner.getSeqID());
|
||||
xmlCorner.setCompoundMarkID(corner.getCompoundMarkID());
|
||||
xmlCorner.setRounding(corner.getRounding());
|
||||
|
||||
compoundMarkSequence.corner.add(xmlCorner);
|
||||
}
|
||||
race.setCompoundMarkSequence(compoundMarkSequence);
|
||||
|
||||
|
||||
return race;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Converts a race data source to an xml string.
|
||||
* @param raceDataSource Data source to convert.
|
||||
* @return String containing xml file.
|
||||
* @throws JAXBException Thrown if it cannot be converted.
|
||||
*/
|
||||
public static String toString(RaceDataSource raceDataSource) throws JAXBException {
|
||||
XMLRace race = toXML(raceDataSource);
|
||||
return XMLUtilities.classToXML(race);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user