- Also fixed all boats having ame velocity #story[881]main
parent
a35d9cbc5a
commit
fd036c1835
@ -1,11 +0,0 @@
|
|||||||
package seng302.DataInput;
|
|
||||||
|
|
||||||
|
|
||||||
import seng302.Model.Regatta;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by zwu18 on 25/04/17.
|
|
||||||
*/
|
|
||||||
public interface RegattaDataSource {
|
|
||||||
Regatta getRegatta();
|
|
||||||
}
|
|
||||||
@ -1,75 +0,0 @@
|
|||||||
package seng302.DataInput;
|
|
||||||
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
import org.w3c.dom.NodeList;
|
|
||||||
import org.xml.sax.SAXException;
|
|
||||||
import seng302.Model.Regatta;
|
|
||||||
|
|
||||||
|
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by jjg64 on 19/04/17.
|
|
||||||
*/
|
|
||||||
public class RegattaXMLReader extends XMLReader implements RegattaDataSource {
|
|
||||||
private Regatta regatta;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor for Regatta XML
|
|
||||||
*
|
|
||||||
* @param filePath path of the file
|
|
||||||
* @throws IOException error
|
|
||||||
* @throws SAXException error
|
|
||||||
* @throws ParserConfigurationException error
|
|
||||||
*/
|
|
||||||
public RegattaXMLReader(String filePath) throws IOException, SAXException, ParserConfigurationException {
|
|
||||||
this(filePath, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor for Regatta XML
|
|
||||||
*
|
|
||||||
* @param filePath file path to read
|
|
||||||
* @param read whether or not to read and store the files straight away.
|
|
||||||
* @throws IOException error
|
|
||||||
* @throws SAXException error
|
|
||||||
* @throws ParserConfigurationException error
|
|
||||||
*/
|
|
||||||
public RegattaXMLReader(String filePath, boolean read) throws IOException, SAXException, ParserConfigurationException {
|
|
||||||
super(filePath);
|
|
||||||
if (read) {
|
|
||||||
read();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Read the XML
|
|
||||||
*/
|
|
||||||
private void read() {
|
|
||||||
NodeList attributeConfig = doc.getElementsByTagName("RegattaConfig");
|
|
||||||
Element attributes = (Element) attributeConfig.item(0);
|
|
||||||
makeRegatta(attributes);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create new regatta
|
|
||||||
* @param attributes
|
|
||||||
*/
|
|
||||||
private void makeRegatta(Element attributes) {
|
|
||||||
int regattaID = Integer.parseInt(getTextValueOfNode(attributes, "RegattaID"));
|
|
||||||
String regattaName = getTextValueOfNode(attributes, "RegattaName");
|
|
||||||
String courseName = getTextValueOfNode(attributes, "CourseName");
|
|
||||||
double centralLatitude = Double.parseDouble(getTextValueOfNode(attributes, "CentralLatitude"));
|
|
||||||
double centralLongitude = Double.parseDouble(getTextValueOfNode(attributes, "CentralLongitude"));
|
|
||||||
double centralAltitude = Double.parseDouble(getTextValueOfNode(attributes, "CentralAltitude"));
|
|
||||||
float utcOffset = Float.parseFloat(getTextValueOfNode(attributes, "UtcOffset"));
|
|
||||||
float magneticVariation = Float.parseFloat(getTextValueOfNode(attributes, "MagneticVariation"));
|
|
||||||
|
|
||||||
regatta = new Regatta(regattaID, regattaName, courseName, centralLatitude, centralLongitude, centralAltitude, utcOffset, magneticVariation);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Regatta getRegatta() {
|
|
||||||
return regatta;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,17 +0,0 @@
|
|||||||
package seng302.Exceptions;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by f123 on 25-Apr-17.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An exception thrown when a Regatta.xml message cannot be generated and sent.
|
|
||||||
*/
|
|
||||||
public class InvalidRegattaDataException extends RuntimeException {
|
|
||||||
public InvalidRegattaDataException() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public InvalidRegattaDataException(String message) {
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,99 +0,0 @@
|
|||||||
package seng302.Model;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by jjg64 on 19/04/17.
|
|
||||||
*/
|
|
||||||
public class Regatta {
|
|
||||||
int regattaID;
|
|
||||||
String RegattaName;
|
|
||||||
int raceID = 0;
|
|
||||||
String courseName;
|
|
||||||
double centralLatitude;
|
|
||||||
double centralLongitude;
|
|
||||||
double centralAltitude;
|
|
||||||
float utcOffset;
|
|
||||||
float magneticVariation;
|
|
||||||
|
|
||||||
public Regatta(int regattaID, String regattaName, String courseName, double centralLatitude, double centralLongitude, double centralAltitude, float utcOffset, float magneticVariation) {
|
|
||||||
this.regattaID = regattaID;
|
|
||||||
this.RegattaName = regattaName;
|
|
||||||
this.courseName = courseName;
|
|
||||||
this.centralLatitude = centralLatitude;
|
|
||||||
this.centralLongitude = centralLongitude;
|
|
||||||
this.centralAltitude = centralAltitude;
|
|
||||||
this.utcOffset = utcOffset;
|
|
||||||
this.magneticVariation = magneticVariation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getRegattaID() {
|
|
||||||
return regattaID;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRegattaID(int ID) {
|
|
||||||
this.regattaID = ID;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getRegattaName() {
|
|
||||||
return RegattaName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRegattaName(String regattaName) {
|
|
||||||
RegattaName = regattaName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getRaceID() {
|
|
||||||
return raceID;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRaceID(int raceID) {
|
|
||||||
this.raceID = raceID;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCourseName() {
|
|
||||||
return courseName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCourseName(String courseName) {
|
|
||||||
this.courseName = courseName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getCentralLatitude() {
|
|
||||||
return centralLatitude;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCentralLatitude(double centralLatitude) {
|
|
||||||
this.centralLatitude = centralLatitude;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getCentralLongitude() {
|
|
||||||
return centralLongitude;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCentralLongitude(double centralLongitude) {
|
|
||||||
this.centralLongitude = centralLongitude;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getCentralAltitude() {
|
|
||||||
return centralAltitude;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCentralAltitude(double centralAltitude) {
|
|
||||||
this.centralAltitude = centralAltitude;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getUtcOffset() {
|
|
||||||
return utcOffset;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUtcOffset(float utcOffset) {
|
|
||||||
this.utcOffset = utcOffset;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getMagneticVariation() {
|
|
||||||
return magneticVariation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMagneticVariation(float magneticVariation) {
|
|
||||||
this.magneticVariation = magneticVariation;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,286 +0,0 @@
|
|||||||
<race>
|
|
||||||
<raceId>5326</raceId>
|
|
||||||
<boats>
|
|
||||||
<boat>
|
|
||||||
<name>Team ORACLE USA</name>
|
|
||||||
<speed>20</speed>
|
|
||||||
<abbr>USA</abbr>
|
|
||||||
<sourceID>121</sourceID>
|
|
||||||
<colour>BLUEVIOLET</colour>
|
|
||||||
</boat>
|
|
||||||
<boat>
|
|
||||||
<name>Land Rover BAR</name>
|
|
||||||
<speed>30</speed>
|
|
||||||
<abbr>GBR</abbr>
|
|
||||||
<sourceID>122</sourceID>
|
|
||||||
<colour>BLACK</colour>
|
|
||||||
</boat>
|
|
||||||
<boat>
|
|
||||||
<name>SoftBank Team Japan</name>
|
|
||||||
<speed>25</speed>
|
|
||||||
<abbr>JPN</abbr>
|
|
||||||
<sourceID>123</sourceID>
|
|
||||||
<colour>RED</colour>
|
|
||||||
</boat>
|
|
||||||
<boat>
|
|
||||||
<name>Groupama Team France</name>
|
|
||||||
<speed>20</speed>
|
|
||||||
<abbr>FRA</abbr>
|
|
||||||
<sourceID>124</sourceID>
|
|
||||||
<colour>ORANGE</colour>
|
|
||||||
</boat>
|
|
||||||
<boat>
|
|
||||||
<name>Artemis Racing</name>
|
|
||||||
<speed>29</speed>
|
|
||||||
<abbr>SWE</abbr>
|
|
||||||
<sourceID>125</sourceID>
|
|
||||||
<colour>DARKOLIVEGREEN</colour>
|
|
||||||
</boat>
|
|
||||||
<boat>
|
|
||||||
<name>Emirates Team New Zealand</name>
|
|
||||||
<speed>62</speed>
|
|
||||||
<abbr>NZL</abbr>
|
|
||||||
<sourceID>126</sourceID>
|
|
||||||
<colour>LIMEGREEN</colour>
|
|
||||||
</boat>
|
|
||||||
</boats>
|
|
||||||
<legs>
|
|
||||||
<leg>
|
|
||||||
<name>Start to Mark 1</name>
|
|
||||||
<start>
|
|
||||||
<compoundMark>
|
|
||||||
<coordinate>
|
|
||||||
<latitude>32.296577</latitude>
|
|
||||||
<longitude>-64.854304</longitude>
|
|
||||||
</coordinate>
|
|
||||||
<coordinate>
|
|
||||||
<latitude>32.293771</latitude>
|
|
||||||
<longitude>-64.855242</longitude>
|
|
||||||
</coordinate>
|
|
||||||
</compoundMark>
|
|
||||||
</start>
|
|
||||||
<finish>
|
|
||||||
<compoundMark>
|
|
||||||
<coordinate>
|
|
||||||
<latitude>32.293039</latitude>
|
|
||||||
<longitude>-64.843983</longitude>
|
|
||||||
</coordinate>
|
|
||||||
</compoundMark>
|
|
||||||
</finish>
|
|
||||||
</leg>
|
|
||||||
<leg>
|
|
||||||
<name>Mark 1 to Leeward Gate</name>
|
|
||||||
<start>
|
|
||||||
<compoundMark>
|
|
||||||
<coordinate>
|
|
||||||
<latitude>32.293039</latitude>
|
|
||||||
<longitude>-64.843983</longitude>
|
|
||||||
</coordinate>
|
|
||||||
</compoundMark>
|
|
||||||
</start>
|
|
||||||
<finish>
|
|
||||||
<compoundMark>
|
|
||||||
<coordinate>
|
|
||||||
<latitude>32.309693</latitude>
|
|
||||||
<longitude>-64.835249</longitude>
|
|
||||||
</coordinate>
|
|
||||||
<coordinate>
|
|
||||||
<latitude>32.308046</latitude>
|
|
||||||
<longitude>-64.831785</longitude>
|
|
||||||
</coordinate>
|
|
||||||
</compoundMark>
|
|
||||||
</finish>
|
|
||||||
</leg>
|
|
||||||
<leg>
|
|
||||||
<name>Leeward Gate to Windward Gate</name>
|
|
||||||
<start>
|
|
||||||
<compoundMark>
|
|
||||||
<coordinate>
|
|
||||||
<latitude>32.309693</latitude>
|
|
||||||
<longitude>-64.835249</longitude>
|
|
||||||
</coordinate>
|
|
||||||
<coordinate>
|
|
||||||
<latitude>32.308046</latitude>
|
|
||||||
<longitude>-64.831785</longitude>
|
|
||||||
</coordinate>
|
|
||||||
</compoundMark>
|
|
||||||
</start>
|
|
||||||
<finish>
|
|
||||||
<compoundMark>
|
|
||||||
<coordinate>
|
|
||||||
<latitude>32.284680</latitude>
|
|
||||||
<longitude>-64.850045</longitude>
|
|
||||||
</coordinate>
|
|
||||||
<coordinate>
|
|
||||||
<latitude>32.280164</latitude>
|
|
||||||
<longitude>-64.847591</longitude>
|
|
||||||
</coordinate>
|
|
||||||
</compoundMark>
|
|
||||||
</finish>
|
|
||||||
</leg>
|
|
||||||
<leg>
|
|
||||||
<name>Windward Gate to Leeward Gate</name>
|
|
||||||
<start>
|
|
||||||
<compoundMark>
|
|
||||||
<coordinate>
|
|
||||||
<latitude>32.284680</latitude>
|
|
||||||
<longitude>-64.850045</longitude>
|
|
||||||
</coordinate>
|
|
||||||
<coordinate>
|
|
||||||
<latitude>32.280164</latitude>
|
|
||||||
<longitude>-64.847591</longitude>
|
|
||||||
</coordinate>
|
|
||||||
</compoundMark>
|
|
||||||
</start>
|
|
||||||
<finish>
|
|
||||||
<compoundMark>
|
|
||||||
<coordinate>
|
|
||||||
<latitude>32.309693</latitude>
|
|
||||||
<longitude>-64.835249</longitude>
|
|
||||||
</coordinate>
|
|
||||||
<coordinate>
|
|
||||||
<latitude>32.308046</latitude>
|
|
||||||
<longitude>-64.831785</longitude>
|
|
||||||
</coordinate>
|
|
||||||
</compoundMark>
|
|
||||||
</finish>
|
|
||||||
</leg>
|
|
||||||
<leg>
|
|
||||||
<name>Leeward Gate to Finish</name>
|
|
||||||
<start>
|
|
||||||
<compoundMark>
|
|
||||||
<coordinate>
|
|
||||||
<latitude>32.309693</latitude>
|
|
||||||
<longitude>-64.835249</longitude>
|
|
||||||
</coordinate>
|
|
||||||
<coordinate>
|
|
||||||
<latitude>32.308046</latitude>
|
|
||||||
<longitude>-64.831785</longitude>
|
|
||||||
</coordinate>
|
|
||||||
</compoundMark>
|
|
||||||
</start>
|
|
||||||
<finish>
|
|
||||||
<compoundMark>
|
|
||||||
<coordinate>
|
|
||||||
<latitude>32.317379</latitude>
|
|
||||||
<longitude>-64.839291</longitude>
|
|
||||||
</coordinate>
|
|
||||||
<coordinate>
|
|
||||||
<latitude>32.317257</latitude>
|
|
||||||
<longitude>-64.836260</longitude>
|
|
||||||
</coordinate>
|
|
||||||
</compoundMark>
|
|
||||||
</finish>
|
|
||||||
</leg>
|
|
||||||
</legs>
|
|
||||||
<course>
|
|
||||||
<boundaries>
|
|
||||||
<coordinate>
|
|
||||||
<latitude>32.313922</latitude>
|
|
||||||
<longitude>-64.837168</longitude>
|
|
||||||
</coordinate>
|
|
||||||
<coordinate>
|
|
||||||
<latitude>32.317379</latitude>
|
|
||||||
<longitude>-64.839291</longitude>
|
|
||||||
</coordinate>
|
|
||||||
<coordinate>
|
|
||||||
<latitude>32.317911</latitude>
|
|
||||||
<longitude>-64.836996</longitude>
|
|
||||||
</coordinate>
|
|
||||||
<coordinate>
|
|
||||||
<latitude>32.317257</latitude>
|
|
||||||
<longitude>-64.836260</longitude>
|
|
||||||
</coordinate>
|
|
||||||
<coordinate>
|
|
||||||
<latitude>32.304273</latitude>
|
|
||||||
<longitude>-64.822834</longitude>
|
|
||||||
</coordinate>
|
|
||||||
<coordinate>
|
|
||||||
<latitude>32.279097</latitude>
|
|
||||||
<longitude>-64.841545</longitude>
|
|
||||||
</coordinate>
|
|
||||||
<coordinate>
|
|
||||||
<latitude>32.279604</latitude>
|
|
||||||
<longitude>-64.849871</longitude>
|
|
||||||
</coordinate>
|
|
||||||
<coordinate>
|
|
||||||
<latitude>32.289545</latitude>
|
|
||||||
<longitude>-64.854162</longitude>
|
|
||||||
</coordinate>
|
|
||||||
<coordinate>
|
|
||||||
<latitude>32.290198</latitude>
|
|
||||||
<longitude>-64.858711</longitude>
|
|
||||||
</coordinate>
|
|
||||||
<coordinate>
|
|
||||||
<latitude>32.297164</latitude>
|
|
||||||
<longitude>-64.856394</longitude>
|
|
||||||
</coordinate>
|
|
||||||
<coordinate>
|
|
||||||
<latitude>32.296148</latitude>
|
|
||||||
<longitude>-64.849184</longitude>
|
|
||||||
</coordinate>
|
|
||||||
</boundaries>
|
|
||||||
<compoundMark>
|
|
||||||
<name>Start Line</name>
|
|
||||||
<coordinate>
|
|
||||||
<latitude>32.296577</latitude>
|
|
||||||
<longitude>-64.854304</longitude>
|
|
||||||
</coordinate>
|
|
||||||
<coordinate>
|
|
||||||
<latitude>32.293771</latitude>
|
|
||||||
<longitude>-64.855242</longitude>
|
|
||||||
</coordinate>
|
|
||||||
</compoundMark>
|
|
||||||
<compoundMark>
|
|
||||||
<name>Mark</name>
|
|
||||||
<coordinate>
|
|
||||||
<latitude>32.293039</latitude>
|
|
||||||
<longitude>-64.843983</longitude>
|
|
||||||
</coordinate>
|
|
||||||
</compoundMark>
|
|
||||||
<compoundMark>
|
|
||||||
<name>Windward Gate</name>
|
|
||||||
<coordinate>
|
|
||||||
<latitude>32.284680</latitude>
|
|
||||||
<longitude>-64.850045</longitude>
|
|
||||||
</coordinate>
|
|
||||||
<coordinate>
|
|
||||||
<latitude>32.280164</latitude>
|
|
||||||
<longitude>-64.847591</longitude>
|
|
||||||
</coordinate>
|
|
||||||
</compoundMark>
|
|
||||||
<compoundMark>
|
|
||||||
<name>Leeward Gate</name>
|
|
||||||
<coordinate>
|
|
||||||
<latitude>32.309693</latitude>
|
|
||||||
<longitude>-64.835249</longitude>
|
|
||||||
</coordinate>
|
|
||||||
<coordinate>
|
|
||||||
<latitude>32.308046</latitude>
|
|
||||||
<longitude>-64.831785</longitude>
|
|
||||||
</coordinate>
|
|
||||||
</compoundMark>
|
|
||||||
<compoundMark>
|
|
||||||
<name>Windward Gate</name>
|
|
||||||
<coordinate>
|
|
||||||
<latitude>32.284680</latitude>
|
|
||||||
<longitude>-64.850045</longitude>
|
|
||||||
</coordinate>
|
|
||||||
<coordinate>
|
|
||||||
<latitude>32.280164</latitude>
|
|
||||||
<longitude>-64.847591</longitude>
|
|
||||||
</coordinate>
|
|
||||||
</compoundMark>
|
|
||||||
<compoundMark>
|
|
||||||
<name>Finish Line</name>
|
|
||||||
<coordinate>
|
|
||||||
<latitude>32.317379</latitude>
|
|
||||||
<longitude>-64.839291</longitude>
|
|
||||||
</coordinate>
|
|
||||||
<coordinate>
|
|
||||||
<latitude>32.317257</latitude>
|
|
||||||
<longitude>-64.836260</longitude>
|
|
||||||
</coordinate>
|
|
||||||
</compoundMark>
|
|
||||||
</course>
|
|
||||||
</race>
|
|
||||||
@ -1,51 +0,0 @@
|
|||||||
package seng302.DataInput;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import seng302.Model.Regatta;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by jjg64 on 19/04/17.
|
|
||||||
*/
|
|
||||||
public class RegattaXMLTest {
|
|
||||||
RegattaXMLReader regattaXMLReader;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void findFile() {
|
|
||||||
try {
|
|
||||||
regattaXMLReader = new RegattaXMLReader("mockXML/regattaTest.xml", false);
|
|
||||||
} catch (Exception e) {
|
|
||||||
fail("Cannot find mockXML/regattaXML/regattaTest.xml in the resources folder");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void makeRegattaTest() {
|
|
||||||
try {
|
|
||||||
regattaXMLReader = new RegattaXMLReader("mockXML/regattaTest.xml");
|
|
||||||
assertNotEquals(regattaXMLReader.getRegatta(), null);
|
|
||||||
} catch (Exception e) {
|
|
||||||
fail("Did not make a Regatta object");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void correctValuesTest() {
|
|
||||||
try {
|
|
||||||
regattaXMLReader = new RegattaXMLReader("mockXML/regattaTest.xml");
|
|
||||||
Regatta regatta = regattaXMLReader.getRegatta();
|
|
||||||
assertEquals(regatta.getRegattaID(), 3);
|
|
||||||
assertEquals(regatta.getRegattaName(), "New Zealand Test");
|
|
||||||
assertEquals(regatta.getCourseName(), "North Head");
|
|
||||||
assertEquals(regatta.getCentralLatitude(), -36.82791529, 0.00000001);
|
|
||||||
assertEquals(regatta.getCentralLongitude(), 174.81218919, 0.00000001);
|
|
||||||
assertEquals(regatta.getCentralAltitude(), 0.00, 0.00000001);
|
|
||||||
assertEquals(regatta.getUtcOffset(), 12.0, 0.001);
|
|
||||||
assertEquals(regatta.getMagneticVariation(), 14.1, 0.001);
|
|
||||||
} catch (Exception e) {
|
|
||||||
fail("Did not have the correct values");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in new issue