From d294ee7994b43a4301b06d3faeee4a46284b7360 Mon Sep 17 00:00:00 2001 From: Jessica McAuslin Date: Thu, 11 May 2017 15:44:58 +1200 Subject: [PATCH] Deleted redundant and deprecated code (Visualiser) - References to deprecated objects replaced - Deprecated Constants class removed - general redundant code deleted --- .../src/main/java/seng302/Constants.java | 34 ------------------- .../seng302/Controllers/StartController.java | 9 ----- .../java/seng302/Mock/StreamedCourse.java | 8 ----- .../seng302/Mock/StreamedCourseXMLReader.java | 24 ++----------- .../main/java/seng302/Mock/StreamedRace.java | 3 +- .../main/java/seng302/Model/BoatInRace.java | 4 +-- .../src/main/java/seng302/Model/Leg.java | 5 +-- .../main/java/seng302/Model/RaceClock.java | 7 ---- .../seng302/Model/ResizableRaceCanvas.java | 1 - .../main/java/seng302/VisualiserInput.java | 5 +-- .../src/test/java/seng302/Model/LegTest.java | 10 +++--- 11 files changed, 14 insertions(+), 96 deletions(-) delete mode 100644 visualiser/src/main/java/seng302/Constants.java diff --git a/visualiser/src/main/java/seng302/Constants.java b/visualiser/src/main/java/seng302/Constants.java deleted file mode 100644 index 096e5a2b..00000000 --- a/visualiser/src/main/java/seng302/Constants.java +++ /dev/null @@ -1,34 +0,0 @@ -package seng302; - -import javafx.scene.paint.Color; -import seng302.Model.BoatInRace; - -/** - * Constants that are used throughout the program - * Created by Erika on 19-Mar-17. - * @deprecated please use XML for constant data - */ -public class Constants { - - public static final int NMToMetersConversion = 1852; // 1 nautical mile = 1852 meters - - public static final GPSCoordinate startLineMarker1 = new GPSCoordinate(32.296577, -64.854304); - public static final GPSCoordinate startLineMarker2 = new GPSCoordinate(32.293771, -64.855242); - public static final GPSCoordinate mark1 = new GPSCoordinate(32.293039, -64.843983); - public static final GPSCoordinate windwardGate1 = new GPSCoordinate(32.284680, -64.850045); - public static final GPSCoordinate windwardGate2 = new GPSCoordinate(32.280164, -64.847591); - public static final GPSCoordinate leewardGate1 = new GPSCoordinate(32.309693, -64.835249); - public static final GPSCoordinate leewardGate2 = new GPSCoordinate(32.308046, -64.831785); - public static final GPSCoordinate finishLineMarker1 = new GPSCoordinate(32.317379, -64.839291); - public static final GPSCoordinate finishLineMarker2 = new GPSCoordinate(32.317257, -64.836260); - - public static final double wakeScale = 10; - - public static final BoatInRace[] OFFICIAL_AC35_COMPETITORS = new BoatInRace[] - {new BoatInRace("Oracle Team USA", 30.0, Color.BLUEVIOLET, "Oracle"), - new BoatInRace("Land Rover BAR", 23.0, Color.BLACK, "BGR"), - new BoatInRace("SoftBank Team Japan", 27.0, Color.RED, "JPN"), - new BoatInRace("Groupama Team France", 25.0, Color.ORANGE, "FRA"), - new BoatInRace("Artemis Racing", 22.5, Color.DARKOLIVEGREEN, "SWE"), - new BoatInRace("Emirates Team New Zealand", 62, Color.LIMEGREEN, "ETNZ")}; -} diff --git a/visualiser/src/main/java/seng302/Controllers/StartController.java b/visualiser/src/main/java/seng302/Controllers/StartController.java index f264cded..aaf6ae2a 100644 --- a/visualiser/src/main/java/seng302/Controllers/StartController.java +++ b/visualiser/src/main/java/seng302/Controllers/StartController.java @@ -19,7 +19,6 @@ import seng302.VisualiserInput; import java.io.IOException; import java.net.Socket; import java.net.URL; -import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.util.List; import java.util.Observable; @@ -43,8 +42,6 @@ public class StartController extends Controller implements Observer { @FXML private Label timer; @FXML private Label raceStatusLabel; - private ZonedDateTime startingTime; - //@FXML Button fifteenMinButton; private RaceClock raceClock; @@ -61,17 +58,11 @@ public class StartController extends Controller implements Observer { * Begins the race with a scale factor of 1 */ private void startRaceNoScaling() { - //startRace(1); while(visualiserInput.getRaceStatus() == null);//TODO probably remove this. countdownTimer(); } - private void startRace(int raceScale){ - //fifteenMinButton.setDisable(true); - //countdownTimer(raceScale); - } - @Override public void initialize(URL location, ResourceBundle resources){ raceData = new StreamedCourse(); diff --git a/visualiser/src/main/java/seng302/Mock/StreamedCourse.java b/visualiser/src/main/java/seng302/Mock/StreamedCourse.java index 04c89cfc..bcb4a90c 100644 --- a/visualiser/src/main/java/seng302/Mock/StreamedCourse.java +++ b/visualiser/src/main/java/seng302/Mock/StreamedCourse.java @@ -21,14 +21,6 @@ public class StreamedCourse extends Observable implements RaceDataSource { public StreamedCourse() {} - public StreamedCourse(StreamedCourseXMLReader streamedCourseXMLReader) { - this.streamedCourseXMLReader = streamedCourseXMLReader; - } - - public StreamedCourse(BoatXMLReader boatXMLReader) { - this.boatXMLReader = boatXMLReader; - } - public void setBoatXMLReader(BoatXMLReader boatXMLReader) { this.boatXMLReader = boatXMLReader; if (streamedCourseXMLReader != null && boatXMLReader != null) { diff --git a/visualiser/src/main/java/seng302/Mock/StreamedCourseXMLReader.java b/visualiser/src/main/java/seng302/Mock/StreamedCourseXMLReader.java index c8410562..d2cac2ad 100644 --- a/visualiser/src/main/java/seng302/Mock/StreamedCourseXMLReader.java +++ b/visualiser/src/main/java/seng302/Mock/StreamedCourseXMLReader.java @@ -13,7 +13,6 @@ import seng302.XMLReader; import javax.xml.parsers.ParserConfigurationException; import java.io.IOException; import java.io.InputStream; -import java.text.ParseException; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.util.*; @@ -35,19 +34,6 @@ public class StreamedCourseXMLReader extends XMLReader { private String raceType; private boolean postpone; - /** - * Constructor for Streamed Race XML - * @param filePath path of the file - * @throws IOException error - * @throws SAXException error - * @throws ParserConfigurationException error - * @throws ParseException error - * @throws StreamedCourseXMLException error - */ - public StreamedCourseXMLReader(String filePath) throws IOException, SAXException, ParserConfigurationException, ParseException, StreamedCourseXMLException { - this(filePath, true); - } - /** * Constructor for Streamed Race XML * @param filePath file path to read @@ -55,10 +41,9 @@ public class StreamedCourseXMLReader extends XMLReader { * @throws IOException error * @throws SAXException error * @throws ParserConfigurationException error - * @throws ParseException error * @throws StreamedCourseXMLException error */ - public StreamedCourseXMLReader(String filePath, boolean read) throws IOException, SAXException, ParserConfigurationException, ParseException, StreamedCourseXMLException { + public StreamedCourseXMLReader(String filePath, boolean read) throws IOException, SAXException, ParserConfigurationException, StreamedCourseXMLException { super(filePath); if (read) { read(); @@ -71,10 +56,9 @@ public class StreamedCourseXMLReader extends XMLReader { * @throws IOException error * @throws SAXException error * @throws ParserConfigurationException error - * @throws ParseException error * @throws StreamedCourseXMLException error */ - public StreamedCourseXMLReader(InputStream xmlString) throws IOException, SAXException, ParserConfigurationException, ParseException, StreamedCourseXMLException { + public StreamedCourseXMLReader(InputStream xmlString) throws IOException, SAXException, ParserConfigurationException, StreamedCourseXMLException { super(xmlString); read(); } @@ -268,10 +252,6 @@ public class StreamedCourseXMLReader extends XMLReader { return COORDINATEPADDING; } - public ZonedDateTime getCreationTimeDate() { - return creationTimeDate; - } - public ZonedDateTime getRaceStartTime() { return raceStartTime; } diff --git a/visualiser/src/main/java/seng302/Mock/StreamedRace.java b/visualiser/src/main/java/seng302/Mock/StreamedRace.java index 0856cb0c..5c06ddc1 100644 --- a/visualiser/src/main/java/seng302/Mock/StreamedRace.java +++ b/visualiser/src/main/java/seng302/Mock/StreamedRace.java @@ -27,8 +27,7 @@ public class StreamedRace extends Race { String name = officialStart.getName(); Marker endMarker = officialStart.getEndMarker(); - for (int i = 0; i < startingBoats.size(); i++) { - Boat boat = startingBoats.get(i); + for (Boat boat : startingBoats) { if (boat != null) { Leg startLeg = new Leg(name, 0); startLeg.setEndMarker(endMarker); diff --git a/visualiser/src/main/java/seng302/Model/BoatInRace.java b/visualiser/src/main/java/seng302/Model/BoatInRace.java index 274a8000..39087177 100644 --- a/visualiser/src/main/java/seng302/Model/BoatInRace.java +++ b/visualiser/src/main/java/seng302/Model/BoatInRace.java @@ -4,7 +4,6 @@ import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; import javafx.scene.paint.Color; import org.geotools.referencing.GeodeticCalculator; -import seng302.Constants; import seng302.GPSCoordinate; import java.awt.geom.Point2D; @@ -28,6 +27,7 @@ public class BoatInRace extends Boat { private boolean started = false; private final StringProperty position; private double heading; + private static final double WAKE_SCALE = 10; private final Queue track = new ConcurrentLinkedQueue<>(); private long nextValidTime = 0; @@ -108,7 +108,7 @@ public class BoatInRace extends Boat { */ public GPSCoordinate getWake() { double reverseHeading = getHeading() - 180; - double distance = Constants.wakeScale * getVelocity(); + double distance = WAKE_SCALE * getVelocity(); GeodeticCalculator calc = new GeodeticCalculator(); calc.setStartingGeographicPoint( diff --git a/visualiser/src/main/java/seng302/Model/Leg.java b/visualiser/src/main/java/seng302/Model/Leg.java index fd596704..3b394fd1 100644 --- a/visualiser/src/main/java/seng302/Model/Leg.java +++ b/visualiser/src/main/java/seng302/Model/Leg.java @@ -1,7 +1,6 @@ package seng302.Model; import org.geotools.referencing.GeodeticCalculator; -import seng302.Constants; import seng302.GPSCoordinate; /** @@ -13,6 +12,8 @@ public class Leg { private Marker startMarker; private Marker endMarker; private final int legNumber; + // 1 nautical mile = 1852 meters + public static final int NM_TO_METERS = 1852; /** * Leg Initializer @@ -97,7 +98,7 @@ public class Leg { GPSCoordinate endMarker = this.endMarker.getAverageGPSCoordinate(); calc.setStartingGeographicPoint(startMarker.getLongitude(), startMarker.getLatitude()); calc.setDestinationGeographicPoint(endMarker.getLongitude(), endMarker.getLatitude()); - this.distance = calc.getOrthodromicDistance() / Constants.NMToMetersConversion; + this.distance = calc.getOrthodromicDistance() / NM_TO_METERS; } diff --git a/visualiser/src/main/java/seng302/Model/RaceClock.java b/visualiser/src/main/java/seng302/Model/RaceClock.java index bef6c206..f17b9e12 100644 --- a/visualiser/src/main/java/seng302/Model/RaceClock.java +++ b/visualiser/src/main/java/seng302/Model/RaceClock.java @@ -34,13 +34,6 @@ public class RaceClock implements Runnable { setTime(time); } - public RaceClock(long utcTime, ZoneId zoneId) { - this.zoneId = zoneId; - this.timeString = new SimpleStringProperty(); - this.time = (new Date(utcTime)).toInstant().atZone(zoneId); - setTime(time); - } - public static ZonedDateTime getCurrentZonedDateTime(GPSCoordinate gpsCoordinate) { TimeZoneLookup timeZoneLookup = new TimeZoneLookup(); TimeZoneResult timeZoneResult = timeZoneLookup.getTimeZone(gpsCoordinate.getLatitude(), gpsCoordinate.getLongitude()); diff --git a/visualiser/src/main/java/seng302/Model/ResizableRaceCanvas.java b/visualiser/src/main/java/seng302/Model/ResizableRaceCanvas.java index e65a45c8..b4815d22 100644 --- a/visualiser/src/main/java/seng302/Model/ResizableRaceCanvas.java +++ b/visualiser/src/main/java/seng302/Model/ResizableRaceCanvas.java @@ -5,7 +5,6 @@ import javafx.collections.ObservableList; import javafx.scene.paint.Color; import javafx.scene.paint.Paint; import javafx.scene.transform.Rotate; -import seng302.GPSCoordinate; import seng302.GraphCoordinate; import seng302.Mock.StreamedCourse; import seng302.RaceDataSource; diff --git a/visualiser/src/main/java/seng302/VisualiserInput.java b/visualiser/src/main/java/seng302/VisualiserInput.java index d1fd53de..4f2b3ce9 100644 --- a/visualiser/src/main/java/seng302/VisualiserInput.java +++ b/visualiser/src/main/java/seng302/VisualiserInput.java @@ -1,7 +1,6 @@ package seng302; import org.xml.sax.SAXException; import seng302.Mock.*; -import seng302.Model.Boat; import seng302.Networking.BinaryMessageDecoder; import seng302.Networking.Exceptions.InvalidMessageException; import seng302.Networking.Messages.*; @@ -11,10 +10,8 @@ import java.io.DataInputStream; import java.io.IOException; import java.net.Socket; import java.nio.ByteBuffer; -import java.text.ParseException; import java.util.Arrays; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.concurrent.ArrayBlockingQueue; @@ -317,7 +314,7 @@ public class VisualiserInput implements Runnable { course.setStreamedCourseXMLReader(new StreamedCourseXMLReader(xmlMessage.getXmlMessage())); } //TODO REFACTOR should put all of these exceptions behind a StreamedCourseXMLReaderException. - catch (IOException | SAXException | ParserConfigurationException | ParseException | StreamedCourseXMLException e) { + catch (IOException | SAXException | ParserConfigurationException | StreamedCourseXMLException e) { System.err.println("Error creating StreamedCourseXMLReader: " + e.getMessage()); //Continue to the next loop iteration/message. } diff --git a/visualiser/src/test/java/seng302/Model/LegTest.java b/visualiser/src/test/java/seng302/Model/LegTest.java index 470d3168..30a68a64 100644 --- a/visualiser/src/test/java/seng302/Model/LegTest.java +++ b/visualiser/src/test/java/seng302/Model/LegTest.java @@ -2,12 +2,12 @@ package seng302.Model; import org.geotools.referencing.GeodeticCalculator; import org.junit.Test; -import seng302.Constants; import seng302.GPSCoordinate; import java.awt.geom.Point2D; import static junit.framework.TestCase.assertEquals; +import static seng302.Model.Leg.NM_TO_METERS; /** * Created by esa46 on 22/03/17. @@ -20,7 +20,7 @@ public class LegTest { public void calculateDistanceHandles5nmNorth() { GeodeticCalculator calc = new GeodeticCalculator(); calc.setStartingGeographicPoint(0, 0); - calc.setDirection(0, 5 * Constants.NMToMetersConversion); + calc.setDirection(0, 5 * NM_TO_METERS); Marker endMarker = getEndMarker(calc.getDestinationGeographicPoint()); Leg test = new Leg("Test", ORIGIN_MARKER, endMarker, 0); @@ -31,7 +31,7 @@ public class LegTest { public void calculateDistanceHandles12nmEast() { GeodeticCalculator calc = new GeodeticCalculator(); calc.setStartingGeographicPoint(0, 0); - calc.setDirection(90, 12 * Constants.NMToMetersConversion); + calc.setDirection(90, 12 * NM_TO_METERS); Marker endMarker = getEndMarker(calc.getDestinationGeographicPoint()); Leg test = new Leg("Test", ORIGIN_MARKER, endMarker, 0); @@ -42,7 +42,7 @@ public class LegTest { public void calculateDistanceHandlesHalfnmSouth() { GeodeticCalculator calc = new GeodeticCalculator(); calc.setStartingGeographicPoint(0, 0); - calc.setDirection(180, 0.5 * Constants.NMToMetersConversion); + calc.setDirection(180, 0.5 * NM_TO_METERS); Marker endMarker = getEndMarker(calc.getDestinationGeographicPoint()); Leg test = new Leg("Test", ORIGIN_MARKER, endMarker, 0); @@ -53,7 +53,7 @@ public class LegTest { public void calculateDistanceHandlesPoint1nmWest() { GeodeticCalculator calc = new GeodeticCalculator(); calc.setStartingGeographicPoint(0, 0); - calc.setDirection(-90, 0.1 * Constants.NMToMetersConversion); + calc.setDirection(-90, 0.1 * NM_TO_METERS); Marker endMarker = getEndMarker(calc.getDestinationGeographicPoint()); Leg test = new Leg("Test", ORIGIN_MARKER, endMarker, 0);