Renamed some directories, optimized imports, general code clean up

#story[778]
This commit is contained in:
Erika Savell
2017-04-25 17:41:10 +12:00
parent 073102d1a3
commit 83dfe1a60c
111 changed files with 1614 additions and 1771 deletions
@@ -3,13 +3,11 @@ package seng302.Mock;
import javafx.scene.paint.Color;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import seng302.XMLReader;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.lang.annotation.ElementType;
import java.text.ParseException;
import java.util.*;
@@ -17,16 +15,17 @@ import java.util.*;
* Created by Joseph on 24/04/2017.
*/
public class BoatXMLReader extends XMLReader {
private static int currentColourIndex = 0;
Map<Integer, StreamedBoat> streamedBoatMap = new HashMap<>();
Map<Integer, StreamedBoat> participants = new HashMap<>();
private List<Color> colours;
private static int currentColourIndex = 0;
/**
* Constructor for Boat XML Reader
*
* @param filePath path of the file
* @throws IOException error
* @throws SAXException error
* @throws IOException error
* @throws SAXException error
* @throws ParserConfigurationException error
*/
public BoatXMLReader(String filePath) throws IOException, SAXException, ParserConfigurationException, ParseException {
@@ -36,10 +35,11 @@ public class BoatXMLReader extends XMLReader {
/**
* Constructor for Boat XML Reader
*
* @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
* @param read whether or not to read and store the files straight away.
* @throws IOException error
* @throws SAXException error
* @throws ParserConfigurationException error
*/
public BoatXMLReader(String filePath, boolean read) throws IOException, SAXException, ParserConfigurationException, ParseException {
@@ -98,7 +98,8 @@ public class BoatXMLReader extends XMLReader {
String shortName = null;
String country = null;
if (exists(boat, "Type")) type = boat.getAttributes().getNamedItem("Type").getTextContent();
if (exists(boat, "SourceID")) sourceID = Integer.parseInt(boat.getAttributes().getNamedItem("SourceID").getTextContent());
if (exists(boat, "SourceID"))
sourceID = Integer.parseInt(boat.getAttributes().getNamedItem("SourceID").getTextContent());
if (exists(boat, "BoatName")) boatName = boat.getAttributes().getNamedItem("BoatName").getTextContent();
if (exists(boat, "ShortName")) shortName = boat.getAttributes().getNamedItem("ShortName").getTextContent();
if (exists(boat, "Country")) country = boat.getAttributes().getNamedItem("Country").getTextContent();
@@ -3,7 +3,6 @@ package seng302.Mock;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import seng302.RaceDataSource;
import seng302.XMLReader;
import javax.xml.parsers.ParserConfigurationException;
@@ -17,9 +16,10 @@ public class RegattaXMLReader extends XMLReader {
/**
* Constructor for Regatta XML
*
* @param filePath path of the file
* @throws IOException error
* @throws SAXException error
* @throws IOException error
* @throws SAXException error
* @throws ParserConfigurationException error
*/
public RegattaXMLReader(String filePath) throws IOException, SAXException, ParserConfigurationException {
@@ -28,10 +28,11 @@ public class RegattaXMLReader extends XMLReader {
/**
* 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
* @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 {
@@ -1,8 +1,6 @@
package seng302.Mock;
import javafx.scene.paint.Color;
import seng302.GPSCoordinate;
import seng302.Model.Boat;
import seng302.Model.BoatInRace;
/**
@@ -27,8 +25,9 @@ public class StreamedBoat extends BoatInRace {
/**
* Overridden to ignore this function
* @deprecated
*
* @return 0
* @deprecated
*/
public double getScaledVelocity() {
return 0;
@@ -36,8 +35,9 @@ public class StreamedBoat extends BoatInRace {
/**
* Overridden to ignore this function
* @deprecated
*
* @param velocity of boat
* @deprecated
*/
public void setScaledVelocity(double velocity) {
}
@@ -7,7 +7,8 @@ import seng302.Model.RaceClock;
import seng302.RaceDataSource;
import java.time.ZonedDateTime;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
/**
* Created by jjg64 on 21/04/17.
@@ -42,14 +43,14 @@ public class StreamedCourse implements RaceDataSource {
}
}
public void setRegattaXMLReader(RegattaXMLReader regattaXMLReader) {
this.regattaXMLReader = regattaXMLReader;
}
public RegattaXMLReader getRegattaXMLReader() {
return regattaXMLReader;
}
public void setRegattaXMLReader(RegattaXMLReader regattaXMLReader) {
this.regattaXMLReader = regattaXMLReader;
}
public List<BoatInRace> getBoats() {
return new ArrayList<>(boatXMLReader.getStreamedBoatMap().values());
}
@@ -22,22 +22,23 @@ import java.util.*;
*/
public class StreamedCourseXMLReader extends XMLReader {
private static double COORDINATEPADDING = 0.0005;
private GPSCoordinate mapTopLeft, mapBottomRight;
private List<GPSCoordinate> boundary = new ArrayList<>();
private Map<Integer,Element> marks = new HashMap<>();
private Map<Integer, StreamedBoat> participants = new HashMap<>();
private List<Leg> legs = new ArrayList<>();
Date creationTimeDate;
Date raceStartTime;
int raceID;
String raceType;
boolean postpone;
private GPSCoordinate mapTopLeft, mapBottomRight;
private List<GPSCoordinate> boundary = new ArrayList<>();
private Map<Integer, Element> marks = new HashMap<>();
private Map<Integer, StreamedBoat> participants = new HashMap<>();
private List<Leg> legs = new ArrayList<>();
/**
* Constructor for Streamed Race XML
*
* @param filePath path of the file
* @throws IOException error
* @throws SAXException error
* @throws IOException error
* @throws SAXException error
* @throws ParserConfigurationException error
*/
public StreamedCourseXMLReader(String filePath) throws IOException, SAXException, ParserConfigurationException, ParseException, StreamedCourseXMLException {
@@ -46,10 +47,11 @@ public class StreamedCourseXMLReader extends XMLReader {
/**
* Constructor for Streamed Race 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
* @param read whether or not to read and store the files straight away.
* @throws IOException error
* @throws SAXException error
* @throws ParserConfigurationException error
*/
public StreamedCourseXMLReader(String filePath, boolean read) throws IOException, SAXException, ParserConfigurationException, ParseException, StreamedCourseXMLException {
@@ -102,16 +104,17 @@ public class StreamedCourseXMLReader extends XMLReader {
*/
private void readCompoundMarks() {
Element nCourse = (Element) doc.getElementsByTagName("Course").item(0);
for(int i = 0; i < nCourse.getChildNodes().getLength(); i++) {
for (int i = 0; i < nCourse.getChildNodes().getLength(); i++) {
Node compoundMark = nCourse.getChildNodes().item(i);
if(compoundMark.getNodeName().equals("CompoundMark")) {
marks.put(getCompoundMarkID((Element)compoundMark),(Element)compoundMark);
if (compoundMark.getNodeName().equals("CompoundMark")) {
marks.put(getCompoundMarkID((Element) compoundMark), (Element) compoundMark);
}
}
}
/**
* Generates a Marker from the CompoundMark element with given ID.
*
* @param compoundMarkID index of required CompoundMark element
* @return generated Marker
* @throws StreamedCourseXMLException if CompoundMark element contains unhandled number of marks
@@ -122,10 +125,15 @@ public class StreamedCourseXMLReader extends XMLReader {
NodeList nMarks = compoundMark.getElementsByTagName("Mark");
Marker marker;
switch(nMarks.getLength()) {
case 1: marker = new Marker(getCoordinate((Element)nMarks.item(0))); break;
case 2: marker = new Marker(getCoordinate((Element)nMarks.item(0)), getCoordinate((Element)nMarks.item(1))); break;
default: throw new StreamedCourseXMLException();
switch (nMarks.getLength()) {
case 1:
marker = new Marker(getCoordinate((Element) nMarks.item(0)));
break;
case 2:
marker = new Marker(getCoordinate((Element) nMarks.item(0)), getCoordinate((Element) nMarks.item(1)));
break;
default:
throw new StreamedCourseXMLException();
}
return marker;
@@ -134,11 +142,12 @@ public class StreamedCourseXMLReader extends XMLReader {
private GPSCoordinate getCoordinate(Element mark) {
double lat = Double.parseDouble(mark.getAttribute("TargetLat"));
double lon = Double.parseDouble(mark.getAttribute("TargetLng"));
return new GPSCoordinate(lat,lon);
return new GPSCoordinate(lat, lon);
}
/**
* Reads "compoundMarkID" attribute of CompoundMark or Corner element
*
* @param element with "compoundMarkID" attribute
* @return value of "compoundMarkID" attribute
*/
@@ -148,6 +157,7 @@ public class StreamedCourseXMLReader extends XMLReader {
/**
* Reads "name" attribute of CompoundMark element with corresponding CompoundMarkID
*
* @param compoundMarkID unique ID for CompoundMark element
* @return value of "name" attribute
*/
@@ -157,17 +167,18 @@ public class StreamedCourseXMLReader extends XMLReader {
/**
* Populates list of legs given CompoundMarkSequence element and referenced CompoundMark elements.
*
* @throws StreamedCourseXMLException if markers cannot be resolved from CompoundMark
*/
private void readCompoundMarkSequence() throws StreamedCourseXMLException {
Element nCompoundMarkSequence = (Element) doc.getElementsByTagName("CompoundMarkSequence").item(0);
NodeList nCorners = nCompoundMarkSequence.getElementsByTagName("Corner");
Marker lastMarker = getMarker(getCompoundMarkID((Element)nCorners.item(0)));
String legName = getCompoundMarkName(getCompoundMarkID((Element)nCorners.item(0)));
for(int i = 1; i < nCorners.getLength(); i++) {
Element markXML = (Element)nCorners.item(i);
Marker lastMarker = getMarker(getCompoundMarkID((Element) nCorners.item(0)));
String legName = getCompoundMarkName(getCompoundMarkID((Element) nCorners.item(0)));
for (int i = 1; i < nCorners.getLength(); i++) {
Element markXML = (Element) nCorners.item(i);
Marker currentMarker = getMarker(getCompoundMarkID(markXML));
legs.add(new Leg(legName, lastMarker, currentMarker, i-1));
legs.add(new Leg(legName, lastMarker, currentMarker, i - 1));
lastMarker = currentMarker;
legName = getCompoundMarkName(getCompoundMarkID(markXML));
}
@@ -175,7 +186,7 @@ public class StreamedCourseXMLReader extends XMLReader {
private void readCourseLimit() {
Element nCourseLimit = (Element) doc.getElementsByTagName("CourseLimit").item(0);
for(int i = 0; i < nCourseLimit.getChildNodes().getLength(); i++) {
for (int i = 0; i < nCourseLimit.getChildNodes().getLength(); i++) {
Node limit = nCourseLimit.getChildNodes().item(i);
if (limit.getNodeName().equals("Limit")) {
double lat = Double.parseDouble(limit.getAttributes().getNamedItem("Lat").getTextContent());
@@ -1,14 +1,10 @@
package seng302.Mock;
import javafx.collections.FXCollections;
import seng302.Controllers.RaceController;
import seng302.Model.BoatInRace;
import seng302.Model.Leg;
import seng302.Model.Race;
import seng302.RaceDataSource;
import java.util.*;
/**
* Created by jjg64 on 21/04/17.
*/
@@ -26,6 +22,7 @@ public class StreamedRace extends Race {
/**
* Checks if the boat cannot finish the race
*
* @return True if boat cannot finish the race
*/
protected boolean doNotFinish() {
@@ -46,7 +43,7 @@ public class StreamedRace extends Race {
/**
* Updates the boat's gps coordinates
*
* @param boat to be updated
* @param boat to be updated
* @param millisecondsElapsed time since last update
*/
protected void updatePosition(BoatInRace boat, int millisecondsElapsed) {