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