General code tidy up

- access modifiers adjusted
- unused declarations removed
- spelling fixes
- removed redundant code
main
Jessica McAuslin 9 years ago
parent e1ba2ae5b6
commit 2d983eccfd

@ -6,14 +6,10 @@ import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;
public class App extends Application {
Stage primaryStage;
BorderPane mainContainer;
Scene mainScene;
/**
* Entry point for running the programme

@ -13,8 +13,6 @@ import seng302.RaceConnection;
import java.io.IOException;
import java.net.Socket;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;
/**

@ -7,13 +7,9 @@ import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.layout.AnchorPane;
import seng302.Model.Boat;
import seng302.Model.Race;
import java.net.URL;
import java.util.ResourceBundle;
@ -41,7 +37,7 @@ public class FinishController extends Controller {
public void setFinishTable(ObservableList<Boat> boats){
private void setFinishTable(ObservableList<Boat> boats){
boatInfoTable.setItems(boats);
boatNameColumn.setCellValueFactory(cellData -> cellData.getValue().getName());
boatRankColumn.setCellValueFactory(cellData -> cellData.getValue().positionProperty());

@ -4,9 +4,7 @@ import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.layout.AnchorPane;
import seng302.Model.Boat;
import seng302.Model.BoatInRace;
import seng302.Model.RaceClock;
import seng302.RaceDataSource;
import seng302.VisualiserInput;
import java.net.Socket;
@ -17,14 +15,10 @@ import java.util.ResourceBundle;
* Created by fwy13 on 15/03/2017.
*/
public class MainController extends Controller {
@FXML
StartController startController;
@FXML
RaceController raceController;
@FXML
ConnectionController connectionController;
@FXML
FinishController finishController;
@FXML private StartController startController;
@FXML private RaceController raceController;
@FXML private ConnectionController connectionController;
@FXML private FinishController finishController;
public void beginRace(VisualiserInput visualiserInput, RaceClock raceClock) {
raceController.startRace(visualiserInput, raceClock);

@ -1,81 +1,46 @@
package seng302.Controllers;
import javafx.beans.property.ReadOnlyObjectWrapper;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.Node;
import javafx.scene.control.*;
import javafx.scene.layout.GridPane;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import seng302.Mock.StreamedRace;
import seng302.Model.*;
import seng302.RaceDataSource;
import seng302.RaceXMLReader;
import seng302.VisualiserInput;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.ResourceBundle;
/**
* Created by fwy13 on 15/03/2017.
*/
public class RaceController extends Controller {
@FXML
GridPane canvasBase;
@FXML GridPane canvasBase;
//user saved data for annotation display
private ArrayList<Boolean> presetAnno;
private ObservableList<Boat> startingBoats;
ResizableRaceCanvas raceMap;
ResizableRaceMap raceBoundaries;
@FXML
SplitPane race;
@FXML
CheckBox showFPS;
@FXML
CheckBox showBoatPath;
@FXML
CheckBox showAnnotations;
@FXML
Label timer;
@FXML
Label FPS;
@FXML
Label timeZone;
@FXML
CheckBox showName;
@FXML
CheckBox showAbbrev;
@FXML
CheckBox showSpeed;
@FXML
Button saveAnno;
@FXML
Button showSetAnno;
@FXML
TableView<Boat> boatInfoTable;
@FXML
TableColumn<Boat, String> boatPlacingColumn;
@FXML
TableColumn<Boat, String> boatTeamColumn;
@FXML
TableColumn<Boat, String> boatMarkColumn;
@FXML
TableColumn<Boat, String> boatSpeedColumn;
private ResizableRaceCanvas raceMap;
private ResizableRaceMap raceBoundaries;
@FXML SplitPane race;
@FXML CheckBox showFPS;
@FXML CheckBox showBoatPath;
@FXML CheckBox showAnnotations;
@FXML Label timer;
@FXML Label FPS;
@FXML Label timeZone;
@FXML CheckBox showName;
@FXML CheckBox showAbbrev;
@FXML CheckBox showSpeed;
@FXML Button saveAnno;
@FXML Button showSetAnno;
@FXML TableView<Boat> boatInfoTable;
@FXML TableColumn<Boat, String> boatPlacingColumn;
@FXML TableColumn<Boat, String> boatTeamColumn;
@FXML TableColumn<Boat, String> boatMarkColumn;
@FXML TableColumn<Boat, String> boatSpeedColumn;
/**
* Updates the ResizableRaceCanvas (raceMap) with most recent data
@ -97,7 +62,7 @@ public class RaceController extends Controller {
*/
public void setInfoTable(Race race) {
//boatInfoTable.getItems().clear();
startingBoats = race.getStartingBoats();
ObservableList<Boat> startingBoats = race.getStartingBoats();
boatInfoTable.setItems(race.getStartingBoats());
boatTeamColumn.setCellValueFactory(cellData -> cellData.getValue().getName());
boatSpeedColumn.setCellValueFactory(cellData -> cellData.getValue().getVelocityProp());

@ -5,14 +5,13 @@ import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.GridPane;
import seng302.Mock.*;
import seng302.Mock.StreamedCourse;
import seng302.Model.Boat;
import seng302.Model.RaceClock;
import seng302.VisualiserInput;
@ -20,12 +19,12 @@ import seng302.VisualiserInput;
import java.io.IOException;
import java.net.Socket;
import java.net.URL;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.List;
import java.util.Observable;
import java.util.Observer;
import java.util.ResourceBundle;
/**
* Created by esa46 on 6/04/17.
@ -56,12 +55,12 @@ public class StartController extends Controller implements Observer {
private VisualiserInput visualiserInput;
///Tracks whether the race has been started (that is, has startRaceNoScaling() be called).
boolean hasRaceStarted = false;
private boolean hasRaceStarted = false;
/**
* Begins the race with a scale factor of 1
*/
public void startRaceNoScaling() {
private void startRaceNoScaling() {
//startRace(1);
while(visualiserInput.getRaceStatus() == null);//TODO probably remove this.
@ -95,7 +94,7 @@ public class StartController extends Controller implements Observer {
/**
* Countdown timer until race starts.
*/
protected void countdownTimer() {
private void countdownTimer() {
new AnimationTimer() {
@Override
public void handle(long arg0) {
@ -151,7 +150,7 @@ public class StartController extends Controller implements Observer {
setRaceClock();
if(visualiserInput.getRaceStatus() == null){
return;//TEMP BUG FIX if the race isn't sending race status messages (our mock currently doesn't), then it would block the javafx thread with the previous while loop.
}; // TODO - replace with observer on VisualiserInput
}// TODO - replace with observer on VisualiserInput
setStartingTime();
setCurrentTime();
});
@ -163,7 +162,6 @@ public class StartController extends Controller implements Observer {
Platform.runLater(() -> {
if (!this.hasRaceStarted) {
if(visualiserInput.getRaceStatus() == null) {
return;//TEMP
}
else {
this.hasRaceStarted = true;

@ -6,8 +6,8 @@ package seng302;
*/
public class GPSCoordinate {
private double latitude;
private double longitude;
private final double latitude;
private final double longitude;
/**
* Constructor Method

@ -5,8 +5,8 @@ package seng302;
* Created by cbt24 on 15/03/17.
*/
public class GraphCoordinate {
private int x;
private int y;
private final int x;
private final int y;
/**
* Constructor method.

@ -1,10 +1,7 @@
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.InputSource;
import org.xml.sax.SAXException;
import seng302.Model.Boat;
import seng302.XMLReader;
@ -12,16 +9,18 @@ import seng302.XMLReader;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.io.InputStream;
import java.lang.annotation.ElementType;
import java.text.ParseException;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by Joseph on 24/04/2017.
*/
public class BoatXMLReader extends XMLReader {
Map<Integer, StreamedBoat> streamedBoatMap = new HashMap<>();
Map<Integer, StreamedBoat> participants = new HashMap<>();
private final Map<Integer, StreamedBoat> streamedBoatMap = new HashMap<>();
private Map<Integer, StreamedBoat> participants = new HashMap<>();
/**
* Constructor for Boat XML Reader
@ -31,7 +30,7 @@ public class BoatXMLReader extends XMLReader {
* @throws ParserConfigurationException error
* @throws ParseException error
*/
public BoatXMLReader(String filePath) throws IOException, SAXException, ParserConfigurationException, ParseException {
public BoatXMLReader(String filePath) throws IOException, SAXException, ParserConfigurationException {
this(filePath, true);
}
@ -44,7 +43,7 @@ public class BoatXMLReader extends XMLReader {
* @throws ParserConfigurationException error
* @throws ParseException error
*/
public BoatXMLReader(String filePath, boolean read) throws IOException, SAXException, ParserConfigurationException, ParseException {
public BoatXMLReader(String filePath, boolean read) throws IOException, SAXException, ParserConfigurationException {
super(filePath);
if (read) {
read();

@ -7,15 +7,15 @@ import seng302.GPSCoordinate;
* @deprecated use the RegattaXMLReader
*/
public class Regatta {
int regattaID;
String RegattaName;
int raceID = 0;
String courseName;
double centralLatitude;
double centralLongitude;
double centralAltitude;
float utcOffset;
float magneticVariation;
private int regattaID;
private String RegattaName;
private int raceID = 0;
private String courseName;
private double centralLatitude;
private double centralLongitude;
private double centralAltitude;
private float utcOffset;
private float magneticVariation;
public Regatta(int regattaID, String regattaName, String courseName, double centralLatitude, double centralLongitude, double centralAltitude, float utcOffset, float magneticVariation) {
this.regattaID = regattaID;

@ -2,7 +2,6 @@ package seng302.Mock;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import seng302.GPSCoordinate;
import seng302.XMLReader;
@ -16,15 +15,15 @@ import java.io.InputStream;
*/
public class RegattaXMLReader extends XMLReader {
private Regatta regatta;
int regattaID;
String regattaName;
int raceID = 0;
String courseName;
double centralLatitude;
double centralLongitude;
double centralAltitude;
float utcOffset;
float magneticVariation;
private int regattaID;
private String regattaName;
private int raceID = 0;
private String courseName;
private double centralLatitude;
private double centralLongitude;
private double centralAltitude;
private float utcOffset;
private float magneticVariation;
/**
* Constructor for Regatta XML
@ -47,7 +46,7 @@ public class RegattaXMLReader extends XMLReader {
* @throws SAXException error
* @throws ParserConfigurationException error
*/
public RegattaXMLReader(String filePath, boolean read) throws IOException, SAXException, ParserConfigurationException {
private RegattaXMLReader(String filePath, boolean read) throws IOException, SAXException, ParserConfigurationException {
super(filePath);
if (read) {
read();

@ -1,18 +1,12 @@
package seng302.Mock;
import javafx.scene.paint.Color;
import org.geotools.referencing.GeodeticCalculator;
import seng302.GPSCoordinate;
import seng302.Model.Boat;
import seng302.Model.BoatInRace;
import seng302.Model.Leg;
import seng302.Model.Marker;
/**
* Created by Joseph on 24/04/2017.
*/
public class StreamedBoat extends Boat {
private int sourceID;
private final int sourceID;
private boolean dnf = false;
private void init() {

@ -1,19 +1,22 @@
package seng302.Mock;
import seng302.GPSCoordinate;
import seng302.Model.*;
import seng302.Model.Boat;
import seng302.Model.Leg;
import seng302.Model.Marker;
import seng302.RaceDataSource;
import java.time.ZonedDateTime;
import java.util.*;
import java.util.List;
import java.util.Observable;
/**
* Created by jjg64 on 21/04/17.
*/
public class StreamedCourse extends Observable implements RaceDataSource {
StreamedCourseXMLReader streamedCourseXMLReader = null;
BoatXMLReader boatXMLReader = null;
RegattaXMLReader regattaXMLReader = null;
private StreamedCourseXMLReader streamedCourseXMLReader = null;
private BoatXMLReader boatXMLReader = null;
private RegattaXMLReader regattaXMLReader = null;
private double windDirection = 0;
public StreamedCourse() {}

@ -1,12 +1,9 @@
package seng302.Mock;
import com.sun.org.apache.xpath.internal.operations.Bool;
import org.joda.time.DateTime;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import seng302.GPSCoordinate;
import seng302.Model.Leg;
@ -16,9 +13,7 @@ import seng302.XMLReader;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.io.InputStream;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
@ -27,18 +22,18 @@ import java.util.*;
* Created by jjg64 on 21/04/17.
*/
public class StreamedCourseXMLReader extends XMLReader {
private static double COORDINATEPADDING = 0.000;
private static final double COORDINATEPADDING = 0.000;
private GPSCoordinate mapTopLeft, mapBottomRight;
private List<GPSCoordinate> boundary = new ArrayList<>();
private Map<Integer,Element> compoundMarks = new HashMap<>();
private Map<Integer, StreamedBoat> participants = new HashMap<>();
private List<Leg> legs = new ArrayList<>();
private List<Marker> markers = new ArrayList<>();
ZonedDateTime creationTimeDate;
ZonedDateTime raceStartTime;
int raceID;
String raceType;
boolean postpone;
private final List<GPSCoordinate> boundary = new ArrayList<>();
private final Map<Integer,Element> compoundMarks = new HashMap<>();
private final Map<Integer, StreamedBoat> participants = new HashMap<>();
private final List<Leg> legs = new ArrayList<>();
private final List<Marker> markers = new ArrayList<>();
private ZonedDateTime creationTimeDate;
private ZonedDateTime raceStartTime;
private int raceID;
private String raceType;
private boolean postpone;
/**
* Constructor for Streamed Race XML
@ -89,7 +84,7 @@ public class StreamedCourseXMLReader extends XMLReader {
* @throws ParseException error
* @throws StreamedCourseXMLException error
*/
private void read() throws ParseException, StreamedCourseXMLException {
private void read() throws StreamedCourseXMLException {
readRace();
readParticipants();
readCourse();
@ -99,7 +94,7 @@ public class StreamedCourseXMLReader extends XMLReader {
* reads a race
* @throws ParseException error
*/
private void readRace() throws ParseException {
private void readRace() {
DateTimeFormatter dateFormat = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
Element settings = (Element) doc.getElementsByTagName("Race").item(0);
NamedNodeMap raceTimeTag = doc.getElementsByTagName("RaceStartTime").item(0).getAttributes();

@ -6,8 +6,8 @@ import seng302.Model.Boat;
import seng302.Model.Leg;
import seng302.Model.Marker;
import seng302.Model.Race;
import seng302.Networking.Messages.BoatStatus;
import seng302.Networking.Messages.BoatLocation;
import seng302.Networking.Messages.BoatStatus;
import seng302.Networking.Messages.Enums.BoatStatusEnum;
import seng302.VisualiserInput;
@ -15,8 +15,7 @@ import seng302.VisualiserInput;
* Created by jjg64 on 21/04/17.
*/
public class StreamedRace extends Race {
private VisualiserInput visualiserInput;
private double MMPS_TO_KN = 0.001944;
private final VisualiserInput visualiserInput;
public StreamedRace(VisualiserInput visualiserInput, RaceController controller) {
super(visualiserInput.getCourse(), controller, 1);
@ -94,6 +93,7 @@ public class StreamedRace extends Race {
double lon = boatLocation.getLongitudeDouble();
boat.setCurrentPosition(new GPSCoordinate(lat, lon));
boat.setHeading(boatLocation.getHeadingDegrees());
double MMPS_TO_KN = 0.001944;
boat.setVelocity(boatLocation.getBoatSOG() * MMPS_TO_KN);
}
}

@ -3,7 +3,6 @@ package seng302.Model;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import org.geotools.referencing.GeodeticCalculator;
import seng302.Constants;
import seng302.GPSCoordinate;
import java.awt.geom.Point2D;
@ -15,32 +14,25 @@ import java.util.concurrent.ConcurrentLinkedQueue;
*/
public class Boat {
protected StringProperty name;
private final StringProperty name;
protected double velocity;
private StringProperty velocityProp;
protected String abbrev;
protected GPSCoordinate currentPosition;
private final StringProperty velocityProp;
private final String abbrev;
private GPSCoordinate currentPosition;
protected double heading;
protected Leg currentLeg;
protected StringProperty currentLegName;
protected boolean finished = false;
protected long timeFinished;
protected StringProperty position;
protected boolean started = false;
protected boolean dnf = false;
private double wakeScale = 3;
private Leg currentLeg;
private final StringProperty currentLegName;
private boolean finished = false;
private long timeFinished;
private final StringProperty position;
private boolean started = false;
private boolean dnf = false;
private int sourceID;
protected Queue<TrackPoint> track = new ConcurrentLinkedQueue<>();
protected long nextValidTime = 0;
protected static final float BASE_TRACK_POINT_TIME_INTERVAL = 5000;
protected static float trackPointTimeInterval = 5000; // every 1 seconds
protected final int TRACK_POINT_LIMIT = 10;
private final Queue<TrackPoint> track = new ConcurrentLinkedQueue<>();
private long nextValidTime = 0;
/**
* Boat initialiser which keeps all of the information of the boat.
* Boat initializer which keeps all of the information of the boat.
*
* @param name Name of the Boat.
* @param velocity Speed in m/s that the boat travels at.
@ -56,12 +48,12 @@ public class Boat {
}
/**
* Boat initialiser which keeps all of the information of the boat.
* Boat initializer which keeps all of the information of the boat.
*
* @param name Name of the Boat.
* @param abbrev nam abbreviation
*/
public Boat(String name, String abbrev) {
protected Boat(String name, String abbrev) {
this(name, 0, abbrev);
}
@ -74,6 +66,7 @@ public class Boat {
*/
public GPSCoordinate getWake() {
double reverseHeading = getHeading() - 180;
double wakeScale = 3;
double distance = wakeScale * getVelocity();
GeodeticCalculator calc = new GeodeticCalculator();
@ -91,14 +84,15 @@ public class Boat {
* @return whether add is successful
* @see seng302.Model.TrackPoint
*/
public boolean addTrackPoint(GPSCoordinate coordinate) {
public void addTrackPoint(GPSCoordinate coordinate) {
Boolean added = System.currentTimeMillis() >= nextValidTime;
long currentTime = System.currentTimeMillis();
if (added && this.started) {
float trackPointTimeInterval = 5000;
nextValidTime = currentTime + (long) trackPointTimeInterval;
int TRACK_POINT_LIMIT = 10;
track.add(new TrackPoint(coordinate, currentTime, TRACK_POINT_LIMIT * (long) trackPointTimeInterval));
}
return added;
}
/**

@ -17,24 +17,23 @@ import java.util.concurrent.ConcurrentLinkedQueue;
*/
public class BoatInRace extends Boat {
protected Leg currentLeg;
protected double scaledVelocity;
protected double distanceTravelledInLeg;
protected GPSCoordinate currentPosition;
protected long timeFinished;
protected Color colour;
protected boolean finished = false;
protected StringProperty currentLegName;
protected boolean started = false;
protected StringProperty position;
protected double heading;
protected Queue<TrackPoint> track = new ConcurrentLinkedQueue<>();
protected long nextValidTime = 0;
protected static final float BASE_TRACK_POINT_TIME_INTERVAL = 5000;
protected static float trackPointTimeInterval = 5000; // every 1 seconds
protected final int TRACK_POINT_LIMIT = 10;
private Leg currentLeg;
private double scaledVelocity;
private double distanceTravelledInLeg;
private GPSCoordinate currentPosition;
private long timeFinished;
private Color colour;
private boolean finished = false;
private final StringProperty currentLegName;
private boolean started = false;
private final StringProperty position;
private double heading;
private final Queue<TrackPoint> track = new ConcurrentLinkedQueue<>();
private long nextValidTime = 0;
private static final float BASE_TRACK_POINT_TIME_INTERVAL = 5000;
private static float trackPointTimeInterval = 5000; // every 1 seconds
/**
* Constructor method.
@ -88,7 +87,7 @@ public class BoatInRace extends Boat {
* @param azimuth azimuth value to be converted
* @return the bearings in degrees (0 to 360).
*/
public static double calculateHeading(double azimuth) {
private static double calculateHeading(double azimuth) {
if (azimuth >= 0) {
return azimuth;
} else {
@ -197,7 +196,7 @@ public class BoatInRace extends Boat {
* @param colour Colour that the boat is to be set to.
* @see ResizableRaceCanvas
*/
public void setColour(Color colour) {
private void setColour(Color colour) {
this.colour = colour;
}
@ -289,14 +288,14 @@ public class BoatInRace extends Boat {
* @return whether add is successful
* @see seng302.Model.TrackPoint
*/
public boolean addTrackPoint(GPSCoordinate coordinate) {
public void addTrackPoint(GPSCoordinate coordinate) {
Boolean added = System.currentTimeMillis() >= nextValidTime;
long currentTime = System.currentTimeMillis();
if (added && this.started) {
nextValidTime = currentTime + (long) trackPointTimeInterval;
int TRACK_POINT_LIMIT = 10;
track.add(new TrackPoint(coordinate, currentTime, TRACK_POINT_LIMIT * (long) trackPointTimeInterval));
}
return added;
}
/**

@ -22,7 +22,7 @@
// private int dnfChance = 0; //%percentage chance a boat fails at each checkpoint
//
// /**
// * Initialiser for a constant velocity race without standard data source
// * Initializer for a constant velocity race without standard data source
// *
// * @param startingBoats in race
// * @param legs in race
@ -34,7 +34,7 @@
// }
//
// /**
// * Initialiser for legacy tests
// * Initializer for legacy tests
// *
// * @param startingBoats in race
// * @param legs in race
@ -48,7 +48,7 @@
// }
//
// /**
// * Initialiser for constant velocity race with standard data source
// * Initializer for constant velocity race with standard data source
// * @param raceData for race
// * @param controller for graphics
// * @param scaleFactor of timer

@ -8,14 +8,14 @@ import seng302.GPSCoordinate;
* Created by cbt24 on 6/03/17.
*/
public class Leg {
private String name; //nautical miles
private final String name; //nautical miles
private double distance;
private Marker startMarker;
private Marker endMarker;
private int legNumber;
private final int legNumber;
/**
* Leg Initialiser
* Leg Initializer
*
* @param name Name of the Leg
* @param start marker
@ -89,7 +89,7 @@ public class Leg {
/**
* Calculates the distance that the legs are in nautical miles (1.852 km).
*/
public void calculateDistance() {
private void calculateDistance() {
GeodeticCalculator calc = new GeodeticCalculator();
//Load start and end of leg

@ -9,9 +9,9 @@ import java.awt.geom.Point2D;
* Created by esa46 on 29/03/17.
*/
public class Marker {
private GPSCoordinate averageGPSCoordinate;
private GPSCoordinate mark1;
private GPSCoordinate mark2;
private final GPSCoordinate averageGPSCoordinate;
private final GPSCoordinate mark1;
private final GPSCoordinate mark2;
public Marker(GPSCoordinate mark1) {

@ -4,55 +4,47 @@ import javafx.animation.AnimationTimer;
import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import org.geotools.referencing.GeodeticCalculator;
import seng302.Controllers.FinishController;
import seng302.Controllers.RaceController;
import seng302.GPSCoordinate;
import seng302.RaceDataSource;
import seng302.VisualiserInput;
import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
/**
* Parent class for races
* Created by fwy13 on 3/03/17.
*/
public abstract class Race implements Runnable {
protected ObservableList<Boat> startingBoats;
protected List<Leg> legs;
protected RaceController controller;
protected final ObservableList<Boat> startingBoats;
protected final List<Leg> legs;
private RaceController controller;
protected FinishController finishController;
protected int boatsFinished = 0;
protected long totalTimeElapsed;
private long totalTimeElapsed;
protected int scaleFactor;
private int lastFPS = 20;
/**
* Initailiser for Race
* Initializer for Race
*
* @param boats Takes in an array of boats that are participating in the race.
* @param legs Number of marks in order that the boats pass in order to complete the race.
* @param controller race controller
* @param scaleFactor for race
*/
public Race(List<Boat> boats, List<Leg> legs, RaceController controller, int scaleFactor) {
private Race(List<Boat> boats, List<Leg> legs, RaceController controller, int scaleFactor) {
this.startingBoats = FXCollections.observableArrayList(boats);
this.legs = legs;
this.legs.add(new Leg("Finish", this.legs.size()));
this.controller = controller;
this.scaleFactor = scaleFactor;
if (startingBoats != null && startingBoats.size() > 0) {
initialiseBoats();
}
}
public Race(RaceDataSource raceData, RaceController controller, int scaleFactor) {
protected Race(RaceDataSource raceData, RaceController controller, int scaleFactor) {
this(raceData.getBoats(), raceData.getLegs(), controller, scaleFactor);
}
@ -71,7 +63,7 @@ public abstract class Race implements Runnable {
this.controller = controller;
}
public abstract void initialiseBoats();
protected abstract void initialiseBoats();
/**
* Checks if the boat cannot finish the race
@ -82,7 +74,7 @@ public abstract class Race implements Runnable {
/**
* Checks the position of the boat, this updates the boats current position.
*
* @param boat Boat that the postion is to be updated for.
* @param boat Boat that the position is to be updated for.
* @param timeElapsed Time that has elapse since the start of the the race.
* @see Boat
*/
@ -112,16 +104,14 @@ public abstract class Race implements Runnable {
* @param fps The new calculated fps value
*/
private void updateFPS(int fps) {
Platform.runLater(() -> {
controller.setFrames("FPS: " + fps);
});
Platform.runLater(() -> controller.setFrames("FPS: " + fps));
}
/**
* Starts the Race Simulation, playing the race start to finish with the timescale.
* This prints the boats participating, the order that the events occur in time order, and the respective information of the events.
*/
protected final void simulateRace() {
private void simulateRace() {
System.setProperty("javafx.animation.fullspeed", "true");
@ -131,7 +121,7 @@ public abstract class Race implements Runnable {
new AnimationTimer() {
long timeRaceStarted = System.currentTimeMillis(); //start time of loop
final long timeRaceStarted = System.currentTimeMillis(); //start time of loop
int fps = 0; //init fps value
long timeCurrent = System.currentTimeMillis(); //current time
@ -184,7 +174,7 @@ public abstract class Race implements Runnable {
/**
* Update call for the controller.
*/
protected void setControllerListeners() {
private void setControllerListeners() {
if (controller != null) controller.setInfoTable(this);
}

@ -20,10 +20,10 @@ import java.util.Date;
*/
public class RaceClock implements Runnable {
private long lastTime;
private ZoneId zoneId;
private final ZoneId zoneId;
private ZonedDateTime time;
private ZonedDateTime startingTime;
private StringProperty timeString;
private final StringProperty timeString;
private StringProperty duration;
public RaceClock(ZonedDateTime zonedDateTime) {
@ -62,16 +62,16 @@ public class RaceClock implements Runnable {
*
* @param time arbitrary time with timezone.
*/
public void setTime(ZonedDateTime time) {
private void setTime(ZonedDateTime time) {
this.time = time;
this.timeString.set(DateTimeFormatter.ofPattern("HH:mm:ss dd/MM/YYYY Z").format(time));
this.lastTime = System.currentTimeMillis();
if(startingTime != null) {
long seconds = Duration.between(startingTime.toLocalDateTime(), time.toLocalDateTime()).getSeconds();
if(seconds < 0)
duration.set(String.format(String.format("Starting in: %02d:%02d:%02d", -seconds/3600, -(seconds%3600)/60, -seconds%60)));
duration.set(String.format("Starting in: %02d:%02d:%02d", -seconds/3600, -(seconds%3600)/60, -seconds%60));
else
duration.set(String.format(String.format("Time: %02d:%02d:%02d", seconds/3600, (seconds%3600)/60, seconds%60)));
duration.set(String.format("Time: %02d:%02d:%02d", seconds/3600, (seconds%3600)/60, seconds%60));
}
}
@ -105,7 +105,7 @@ public class RaceClock implements Runnable {
/**
* Updates time by duration elapsed since last update.
*/
public void updateTime() {
private void updateTime() {
this.time = this.time.plus(Duration.of(System.currentTimeMillis() - this.lastTime, ChronoUnit.MILLIS));
this.lastTime = System.currentTimeMillis();
setTime(time);

@ -7,7 +7,7 @@ import javafx.scene.canvas.GraphicsContext;
* Created by fwy13 on 4/05/17.
*/
public abstract class ResizableCanvas extends Canvas {
protected GraphicsContext gc;
protected final GraphicsContext gc;
public ResizableCanvas(){
this.gc = this.getGraphicsContext2D();

@ -1,14 +1,14 @@
package seng302.Model;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.scene.transform.Rotate;
import seng302.*;
import seng302.Controllers.RaceController;
import seng302.GPSCoordinate;
import seng302.GraphCoordinate;
import seng302.Mock.StreamedCourse;
import seng302.RaceDataSource;
import seng302.RaceMap;
import java.util.ArrayList;
import java.util.Arrays;
@ -28,9 +28,9 @@ public class ResizableRaceCanvas extends ResizableCanvas {
private boolean annoSpeed = true;
private boolean annoPath = true;
private List<Color> colours;
private List<Marker> markers;
private final List<Marker> markers;
double[] xpoints = {}, ypoints = {};
RaceDataSource raceData;
private final RaceDataSource raceData;
public ResizableRaceCanvas(RaceDataSource raceData) {
super();
@ -61,14 +61,15 @@ public class ResizableRaceCanvas extends ResizableCanvas {
*
* @param map race map
*/
public void setMap(RaceMap map) {
private void setMap(RaceMap map) {
this.map = map;
}
/**
* Displays the mark of a race as a circle.
*
* @param graphCoordinate Latitude and Logintude in GraphCoordinate that it is to be displayed as.
* @param graphCoordinate Latitude and Longitude in GraphCoordinate that it
* is to be displayed as.
* @param paint Colour the mark is to be coloured.
* @see GraphCoordinate
* @see Color
@ -80,14 +81,13 @@ public class ResizableRaceCanvas extends ResizableCanvas {
gc.fillOval(graphCoordinate.getX() - (d / 2), graphCoordinate.getY() - (d / 2), d, d);
}
public void displayBoat(Boat boat, double angle, Color colour) {
private void displayBoat(Boat boat, double angle, Color colour) {
if (boat.getCurrentPosition() != null) {
GraphCoordinate pos = this.map.convertGPS(boat.getCurrentPosition());
Paint paint = colour;
double[] x = {pos.getX() - 6, pos.getX(), pos.getX() + 6};
double[] y = {pos.getY() + 12, pos.getY() - 12, pos.getY() + 12};
gc.setFill(paint);
gc.setFill(colour);
gc.save();
rotate(angle, pos.getX(), pos.getY());
@ -203,7 +203,7 @@ public class ResizableRaceCanvas extends ResizableCanvas {
/**
* Draw race markers
*/
public void drawMarkers() {
private void drawMarkers() {
for(Marker marker: markers) {
GraphCoordinate mark1 = this.map.convertGPS(marker.getMark1());
// removed drawing of lines between the marks as only
@ -263,58 +263,38 @@ public class ResizableRaceCanvas extends ResizableCanvas {
* Toggle the raceAnno value
*/
public void toggleAnnotations() {
if (raceAnno) {
raceAnno = false;
} else {
raceAnno = true;
}
raceAnno = !raceAnno;
}
/**
* Toggle name display in annotation
*/
public void toggleAnnoName() {
if (annoName) {
annoName = false;
} else {
annoName = true;
}
annoName = !annoName;
}
public void toggleBoatPath() {
if (annoPath) {
annoPath = false;
} else {
annoPath = true;
}
annoPath = !annoPath;
}
/**
* Toggle abbreviation display in annotation
*/
public void toggleAnnoAbbrev() {
if (annoAbbrev) {
annoAbbrev = false;
} else {
annoAbbrev = true;
}
annoAbbrev = !annoAbbrev;
}
/**
* Toggle speed display in annotation
*/
public void toggleAnnoSpeed() {
if (annoSpeed) {
annoSpeed = false;
} else {
annoSpeed = true;
}
annoSpeed = !annoSpeed;
}
/**
* Draws boats while race in progress, when leg heading is set.
*/
public void updateBoats() {
private void updateBoats() {
int currentColour = 0;
if (boats != null) {
for (Boat boat : boats) {
@ -349,15 +329,14 @@ public class ResizableRaceCanvas extends ResizableCanvas {
if (annoPath && raceAnno) {
for (TrackPoint point : boat.getTrack()) {
GraphCoordinate scaledCoordinate = this.map.convertGPS(point.getCoordinate());
Color boatColour = colour;
gc.setFill(new Color(boatColour.getRed(), boatColour.getGreen(), boatColour.getBlue(), point.getAlpha()));
gc.setFill(new Color(colour.getRed(), colour.getGreen(), colour.getBlue(), point.getAlpha()));
gc.fillOval(scaledCoordinate.getX(), scaledCoordinate.getY(), 5, 5);
}
}
}
private void makeColours() {
colours = new ArrayList<Color>(Arrays.asList(
colours = new ArrayList<>(Arrays.asList(
Color.BLUEVIOLET,
Color.BLACK,
Color.RED,

@ -3,7 +3,6 @@ package seng302.Model;
import javafx.scene.paint.Color;
import seng302.GPSCoordinate;
import seng302.GraphCoordinate;
import seng302.Mock.StreamedCourse;
import seng302.RaceDataSource;
import seng302.RaceMap;
@ -14,14 +13,13 @@ import java.util.List;
*/
public class ResizableRaceMap extends ResizableCanvas {
private RaceMap map;
RaceDataSource raceData;
private List<GPSCoordinate> raceBoundaries;
double[] xpoints = {}, ypoints = {};
private final List<GPSCoordinate> raceBoundaries;
private double[] xpoints = {};
private double[] ypoints = {};
public ResizableRaceMap(RaceDataSource raceData){
super();
this.raceData = raceData;
raceBoundaries = this.raceData.getBoundary();
raceBoundaries = raceData.getBoundary();
double lat1 = raceData.getMapTopLeft().getLatitude();
double long1 = raceData.getMapTopLeft().getLongitude();
@ -31,13 +29,13 @@ public class ResizableRaceMap extends ResizableCanvas {
//draw();
}
public void setMap(RaceMap map) {
private void setMap(RaceMap map) {
this.map = map;
}
/**
* Draw boundary of the race.
*/
public void drawBoundaries() {
private void drawBoundaries() {
if (this.raceBoundaries == null) {
return;
}
@ -48,7 +46,7 @@ public class ResizableRaceMap extends ResizableCanvas {
gc.fillPolygon(xpoints, ypoints, xpoints.length);
}
public void setRaceBoundCoordinates() {
private void setRaceBoundCoordinates() {
xpoints = new double[this.raceBoundaries.size()];
ypoints = new double[this.raceBoundaries.size()];
for (int i = 0; i < raceBoundaries.size(); i++) {

@ -6,10 +6,10 @@ import seng302.GPSCoordinate;
* Created by cbt24 on 7/04/17.
*/
public class TrackPoint {
private GPSCoordinate coordinate;
private long timeAdded;
private long expiry;
private double minAlpha;
private final GPSCoordinate coordinate;
private final long timeAdded;
private final long expiry;
private final double minAlpha;
/**
* Creates a new track point with fixed GPS coordinates and time, to reach minimum opacity on expiry.

@ -11,9 +11,9 @@ import java.net.Socket;
* Created by cbt24 on 3/05/17.
*/
public class RaceConnection {
private StringProperty hostname;
private int port;
private StringProperty status;
private final StringProperty hostname;
private final int port;
private final StringProperty status;
public RaceConnection(String hostname, int port) {
this.hostname = new SimpleStringProperty(hostname);
@ -29,7 +29,7 @@ public class RaceConnection {
@SuppressWarnings("unused")
public boolean check() {
InetSocketAddress i = new InetSocketAddress(hostname.get(), port);
try (Socket s = new Socket();){
try (Socket s = new Socket()){
s.connect(i, 5000);
status.set("Ready");
return true;

@ -1,13 +1,11 @@
package seng302;
import seng302.Model.Boat;
import seng302.Model.BoatInRace;
import seng302.Model.Leg;
import seng302.Model.Marker;
import java.time.ZonedDateTime;
import java.util.List;
import java.util.Observable;
/**
* Created by connortaylorbrown on 19/04/17.

@ -4,7 +4,10 @@ package seng302;
* Created by cbt24 on 15/03/17.
*/
public class RaceMap {
private double x1, x2, y1, y2;
private final double x1;
private final double x2;
private final double y1;
private final double y2;
private int width, height;
/**
@ -34,7 +37,7 @@ public class RaceMap {
* @return GraphCoordinate (pair of doubles)
* @see GraphCoordinate
*/
public GraphCoordinate convertGPS(double lat, double lon) {
private GraphCoordinate convertGPS(double lat, double lon) {
int difference = Math.abs(width - height);
int size = width;
if (width > height) {

@ -17,16 +17,15 @@ import java.util.List;
* @deprecated use {@link seng302.Mock.StreamedCourseXMLReader}
*/
public class RaceXMLReader extends XMLReader implements RaceDataSource {
private List<Boat> boats = new ArrayList<>();
private Color[] colors = {Color.BLUEVIOLET, Color.BLACK, Color.RED, Color.ORANGE, Color.DARKOLIVEGREEN, Color.LIMEGREEN};//TODO make this established in xml or come up with a better system.
private List<Leg> legs = new ArrayList<>();
private final List<Boat> boats = new ArrayList<>();
private final Color[] colors = {Color.BLUEVIOLET, Color.BLACK, Color.RED, Color.ORANGE, Color.DARKOLIVEGREEN, Color.LIMEGREEN};//TODO make this established in xml or come up with a better system.
private final List<Leg> legs = new ArrayList<>();
private GPSCoordinate mark, startPt1, startPt2, finishPt1, finishPt2, leewardPt1, leewardPt2, windwardPt1, windwardPt2;
private GPSCoordinate mapTopLeft, mapBottomRight;
private List<GPSCoordinate> boundary = new ArrayList<>();
private static double COORDINATEPADDING = 0.0005;
private final List<GPSCoordinate> boundary = new ArrayList<>();
/**
* Constractor for Race XML
* Constructor for Race XML
* @param filePath path of the file
* @throws IOException error
* @throws SAXException error
@ -37,7 +36,7 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
}
/**
* COnstructor for Race XML
* Constructor for Race XML
* @param filePath file path to read
* @param read whether or not to read and store the files straight away.
* @throws IOException error
@ -145,12 +144,13 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
maxLatitude += difference / 2;
minLatitude -= difference / 2;
}
double COORDINATEPADDING = 0.0005;
maxLatitude += COORDINATEPADDING;
minLatitude -= COORDINATEPADDING;
maxLongitude += COORDINATEPADDING;
minLongitude -= COORDINATEPADDING;
//now create map boundaries
//top left canvas point is min logitude, max latitude
//top left canvas point is min longitude, max latitude
//bottom right of canvas point is min longitude, max latitude.
mapTopLeft = new GPSCoordinate(minLatitude, minLongitude);
mapBottomRight = new GPSCoordinate(maxLatitude, maxLongitude);

@ -6,8 +6,9 @@ import seng302.Networking.Exceptions.InvalidMessageException;
import seng302.Networking.Messages.*;
import javax.xml.parsers.ParserConfigurationException;
import java.io.*;
import java.net.*;
import java.io.DataInputStream;
import java.io.IOException;
import java.net.Socket;
import java.nio.ByteBuffer;
import java.text.ParseException;
import java.util.Arrays;
@ -15,7 +16,6 @@ import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ArrayBlockingQueue;
import static seng302.Networking.Utils.ByteConverter.bytesToInt;
import static seng302.Networking.Utils.ByteConverter.bytesToShort;
/**
@ -24,14 +24,12 @@ import static seng302.Networking.Utils.ByteConverter.bytesToShort;
public class VisualiserInput implements Runnable {
///A queue that contains messages that have been received, and need to be handled.
private ArrayBlockingQueue<AC35Data> messagesReceivedQueue = new ArrayBlockingQueue<>(1000000);//We have room for 1,000,000. Is this much capacity actually needed?
private final ArrayBlockingQueue<AC35Data> messagesReceivedQueue = new ArrayBlockingQueue<>(1000000);//We have room for 1,000,000. Is this much capacity actually needed?
///Timestamp of the last heartbeat.
private long lastHeartbeatTime = -1;
///Sequence number of the last heartbeat.
private long lastHeartbeatSequenceNum = -1;
///How long we should wait for a heartbeat before assuming the connection is dead. Measured in milliseconds.
private long heartBeatPeriod = 10 * 1000;
///The socket that we have connected to.
private Socket connectionSocket;
@ -43,10 +41,10 @@ public class VisualiserInput implements Runnable {
private RaceStatus raceStatus;
///A map of the last BoatStatus message received, for each boat.
private Map<Integer, BoatStatus> boatStatusMap = new HashMap<>();;
private final Map<Integer, BoatStatus> boatStatusMap = new HashMap<>();
///A map of the last BoatLocation message received, for each boat.
private Map<Integer, BoatLocation> boatLocationMap = new HashMap<>();
private final Map<Integer, BoatLocation> boatLocationMap = new HashMap<>();
///The last AverageWind message received.
private AverageWind averageWind;
@ -55,17 +53,11 @@ public class VisualiserInput implements Runnable {
private CourseWinds courseWinds;
///A map of the last MarkRounding message received, for each boat.
private Map<Integer, MarkRounding> markRoundingMap = new HashMap<>();
///The last RaceStartStatus message received.
private RaceStartStatus raceStartStatus;
private final Map<Integer, MarkRounding> markRoundingMap = new HashMap<>();
///InputStream (from the socket).
private DataInputStream inStream;
///TODO comment?
private boolean receiverLoop = true;
/**
* Ctor.
* @param socket Socket from which we will receive race data.
@ -212,9 +204,8 @@ public class VisualiserInput implements Runnable {
//Decode the binary message into an appropriate message object.
BinaryMessageDecoder decoder = new BinaryMessageDecoder(messageBytes);
AC35Data message = decoder.decode();
return message;
return decoder.decode();
}
@ -222,14 +213,15 @@ public class VisualiserInput implements Runnable {
* Main loop which reads messages from the socket, and exposes them.
*/
public void run(){
this.receiverLoop = true;
boolean receiverLoop = true;
//receiver loop that gets the input
while (receiverLoop) {
//If no heartbeat has been received in more the heartbeat period
//then the connection will need to be restarted.
System.out.println("time since last heartbeat: " + timeSinceHeartbeat());//TEMP REMOVE
if (timeSinceHeartbeat() > this.heartBeatPeriod) {
long heartBeatPeriod = 10 * 1000;
if (timeSinceHeartbeat() > heartBeatPeriod) {
System.out.println("Connection has stopped, trying to reconnect.");
//Attempt to reconnect the socket.
@ -257,7 +249,7 @@ public class VisualiserInput implements Runnable {
}
//Reads the next message.
AC35Data message = null;
AC35Data message;
try {
message = this.getNextMessage();
}
@ -306,7 +298,7 @@ public class VisualiserInput implements Runnable {
//System.out.println("XML Message!");
if (xmlMessage.getXmlMsgSubType() == xmlMessage.XMLTypeRegatta){
if (xmlMessage.getXmlMsgSubType() == XMLMessage.XMLTypeRegatta){
//System.out.println("Setting Regatta");
try {
course.setRegattaXMLReader(new RegattaXMLReader(xmlMessage.getXmlMessage()));
@ -315,10 +307,9 @@ public class VisualiserInput implements Runnable {
catch (IOException | SAXException | ParserConfigurationException e) {
System.err.println("Error creating RegattaXMLReader: " + e.getMessage());
//Continue to the next loop iteration/message.
continue;
}
} else if (xmlMessage.getXmlMsgSubType() == xmlMessage.XMLTypeRace){
} else if (xmlMessage.getXmlMsgSubType() == XMLMessage.XMLTypeRace){
//System.out.println("Setting Course");
try {
course.setStreamedCourseXMLReader(new StreamedCourseXMLReader(xmlMessage.getXmlMessage()));
@ -327,10 +318,9 @@ public class VisualiserInput implements Runnable {
catch (IOException | SAXException | ParserConfigurationException | ParseException | StreamedCourseXMLException e) {
System.err.println("Error creating StreamedCourseXMLReader: " + e.getMessage());
//Continue to the next loop iteration/message.
continue;
}
} else if (xmlMessage.getXmlMsgSubType() == xmlMessage.XMLTypeBoat){
} else if (xmlMessage.getXmlMsgSubType() == XMLMessage.XMLTypeBoat){
//System.out.println("Setting Boats");
try
{
@ -340,7 +330,6 @@ public class VisualiserInput implements Runnable {
catch (IOException | SAXException | ParserConfigurationException e) {
System.err.println("Error creating BoatXMLReader: " + e.getMessage());
//Continue to the next loop iteration/message.
continue;
}
}
@ -348,10 +337,8 @@ public class VisualiserInput implements Runnable {
}
//RaceStartStatus.
else if (message instanceof RaceStartStatus) {
RaceStartStatus raceStartStatus = (RaceStartStatus) message;
//System.out.println("Race Start Status Message");
this.raceStartStatus = raceStartStatus;
}
//YachtEventCode.
/*else if (message instanceof YachtEventCode) {
@ -414,18 +401,16 @@ public class VisualiserInput implements Runnable {
}
//CourseWinds.
else if (message instanceof CourseWinds) {
CourseWinds courseWinds = (CourseWinds) message;
//System.out.println("Course Wind Message!");
this.courseWinds = courseWinds;
this.courseWinds = (CourseWinds) message;
}
//AverageWind.
else if (message instanceof AverageWind) {
AverageWind averageWind = (AverageWind) message;
//System.out.println("Average Wind Message!");
this.averageWind = averageWind;
this.averageWind = (AverageWind) message;
}
//Unrecognised message.

@ -3,7 +3,6 @@ package seng302;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import javax.xml.parsers.DocumentBuilder;
@ -11,7 +10,6 @@ import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
/**
* Created by fwy13 on 26/03/2017.
@ -20,7 +18,7 @@ public abstract class XMLReader {
protected Document doc;
public XMLReader(String filePath) throws ParserConfigurationException, IOException, SAXException {
protected XMLReader(String filePath) throws ParserConfigurationException, IOException, SAXException {
InputStream fXmlFile = getClass().getClassLoader().getResourceAsStream(filePath);
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
@ -28,7 +26,7 @@ public abstract class XMLReader {
doc.getDocumentElement().normalize();
}
public XMLReader(InputStream xmlInput) throws ParserConfigurationException, IOException, SAXException {
protected XMLReader(InputStream xmlInput) throws ParserConfigurationException, IOException, SAXException {
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
@ -39,11 +37,11 @@ public abstract class XMLReader {
return doc;
}
public String getTextValueOfNode(Element n, String tagName) {
protected String getTextValueOfNode(Element n, String tagName) {
return n.getElementsByTagName(tagName).item(0).getTextContent();
}
public boolean exists(Node node, String attribute) {
protected boolean exists(Node node, String attribute) {
return node.getAttributes().getNamedItem(attribute) != null;
}

@ -1,21 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.text.Font?>
<AnchorPane fx:id="connectionWrapper" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="780.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.Controllers.ConnectionController">
<children>
<GridPane fx:id="connection" prefHeight="600.0" prefWidth="780.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">

@ -1,19 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.text.Font?>
<AnchorPane fx:id="finishWrapper" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" visible="false" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.Controllers.FinishController">
<children>
<GridPane fx:id="start" alignment="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="600.0" prefWidth="780.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane fx:id="main" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.Controllers.MainController">
<children>
<fx:include fx:id="race" source="race.fxml" />

@ -1,19 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.text.Font?>
<AnchorPane fx:id="startWrapper" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" visible="false" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.Controllers.StartController">
<children>
<GridPane fx:id="start" prefHeight="600.0" prefWidth="780.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">

@ -7,13 +7,12 @@ import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* Created by jjg64 on 21/04/17.
*/
public class BoatsXMLTest {
BoatXMLReader boatXMLReader;
private BoatXMLReader boatXMLReader;
@Before
public void setup() {

@ -1,25 +1,17 @@
package seng302.Mock;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.xml.sax.SAXException;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.text.ParseException;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* Created by jjg64 on 1/05/17.
*/
public class FailBoatXMLTest {
String path = "mockXML/boatXML/";
private final String path = "mockXML/boatXML/";
@Test(expected = NumberFormatException.class)
public void invalidSourceID() throws SAXException, ParserConfigurationException, ParseException, IOException {

@ -3,7 +3,8 @@ package seng302.Mock;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
/**
* Created by jjg64 on 19/04/17.

@ -11,25 +11,22 @@ import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
/**
* Tests only work on the current version of mockXML/raceXML/raceTest.xml
*/
public class StreamedRaceTest {
StreamedCourseXMLReader streamedCourseXMLReader;
List<GPSCoordinate> boundary;
private StreamedCourseXMLReader streamedCourseXMLReader;
private List<GPSCoordinate> boundary;
@Before
public void setup() {
try {
streamedCourseXMLReader = new StreamedCourseXMLReader("mockXML/raceXML/raceTest.xml", true);
boundary = streamedCourseXMLReader.getBoundary();
} catch (Exception e) {
} catch (Exception | StreamedCourseXMLException e) {
e.printStackTrace();
//fail("Cannot find mockXML/raceXML/raceTest.xml in the resources folder");
} catch (StreamedCourseXMLException e) {
e.printStackTrace();
}
}

@ -12,8 +12,8 @@ import static junit.framework.TestCase.*;
public class BoatInRaceTest {
private GPSCoordinate ORIGIN_COORDS = new GPSCoordinate(0, 0);
private BoatInRace TEST_BOAT = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt");
private final GPSCoordinate ORIGIN_COORDS = new GPSCoordinate(0, 0);
private final BoatInRace TEST_BOAT = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt");
@Test

@ -14,7 +14,7 @@ import static junit.framework.TestCase.assertEquals;
*/
public class LegTest {
private Marker ORIGIN_MARKER = new Marker(new GPSCoordinate(0, 0));
private final Marker ORIGIN_MARKER = new Marker(new GPSCoordinate(0, 0));
@Test
public void calculateDistanceHandles5nmNorth() {

@ -10,7 +10,7 @@ import static org.junit.Assert.assertTrue;
*/
public class MarkerTest {
GPSCoordinate ORIGIN_COORD = new GPSCoordinate(0, 0);
private final GPSCoordinate ORIGIN_COORD = new GPSCoordinate(0, 0);
@Test
public void averageOfSingleMarkAtOriginIsSingleMark() {

@ -1,4 +1,5 @@
package seng302.Model;/**
package seng302.Model;
/**
* Created by Gondr on 26/03/2017.
*/

Loading…
Cancel
Save