Added documentation for multiple classes.
#Story[782]
This commit is contained in:
@@ -232,6 +232,11 @@ public class RaceData {
|
||||
rootElement.appendChild(courseLimitElement);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format time data and return it.
|
||||
* @param time time data.
|
||||
* @return formatted time data.
|
||||
*/
|
||||
private String toTruncatedString(ZonedDateTime time) {
|
||||
|
||||
DateTimeFormatter dateFormat = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
|
||||
|
||||
@@ -69,6 +69,9 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
|
||||
readBoats();
|
||||
}
|
||||
|
||||
/**
|
||||
* Read in race ID from XML object.
|
||||
*/
|
||||
public void readID() {
|
||||
NodeList race = doc.getElementsByTagName("race");
|
||||
raceID = Integer.parseInt(getTextValueOfNode((Element) race.item(0), "raceId"));
|
||||
|
||||
@@ -52,6 +52,10 @@ public class RegattaXMLReader extends XMLReader implements RegattaDataSource {
|
||||
makeRegatta(attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new regatta
|
||||
* @param attributes
|
||||
*/
|
||||
private void makeRegatta(Element attributes) {
|
||||
int regattaID = Integer.parseInt(getTextValueOfNode(attributes, "RegattaID"));
|
||||
String regattaName = getTextValueOfNode(attributes, "RegattaName");
|
||||
|
||||
@@ -17,6 +17,13 @@ public abstract class XMLReader {
|
||||
|
||||
protected Document doc;
|
||||
|
||||
/**
|
||||
* Read in XML file
|
||||
* @param filePath filepath for XML file
|
||||
* @throws ParserConfigurationException
|
||||
* @throws IOException
|
||||
* @throws SAXException
|
||||
*/
|
||||
public XMLReader(String filePath) throws ParserConfigurationException, IOException, SAXException {
|
||||
InputStream fXmlFile = getClass().getClassLoader().getResourceAsStream(filePath);
|
||||
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
|
||||
@@ -25,14 +32,30 @@ public abstract class XMLReader {
|
||||
doc.getDocumentElement().normalize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return Document data of the read-in XML
|
||||
* @return XML document
|
||||
*/
|
||||
public Document getDocument() {
|
||||
return doc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get content of a tag in an element
|
||||
* @param n Element to read tags from
|
||||
* @param tagName Name of the tag
|
||||
* @return Content of the tag
|
||||
*/
|
||||
public String getTextValueOfNode(Element n, String tagName) {
|
||||
return n.getElementsByTagName(tagName).item(0).getTextContent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get attributes for an element
|
||||
* @param n Element to read attributes from
|
||||
* @param attr Attributes of element
|
||||
* @return Attributes of element
|
||||
*/
|
||||
public String getAttribute(Element n, String attr) {
|
||||
return n.getAttribute(attr);
|
||||
}
|
||||
|
||||
@@ -57,6 +57,11 @@ public class MockOutput implements Runnable
|
||||
}
|
||||
|
||||
//returns the heartbeat message
|
||||
|
||||
/**
|
||||
* Increment the heartbeat value
|
||||
* @return message for heartbeat data
|
||||
*/
|
||||
private byte[] heartbeat(){
|
||||
byte[] heartbeatMessage = messageEncoder.heartBeat(heartbeatSequenceNum);
|
||||
heartbeatSequenceNum++;
|
||||
@@ -110,7 +115,10 @@ public class MockOutput implements Runnable
|
||||
addMessageToBufferToSend(binaryMessageEncoder.getFullMessage());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parse the race status data and add it to the buffer to be sent
|
||||
* @param raceStatus race status to parses
|
||||
*/
|
||||
public synchronized void parseRaceStatus(RaceStatus raceStatus){
|
||||
|
||||
//iterates the sequence number
|
||||
@@ -130,6 +138,10 @@ public class MockOutput implements Runnable
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a message to the buffer to be sent
|
||||
* @param messagesToSendBuffer message to add to the buffer
|
||||
*/
|
||||
private synchronized void addMessageToBufferToSend(byte[] messagesToSendBuffer) {
|
||||
this.messagesToSendBuffer.add(messagesToSendBuffer);
|
||||
}
|
||||
|
||||
@@ -51,6 +51,10 @@ public class Boat {
|
||||
return calc.getAzimuth();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the heding depending on the calculated azimuth value
|
||||
* @return The azimuth value which is greater than 0
|
||||
*/
|
||||
public double calculateHeading() {
|
||||
double azimuth = this.calculateAzimuth();
|
||||
|
||||
|
||||
@@ -34,20 +34,25 @@ public class Event {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the initial race data and then begin race simulation
|
||||
*/
|
||||
public void start() {
|
||||
|
||||
System.out.println("Sending Regatta");
|
||||
sendRegattaData();
|
||||
System.out.println("Sending Race");
|
||||
sendRaceData();
|
||||
System.out.println("Sending Boat");
|
||||
sendBoatData();
|
||||
|
||||
Race newRace = new Race(raceDataSource, 15, mockOutput);
|
||||
new Thread((newRace)).start();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Send XML string of initial regatta data to the visualiser
|
||||
* @throws InvalidRegattaDataException Invalid regatta
|
||||
*/
|
||||
public void sendRegattaData() throws InvalidRegattaDataException {
|
||||
|
||||
System.setOut(System.out);
|
||||
@@ -58,6 +63,10 @@ public class Event {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Send XML string of initial race data to the visualiser
|
||||
* @throws InvalidRaceDataException Invalid race
|
||||
*/
|
||||
public void sendRaceData() throws InvalidRaceDataException {
|
||||
RaceData raceData = new RaceData(raceDataSource);
|
||||
//Serialize race data to an XML as a string.
|
||||
@@ -66,6 +75,10 @@ public class Event {
|
||||
mockOutput.parseXMLString(xmlString, 26);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send XML string of initial boat data to the visualiser
|
||||
* @throws InvalidBoatDataException Invalid boat
|
||||
*/
|
||||
public void sendBoatData() throws InvalidBoatDataException {
|
||||
BoatData boatData = new BoatData(raceDataSource.getBoats());
|
||||
//Serialize race data to an XML as a string.
|
||||
|
||||
Reference in New Issue
Block a user