Updated the xml reader to pull in the rounding type of the compound marks and set each mark with that value

#story[1101]
main
hba56 8 years ago
parent f212414bd9
commit be8b0e672d

@ -5,6 +5,7 @@ import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import shared.enums.RoundingType;
import shared.enums.XMLFileType;
import shared.exceptions.InvalidRaceDataException;
import shared.exceptions.XMLReaderException;
@ -313,6 +314,8 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
return element.getAttribute("Name");
}
private String getCompoundMarkRounding(Element element){return element.getAttribute("Rounding");}
/**
* Populates list of legs given CompoundMarkSequence element and referenced CompoundMark elements.
@ -331,12 +334,18 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
//Gets the ID number of this corner element.
int cornerID = getCompoundMarkID(cornerElement);
//gets the Rounding of this corner element
String cornerRounding = getCompoundMarkRounding(cornerElement);
//Gets the CompoundMark associated with this corner.
CompoundMark lastCompoundMark = this.compoundMarkMap.get(cornerID);
//The name of the leg is the name of the first compoundMark in the leg.
String legName = lastCompoundMark.getName();
//Sets the rounding type of this compound mark
lastCompoundMark.setRoundingType(RoundingType.valueOf(cornerRounding));
//For each following corner, create a leg between cornerN and cornerN+1.
for(int i = 1; i < corners.getLength(); i++) {
@ -346,9 +355,15 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
//Gets the ID number of this corner element.
cornerID = getCompoundMarkID(cornerElement);
//gets the Rounding of this corner element
cornerRounding = getCompoundMarkRounding(cornerElement);
//Gets the CompoundMark associated with this corner.
CompoundMark currentCompoundMark = this.compoundMarkMap.get(cornerID);
//Sets the rounding type of this compound mark
currentCompoundMark.setRoundingType(RoundingType.valueOf(cornerRounding));
//Create a leg from these two adjacent compound marks.
Leg leg = new Leg(legName, lastCompoundMark, currentCompoundMark, i - 1);
legs.add(leg);

@ -0,0 +1,34 @@
package shared.enums;
/**
* Enum for the types of rounding that can be done
*/
public enum RoundingType {
/**
* This is means it must be rounded port side
*/
Port,
/**
* This is means it must be rounded starboard side
*/
Starboard,
/**
* The boat within the compound mark with the SeqID
* of 1 should be rounded to starboard and the boat
* within the compound mark with the SeqID of 2 should
* be rounded to port.
*/
SP,
/**
* The boat within the compound mark with the SeqID
* of 1 should be rounded to port and the boat
* within the compound mark with the SeqID of 2 should
* be rounded to starboard.
*
* opposite of SP
*/
PS;
}

@ -1,6 +1,8 @@
package shared.model;
import shared.enums.RoundingType;
/**
* Represents a compound mark - that is, either one or two individual marks which form a single compound mark.
*/
@ -31,6 +33,11 @@ public class CompoundMark {
*/
private GPSCoordinate averageGPSCoordinate;
/**
* The side that the mark must be rounded on
*/
private RoundingType roundingType;
/**
* Constructs a compound mark from a single mark.
@ -141,4 +148,20 @@ public class CompoundMark {
return averageCoordinate;
}
/**
* Used to get how this mark should be rounded
* @return rounding type for mark
*/
public RoundingType getRoundingType() {
return roundingType;
}
/**
* Used to set the type of rounding for this mark
* @param roundingType rounding type to set
*/
public void setRoundingType(RoundingType roundingType) {
this.roundingType = roundingType;
}
}

@ -22,7 +22,6 @@ public class Mark {
private GPSCoordinate position;
/**
* Constructs a mark with a given source ID, name, and position.
* @param sourceID The source ID of the mark.

Loading…
Cancel
Save