From 2d983eccfd3a8e8ce164df51b9928b197520df13 Mon Sep 17 00:00:00 2001 From: Jessica McAuslin Date: Mon, 8 May 2017 20:21:20 +1200 Subject: [PATCH] General code tidy up - access modifiers adjusted - unused declarations removed - spelling fixes - removed redundant code --- visualiser/src/main/java/seng302/App.java | 4 - .../Controllers/ConnectionController.java | 2 - .../seng302/Controllers/FinishController.java | 6 +- .../seng302/Controllers/MainController.java | 14 +--- .../seng302/Controllers/RaceController.java | 77 +++++-------------- .../seng302/Controllers/StartController.java | 20 +++-- .../src/main/java/seng302/GPSCoordinate.java | 4 +- .../main/java/seng302/GraphCoordinate.java | 4 +- .../main/java/seng302/Mock/BoatXMLReader.java | 17 ++-- .../src/main/java/seng302/Mock/Regatta.java | 18 ++--- .../java/seng302/Mock/RegattaXMLReader.java | 21 +++-- .../main/java/seng302/Mock/StreamedBoat.java | 8 +- .../java/seng302/Mock/StreamedCourse.java | 13 ++-- .../seng302/Mock/StreamedCourseXMLReader.java | 31 ++++---- .../main/java/seng302/Mock/StreamedRace.java | 6 +- .../src/main/java/seng302/Model/Boat.java | 46 +++++------ .../main/java/seng302/Model/BoatInRace.java | 43 +++++------ .../seng302/Model/ConstantVelocityRace.java | 6 +- .../src/main/java/seng302/Model/Leg.java | 8 +- .../src/main/java/seng302/Model/Marker.java | 6 +- .../src/main/java/seng302/Model/Race.java | 36 ++++----- .../main/java/seng302/Model/RaceClock.java | 12 +-- .../java/seng302/Model/ResizableCanvas.java | 2 +- .../seng302/Model/ResizableRaceCanvas.java | 61 +++++---------- .../java/seng302/Model/ResizableRaceMap.java | 16 ++-- .../main/java/seng302/Model/TrackPoint.java | 8 +- .../src/main/java/seng302/RaceConnection.java | 8 +- .../src/main/java/seng302/RaceDataSource.java | 2 - visualiser/src/main/java/seng302/RaceMap.java | 7 +- .../src/main/java/seng302/RaceXMLReader.java | 16 ++-- .../main/java/seng302/VisualiserInput.java | 49 ++++-------- .../src/main/java/seng302/XMLReader.java | 10 +-- .../src/main/resources/scenes/connect.fxml | 12 --- .../src/main/resources/scenes/finish.fxml | 11 --- .../src/main/resources/scenes/main.fxml | 1 - .../src/main/resources/scenes/start.fxml | 11 --- .../test/java/seng302/Mock/BoatsXMLTest.java | 3 +- .../java/seng302/Mock/FailBoatXMLTest.java | 10 +-- .../java/seng302/Mock/RegattaXMLTest.java | 3 +- .../java/seng302/Mock/StreamedRaceTest.java | 9 +-- .../java/seng302/Model/BoatInRaceTest.java | 4 +- .../src/test/java/seng302/Model/LegTest.java | 2 +- .../test/java/seng302/Model/MarkerTest.java | 2 +- .../test/java/seng302/Model/RaceXMLTest.java | 3 +- 44 files changed, 244 insertions(+), 408 deletions(-) diff --git a/visualiser/src/main/java/seng302/App.java b/visualiser/src/main/java/seng302/App.java index 8a8d1376..a003c681 100644 --- a/visualiser/src/main/java/seng302/App.java +++ b/visualiser/src/main/java/seng302/App.java @@ -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 diff --git a/visualiser/src/main/java/seng302/Controllers/ConnectionController.java b/visualiser/src/main/java/seng302/Controllers/ConnectionController.java index 4e4eb2d0..aed1806d 100644 --- a/visualiser/src/main/java/seng302/Controllers/ConnectionController.java +++ b/visualiser/src/main/java/seng302/Controllers/ConnectionController.java @@ -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; /** diff --git a/visualiser/src/main/java/seng302/Controllers/FinishController.java b/visualiser/src/main/java/seng302/Controllers/FinishController.java index ead7ba59..e610827d 100644 --- a/visualiser/src/main/java/seng302/Controllers/FinishController.java +++ b/visualiser/src/main/java/seng302/Controllers/FinishController.java @@ -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 boats){ + private void setFinishTable(ObservableList boats){ boatInfoTable.setItems(boats); boatNameColumn.setCellValueFactory(cellData -> cellData.getValue().getName()); boatRankColumn.setCellValueFactory(cellData -> cellData.getValue().positionProperty()); diff --git a/visualiser/src/main/java/seng302/Controllers/MainController.java b/visualiser/src/main/java/seng302/Controllers/MainController.java index 5f87b049..3e29086b 100644 --- a/visualiser/src/main/java/seng302/Controllers/MainController.java +++ b/visualiser/src/main/java/seng302/Controllers/MainController.java @@ -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); diff --git a/visualiser/src/main/java/seng302/Controllers/RaceController.java b/visualiser/src/main/java/seng302/Controllers/RaceController.java index 2a489c0f..a108b592 100644 --- a/visualiser/src/main/java/seng302/Controllers/RaceController.java +++ b/visualiser/src/main/java/seng302/Controllers/RaceController.java @@ -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 presetAnno; - private ObservableList 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 boatInfoTable; - @FXML - TableColumn boatPlacingColumn; - @FXML - TableColumn boatTeamColumn; - @FXML - TableColumn boatMarkColumn; - @FXML - TableColumn 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 boatInfoTable; + @FXML TableColumn boatPlacingColumn; + @FXML TableColumn boatTeamColumn; + @FXML TableColumn boatMarkColumn; + @FXML TableColumn 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 startingBoats = race.getStartingBoats(); boatInfoTable.setItems(race.getStartingBoats()); boatTeamColumn.setCellValueFactory(cellData -> cellData.getValue().getName()); boatSpeedColumn.setCellValueFactory(cellData -> cellData.getValue().getVelocityProp()); diff --git a/visualiser/src/main/java/seng302/Controllers/StartController.java b/visualiser/src/main/java/seng302/Controllers/StartController.java index fb5f6f08..f264cded 100644 --- a/visualiser/src/main/java/seng302/Controllers/StartController.java +++ b/visualiser/src/main/java/seng302/Controllers/StartController.java @@ -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; diff --git a/visualiser/src/main/java/seng302/GPSCoordinate.java b/visualiser/src/main/java/seng302/GPSCoordinate.java index 9ece540f..0da61471 100644 --- a/visualiser/src/main/java/seng302/GPSCoordinate.java +++ b/visualiser/src/main/java/seng302/GPSCoordinate.java @@ -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 diff --git a/visualiser/src/main/java/seng302/GraphCoordinate.java b/visualiser/src/main/java/seng302/GraphCoordinate.java index 050931c2..458052dc 100644 --- a/visualiser/src/main/java/seng302/GraphCoordinate.java +++ b/visualiser/src/main/java/seng302/GraphCoordinate.java @@ -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. diff --git a/visualiser/src/main/java/seng302/Mock/BoatXMLReader.java b/visualiser/src/main/java/seng302/Mock/BoatXMLReader.java index cac0f5f9..eee6116c 100644 --- a/visualiser/src/main/java/seng302/Mock/BoatXMLReader.java +++ b/visualiser/src/main/java/seng302/Mock/BoatXMLReader.java @@ -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 streamedBoatMap = new HashMap<>(); - Map participants = new HashMap<>(); + private final Map streamedBoatMap = new HashMap<>(); + private Map 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(); diff --git a/visualiser/src/main/java/seng302/Mock/Regatta.java b/visualiser/src/main/java/seng302/Mock/Regatta.java index 8d080978..7eb936f1 100644 --- a/visualiser/src/main/java/seng302/Mock/Regatta.java +++ b/visualiser/src/main/java/seng302/Mock/Regatta.java @@ -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; diff --git a/visualiser/src/main/java/seng302/Mock/RegattaXMLReader.java b/visualiser/src/main/java/seng302/Mock/RegattaXMLReader.java index 0c275dad..70ff8371 100644 --- a/visualiser/src/main/java/seng302/Mock/RegattaXMLReader.java +++ b/visualiser/src/main/java/seng302/Mock/RegattaXMLReader.java @@ -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(); diff --git a/visualiser/src/main/java/seng302/Mock/StreamedBoat.java b/visualiser/src/main/java/seng302/Mock/StreamedBoat.java index 419478d9..d4485b5a 100644 --- a/visualiser/src/main/java/seng302/Mock/StreamedBoat.java +++ b/visualiser/src/main/java/seng302/Mock/StreamedBoat.java @@ -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() { diff --git a/visualiser/src/main/java/seng302/Mock/StreamedCourse.java b/visualiser/src/main/java/seng302/Mock/StreamedCourse.java index 1080679d..04c89cfc 100644 --- a/visualiser/src/main/java/seng302/Mock/StreamedCourse.java +++ b/visualiser/src/main/java/seng302/Mock/StreamedCourse.java @@ -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() {} diff --git a/visualiser/src/main/java/seng302/Mock/StreamedCourseXMLReader.java b/visualiser/src/main/java/seng302/Mock/StreamedCourseXMLReader.java index 6a54d1a8..2f9af8d5 100644 --- a/visualiser/src/main/java/seng302/Mock/StreamedCourseXMLReader.java +++ b/visualiser/src/main/java/seng302/Mock/StreamedCourseXMLReader.java @@ -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 boundary = new ArrayList<>(); - private Map compoundMarks = new HashMap<>(); - private Map participants = new HashMap<>(); - private List legs = new ArrayList<>(); - private List markers = new ArrayList<>(); - ZonedDateTime creationTimeDate; - ZonedDateTime raceStartTime; - int raceID; - String raceType; - boolean postpone; + private final List boundary = new ArrayList<>(); + private final Map compoundMarks = new HashMap<>(); + private final Map participants = new HashMap<>(); + private final List legs = new ArrayList<>(); + private final List 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(); diff --git a/visualiser/src/main/java/seng302/Mock/StreamedRace.java b/visualiser/src/main/java/seng302/Mock/StreamedRace.java index d0721e79..ed1c7bf5 100644 --- a/visualiser/src/main/java/seng302/Mock/StreamedRace.java +++ b/visualiser/src/main/java/seng302/Mock/StreamedRace.java @@ -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); } } diff --git a/visualiser/src/main/java/seng302/Model/Boat.java b/visualiser/src/main/java/seng302/Model/Boat.java index 42bd6b9d..8e10ae93 100644 --- a/visualiser/src/main/java/seng302/Model/Boat.java +++ b/visualiser/src/main/java/seng302/Model/Boat.java @@ -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 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 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; } /** diff --git a/visualiser/src/main/java/seng302/Model/BoatInRace.java b/visualiser/src/main/java/seng302/Model/BoatInRace.java index 3cc3f8d7..8bc42ca5 100644 --- a/visualiser/src/main/java/seng302/Model/BoatInRace.java +++ b/visualiser/src/main/java/seng302/Model/BoatInRace.java @@ -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 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 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; } /** diff --git a/visualiser/src/main/java/seng302/Model/ConstantVelocityRace.java b/visualiser/src/main/java/seng302/Model/ConstantVelocityRace.java index 47e699b3..fefc0755 100644 --- a/visualiser/src/main/java/seng302/Model/ConstantVelocityRace.java +++ b/visualiser/src/main/java/seng302/Model/ConstantVelocityRace.java @@ -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 diff --git a/visualiser/src/main/java/seng302/Model/Leg.java b/visualiser/src/main/java/seng302/Model/Leg.java index 1f4f5292..fd596704 100644 --- a/visualiser/src/main/java/seng302/Model/Leg.java +++ b/visualiser/src/main/java/seng302/Model/Leg.java @@ -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 diff --git a/visualiser/src/main/java/seng302/Model/Marker.java b/visualiser/src/main/java/seng302/Model/Marker.java index ec46edb2..8b432d70 100644 --- a/visualiser/src/main/java/seng302/Model/Marker.java +++ b/visualiser/src/main/java/seng302/Model/Marker.java @@ -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) { diff --git a/visualiser/src/main/java/seng302/Model/Race.java b/visualiser/src/main/java/seng302/Model/Race.java index 2c1a66fa..13e0463e 100644 --- a/visualiser/src/main/java/seng302/Model/Race.java +++ b/visualiser/src/main/java/seng302/Model/Race.java @@ -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 startingBoats; - protected List legs; - protected RaceController controller; + protected final ObservableList startingBoats; + protected final List 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 boats, List legs, RaceController controller, int scaleFactor) { + private Race(List boats, List 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); } diff --git a/visualiser/src/main/java/seng302/Model/RaceClock.java b/visualiser/src/main/java/seng302/Model/RaceClock.java index e5af8fae..bef6c206 100644 --- a/visualiser/src/main/java/seng302/Model/RaceClock.java +++ b/visualiser/src/main/java/seng302/Model/RaceClock.java @@ -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); diff --git a/visualiser/src/main/java/seng302/Model/ResizableCanvas.java b/visualiser/src/main/java/seng302/Model/ResizableCanvas.java index 2067cf4f..1dab2aa6 100644 --- a/visualiser/src/main/java/seng302/Model/ResizableCanvas.java +++ b/visualiser/src/main/java/seng302/Model/ResizableCanvas.java @@ -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(); diff --git a/visualiser/src/main/java/seng302/Model/ResizableRaceCanvas.java b/visualiser/src/main/java/seng302/Model/ResizableRaceCanvas.java index 0535f965..2b793da9 100644 --- a/visualiser/src/main/java/seng302/Model/ResizableRaceCanvas.java +++ b/visualiser/src/main/java/seng302/Model/ResizableRaceCanvas.java @@ -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 colours; - private List markers; + private final List 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(Arrays.asList( + colours = new ArrayList<>(Arrays.asList( Color.BLUEVIOLET, Color.BLACK, Color.RED, diff --git a/visualiser/src/main/java/seng302/Model/ResizableRaceMap.java b/visualiser/src/main/java/seng302/Model/ResizableRaceMap.java index 25774746..7db9b132 100644 --- a/visualiser/src/main/java/seng302/Model/ResizableRaceMap.java +++ b/visualiser/src/main/java/seng302/Model/ResizableRaceMap.java @@ -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 raceBoundaries; - double[] xpoints = {}, ypoints = {}; + private final List 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++) { diff --git a/visualiser/src/main/java/seng302/Model/TrackPoint.java b/visualiser/src/main/java/seng302/Model/TrackPoint.java index 80ffd1d0..1a2007cf 100644 --- a/visualiser/src/main/java/seng302/Model/TrackPoint.java +++ b/visualiser/src/main/java/seng302/Model/TrackPoint.java @@ -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. diff --git a/visualiser/src/main/java/seng302/RaceConnection.java b/visualiser/src/main/java/seng302/RaceConnection.java index 773fc367..da104741 100644 --- a/visualiser/src/main/java/seng302/RaceConnection.java +++ b/visualiser/src/main/java/seng302/RaceConnection.java @@ -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; diff --git a/visualiser/src/main/java/seng302/RaceDataSource.java b/visualiser/src/main/java/seng302/RaceDataSource.java index d244d8ad..5f2e52ad 100644 --- a/visualiser/src/main/java/seng302/RaceDataSource.java +++ b/visualiser/src/main/java/seng302/RaceDataSource.java @@ -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. diff --git a/visualiser/src/main/java/seng302/RaceMap.java b/visualiser/src/main/java/seng302/RaceMap.java index 0ccf9a6d..cbd9f2a4 100644 --- a/visualiser/src/main/java/seng302/RaceMap.java +++ b/visualiser/src/main/java/seng302/RaceMap.java @@ -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) { diff --git a/visualiser/src/main/java/seng302/RaceXMLReader.java b/visualiser/src/main/java/seng302/RaceXMLReader.java index 8be2b022..ddab0b27 100644 --- a/visualiser/src/main/java/seng302/RaceXMLReader.java +++ b/visualiser/src/main/java/seng302/RaceXMLReader.java @@ -17,16 +17,15 @@ import java.util.List; * @deprecated use {@link seng302.Mock.StreamedCourseXMLReader} */ public class RaceXMLReader extends XMLReader implements RaceDataSource { - private List 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 legs = new ArrayList<>(); + private final List 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 legs = new ArrayList<>(); private GPSCoordinate mark, startPt1, startPt2, finishPt1, finishPt2, leewardPt1, leewardPt2, windwardPt1, windwardPt2; private GPSCoordinate mapTopLeft, mapBottomRight; - private List boundary = new ArrayList<>(); - private static double COORDINATEPADDING = 0.0005; + private final List 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); diff --git a/visualiser/src/main/java/seng302/VisualiserInput.java b/visualiser/src/main/java/seng302/VisualiserInput.java index 41f0dc75..ffba53c3 100644 --- a/visualiser/src/main/java/seng302/VisualiserInput.java +++ b/visualiser/src/main/java/seng302/VisualiserInput.java @@ -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 messagesReceivedQueue = new ArrayBlockingQueue<>(1000000);//We have room for 1,000,000. Is this much capacity actually needed? + private final ArrayBlockingQueue 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 boatStatusMap = new HashMap<>();; + private final Map boatStatusMap = new HashMap<>(); ///A map of the last BoatLocation message received, for each boat. - private Map boatLocationMap = new HashMap<>(); + private final Map 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 markRoundingMap = new HashMap<>(); - - ///The last RaceStartStatus message received. - private RaceStartStatus raceStartStatus; + private final Map 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. diff --git a/visualiser/src/main/java/seng302/XMLReader.java b/visualiser/src/main/java/seng302/XMLReader.java index a6935ae2..67253791 100644 --- a/visualiser/src/main/java/seng302/XMLReader.java +++ b/visualiser/src/main/java/seng302/XMLReader.java @@ -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; } diff --git a/visualiser/src/main/resources/scenes/connect.fxml b/visualiser/src/main/resources/scenes/connect.fxml index 86c25190..3b0ed923 100644 --- a/visualiser/src/main/resources/scenes/connect.fxml +++ b/visualiser/src/main/resources/scenes/connect.fxml @@ -1,21 +1,9 @@ - - - - - - - - - - - - diff --git a/visualiser/src/main/resources/scenes/finish.fxml b/visualiser/src/main/resources/scenes/finish.fxml index 9237d753..0dcaf719 100644 --- a/visualiser/src/main/resources/scenes/finish.fxml +++ b/visualiser/src/main/resources/scenes/finish.fxml @@ -1,19 +1,8 @@ - - - - - - - - - - - diff --git a/visualiser/src/main/resources/scenes/main.fxml b/visualiser/src/main/resources/scenes/main.fxml index f03b37f0..b538e1c6 100644 --- a/visualiser/src/main/resources/scenes/main.fxml +++ b/visualiser/src/main/resources/scenes/main.fxml @@ -1,7 +1,6 @@ - diff --git a/visualiser/src/main/resources/scenes/start.fxml b/visualiser/src/main/resources/scenes/start.fxml index 76d18fef..b56945e2 100644 --- a/visualiser/src/main/resources/scenes/start.fxml +++ b/visualiser/src/main/resources/scenes/start.fxml @@ -1,19 +1,8 @@ - - - - - - - - - - - diff --git a/visualiser/src/test/java/seng302/Mock/BoatsXMLTest.java b/visualiser/src/test/java/seng302/Mock/BoatsXMLTest.java index ed795d5a..985473f5 100644 --- a/visualiser/src/test/java/seng302/Mock/BoatsXMLTest.java +++ b/visualiser/src/test/java/seng302/Mock/BoatsXMLTest.java @@ -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() { diff --git a/visualiser/src/test/java/seng302/Mock/FailBoatXMLTest.java b/visualiser/src/test/java/seng302/Mock/FailBoatXMLTest.java index d055d410..02c7bdce 100644 --- a/visualiser/src/test/java/seng302/Mock/FailBoatXMLTest.java +++ b/visualiser/src/test/java/seng302/Mock/FailBoatXMLTest.java @@ -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 { diff --git a/visualiser/src/test/java/seng302/Mock/RegattaXMLTest.java b/visualiser/src/test/java/seng302/Mock/RegattaXMLTest.java index 6b708ccb..c8cadb39 100644 --- a/visualiser/src/test/java/seng302/Mock/RegattaXMLTest.java +++ b/visualiser/src/test/java/seng302/Mock/RegattaXMLTest.java @@ -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. diff --git a/visualiser/src/test/java/seng302/Mock/StreamedRaceTest.java b/visualiser/src/test/java/seng302/Mock/StreamedRaceTest.java index 4abe29c4..946f9d93 100644 --- a/visualiser/src/test/java/seng302/Mock/StreamedRaceTest.java +++ b/visualiser/src/test/java/seng302/Mock/StreamedRaceTest.java @@ -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 boundary; + private StreamedCourseXMLReader streamedCourseXMLReader; + private List 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(); } } diff --git a/visualiser/src/test/java/seng302/Model/BoatInRaceTest.java b/visualiser/src/test/java/seng302/Model/BoatInRaceTest.java index 446b32a6..029a0f43 100644 --- a/visualiser/src/test/java/seng302/Model/BoatInRaceTest.java +++ b/visualiser/src/test/java/seng302/Model/BoatInRaceTest.java @@ -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 diff --git a/visualiser/src/test/java/seng302/Model/LegTest.java b/visualiser/src/test/java/seng302/Model/LegTest.java index 6deab58a..470d3168 100644 --- a/visualiser/src/test/java/seng302/Model/LegTest.java +++ b/visualiser/src/test/java/seng302/Model/LegTest.java @@ -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() { diff --git a/visualiser/src/test/java/seng302/Model/MarkerTest.java b/visualiser/src/test/java/seng302/Model/MarkerTest.java index 1fcfcf5d..420c5eff 100644 --- a/visualiser/src/test/java/seng302/Model/MarkerTest.java +++ b/visualiser/src/test/java/seng302/Model/MarkerTest.java @@ -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() { diff --git a/visualiser/src/test/java/seng302/Model/RaceXMLTest.java b/visualiser/src/test/java/seng302/Model/RaceXMLTest.java index 21b6ff3f..7b48218c 100644 --- a/visualiser/src/test/java/seng302/Model/RaceXMLTest.java +++ b/visualiser/src/test/java/seng302/Model/RaceXMLTest.java @@ -1,4 +1,5 @@ -package seng302.Model;/** +package seng302.Model; +/** * Created by Gondr on 26/03/2017. */