Moved several classes from seng302.model to its own module - sharedModel (this is supposed to contain any shared data model code between mock and visualiser). Specifically, Regatta, Boat, BoatInRace, Constants, GPSCoordinate, Leg, Marker.

Updated RaceVisionByteEncoder.raceStatus to accept a Racestatus object rather than a bunch of parameters.
Added getters to RaceStatus class.
Updated some tests.
Removed Network tests from Mock, as they were duplicated.
This commit is contained in:
fjc40
2017-04-28 01:27:45 +12:00
parent 50cb31b85f
commit 90f8bec415
56 changed files with 624 additions and 2749 deletions
+155
View File
@@ -0,0 +1,155 @@
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>seng302</groupId>
<artifactId>team-7</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<packaging>jar</packaging>
<name>sharedModel</name>
<artifactId>sharedModel</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-all -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-referencing</artifactId>
<version>9.0</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>maven2-repository.dev.java.net</id>
<name>Java.net repository</name>
<url>http://download.java.net/maven/2</url>
</repository>
<repository>
<id>osgeo</id>
<name>Open Source Geospatial Foundation Repository</name>
<url>http://download.osgeo.org/webdav/geotools/</url>
</repository>
</repositories>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>seng302.App</Main-Class>
<X-Compile-Source-JDK>${maven.compiler.source}</X-Compile-Source-JDK>
<X-Compile-Target-JDK>${maven.compiler.target}</X-Compile-Target-JDK>
</manifestEntries>
</transformer>
</transformers>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>2.5</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.6</version>
<configuration>
<linkXRef>true</linkXRef>
<targetJdk>${maven.compiler.target}</targetJdk>
<rulesets>
<ruleset>/rulesets/java/basic.xml</ruleset>
<ruleset>/rulesets/java/imports.xml</ruleset>
<ruleset>/rulesets/java/codesize.xml</ruleset>
<ruleset>/rulesets/java/design.xml</ruleset>
<ruleset>/rulesets/java/empty.xml</ruleset>
<ruleset>/rulesets/java/junit.xml</ruleset>
<ruleset>/rulesets/java/unusedcode.xml</ruleset>
</rulesets>
<includeXmlInSite>true</includeXmlInSite>
<sourceEncoding>utf-8</sourceEncoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.3</version>
<configuration>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.19.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.8.1</version>
</plugin>
</plugins>
</reporting>
</project>
@@ -0,0 +1,92 @@
package SharedModel;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
/**
* Created by fwy13 on 3/03/17.
*/
public class Boat {
private StringProperty name;
private double velocity;
private StringProperty velocityProp;
private String abbrev;
private int sourceID;
/**
* Boat initialiser 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.
* @param abbrev nam abbreviation
*/
public Boat(String name, double velocity, String abbrev, int sourceID) {
this.velocity = velocity;
this.velocityProp = new SimpleStringProperty(String.valueOf(Math.round(velocity)));
this.abbrev = abbrev;
this.name = new SimpleStringProperty(name);
this.sourceID = sourceID;
}
/**
* @return Name of the boat
*/
public StringProperty getName() {
return name;
}
/**
* Sets the boat name
*
* @param name of boat
*/
public void setName(String name) {
this.name.setValue(name);
}
/**
* @return Speed of the boat.
*/
public double getVelocity() {
return velocity;
}
/**
* Sets the speed of the boat in knots.
*
* @param velocity speed in knots
*/
public void setVelocity(double velocity) {
this.velocity = velocity;
this.velocityProp.setValue(String.valueOf(Math.round(velocity)));
}
public int getSourceID() {
return sourceID;
}
/**
* Print method prints the name of the boat
*
* @return Name of the boat.
*/
public String toString() {
return getName().getValue();
}
/**
* @return Velocity String Property of the boat
*/
public StringProperty getVelocityProp() {
return velocityProp;
}
/**
* @return Abbreviation of the boat
*/
public String getAbbrev() {
return abbrev;
}
}
@@ -0,0 +1,280 @@
package SharedModel;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.scene.paint.Color;
import org.geotools.referencing.GeodeticCalculator;
import java.awt.geom.Point2D;
/**
* Boat in the Race extends Boat.
* Created by esa46 on 15/03/17.
*/
public class BoatInRace extends Boat {
private Leg currentLeg;
private double scaledVelocity;
private double distanceTravelledInLeg;
private GPSCoordinate currentPosition;
private long timeFinished;
private Color colour;
private boolean finished = false;
private StringProperty currentLegName;
private boolean started = false;
private StringProperty position;
private double heading;
///While generating BoatLocationMessages, each one needs a sequence number relating to each boat.
private long sequenceNumber = 0;
private boolean trackVisible = true;
/**
* Constructor method.
*
* @param name Name of the boat.
* @param velocity Speed that the boat travels.
* @param colour Colour the boat will be displayed as on the map
* @param abbrev of boat
*/
public BoatInRace(String name, double velocity, Color colour, String abbrev, int sourceID) {
super(name, velocity, abbrev, sourceID);
setColour(colour);
currentLegName = new SimpleStringProperty("");
position = new SimpleStringProperty("-");
}
/**
* Converts an azimuth to a bearing
*
* @param azimuth azimuth value to be converted
* @return the bearings in degrees (0 to 360).
*/
public static double calculateHeading(double azimuth) {
if (azimuth >= 0) {
return azimuth;
} else {
return azimuth + 360;
}
}
/**
* Calculates the azimuth of the travel via map coordinates of the raceMarkers
*
* @return the direction that the boat is heading towards in degrees (-180 to 180).
*/
public double calculateAzimuth() {
GeodeticCalculator calc = new GeodeticCalculator();
GPSCoordinate start = currentLeg.getStartMarker().getAverageGPSCoordinate();
GPSCoordinate end = currentLeg.getEndMarker().getAverageGPSCoordinate();
calc.setStartingGeographicPoint(start.getLongitude(), start.getLatitude());
calc.setDestinationGeographicPoint(end.getLongitude(), end.getLatitude());
return calc.getAzimuth();
}
public double getHeading() {
return heading;
}
public void setHeading(double heading) {
this.heading = heading;
}
/**
* Calculates the bearing of the travel via map coordinates of the raceMarkers
*
* @return the direction that the boat is heading towards in degrees (0 to 360).
*/
public double calculateHeading() {
double azimuth = this.calculateAzimuth();
return calculateHeading(azimuth);
}
/**
* Returns the position of the end of the boat's wake, which is 180 degrees
* from the boat's heading, and whose length is proportional to the boat's
* speed.
*
* @return GPSCoordinate of wake endpoint.
*/
public GPSCoordinate getWake() {
double reverseHeading = getHeading() - 180;
double distance = Constants.wakeScale * getVelocity();
GeodeticCalculator calc = new GeodeticCalculator();
calc.setStartingGeographicPoint(
new Point2D.Double(getCurrentPosition().getLongitude(), getCurrentPosition().getLatitude())
);
calc.setDirection(reverseHeading, distance);
Point2D endpoint = calc.getDestinationGeographicPoint();
return new GPSCoordinate(endpoint.getY(), endpoint.getX());
}
/**
* @return Scaled velocity of the boat
*/
public double getScaledVelocity() {
return scaledVelocity;
}
/**
* Sets the boat's scaled velocity
*
* @param velocity of boat
*/
public void setScaledVelocity(double velocity) {
this.scaledVelocity = velocity;
}
/**
* @return Returns the current position of the boat in a GPSCoordinate Class.
* @see GPSCoordinate
*/
public GPSCoordinate getCurrentPosition() {
return currentPosition;
}
/**
* Sets the current position on the GPS that the boat.
*
* @param position GPSCoordinate of the position that the boat is currently on.
* @see GPSCoordinate
*/
public void setCurrentPosition(GPSCoordinate position) {
this.currentPosition = position;
}
/**
* @return Returns the time that the boat finished the race.
*/
public long getTimeFinished() {
return timeFinished;
}
/**
* Sets the time that the boat finished the race.
*
* @param timeFinished Time the boat finished the race.
*/
public void setTimeFinished(long timeFinished) {
this.timeFinished = timeFinished;
}
/**
* @return Returns the colour of the boat.
*/
public Color getColour() {
return colour;
}
/**
* Sets the colour that boat will be shown as when drawn on the ResizableRaceCanvas.
*
* @param colour Colour that the boat is to be set to.
*/
public void setColour(Color colour) {
this.colour = colour;
}
/**
* Gets the current leg that the boat is on.
*
* @return returns the leg the boat is on in a Leg class
* @see Leg
*/
public Leg getCurrentLeg() {
return currentLeg;
}
/**
* Sets the boat's current leg.
*
* @param currentLeg Leg class that the boat is currently on.
* @see Leg
*/
public void setCurrentLeg(Leg currentLeg) {
this.currentLeg = currentLeg;
this.currentLegName.setValue(currentLeg.getName());
}
/**
* @return Name of boat's current leg
*/
public StringProperty getCurrentLegName() {
return currentLegName;
}
/**
* Gets the distance travelled by the boat in the leg.
*
* @return Returns the value in nautical miles (1.852km) that the boat has traversed.
*/
public double getDistanceTravelledInLeg() {
return distanceTravelledInLeg;
}
/**
* Sets the distance travelled by the boat in the leg in nautical miles (1.852km)
*
* @param distanceTravelledInLeg Distance travelled by the boat in nautical miles.
*/
public void setDistanceTravelledInLeg(double distanceTravelledInLeg) {
this.distanceTravelledInLeg = distanceTravelledInLeg;
}
/**
* @return true if boat has finished, false if not
*/
public boolean isFinished() {
return this.finished;
}
/**
* Sets whether boat is finished or not
*
* @param bool is finished value
*/
public void setFinished(boolean bool) {
this.finished = bool;
}
public boolean isStarted() {
return started;
}
public void setStarted(boolean started) {
this.started = started;
}
public String getPosition() {
return position.get();
}
public void setPosition(String position) {
this.position.set(position);
}
public StringProperty positionProperty() {
return position;
}
/**
* Returns the current sequence number, and increments the internal value, such that that next call will return a value 1 larger than the current call.
*
* @return Current sequence number.
*/
public long getNextSequenceNumber() {
//Make a copy of current value.
long oldNumber = this.sequenceNumber;
//Increment.
this.sequenceNumber += 1;
//Return the previous value.
return oldNumber;
}
}
@@ -0,0 +1,16 @@
package SharedModel;
/**
* Constants that are used throughout the program
* Created by Erika on 19-Mar-17.
*/
public class Constants {
public static final int NMToMetersConversion = 1852; // 1 nautical mile = 1852 meters
//Knots x this = meters per second.
public static final double KnotsToMetersPerSecondConversionFactor = 0.514444;
public static final double wakeScale = 10;
}
@@ -0,0 +1,72 @@
package SharedModel;
/**
* GPS Coordinate for the world map.
* Created by esa46 on 15/03/17.
*/
public class GPSCoordinate {
private double latitude;
private double longitude;
/**
* Constructor Method
*
* @param latitude latitude the coordinate is located at.
* @param longitude Longitude that the coordinate is located at.
*/
public GPSCoordinate(double latitude, double longitude) {
this.latitude = latitude;
this.longitude = longitude;
}
/**
* Gets the Latitude that the Coordinate is at.
*
* @return Returns the latitude of the Coordinate.
*/
public double getLatitude() {
return latitude;
}
/**
* Gets the Longitude that the Coordinate is at.
*
* @return Returns the longitude of the Coordinate.
*/
public double getLongitude() {
return longitude;
}
/**
* To String method of the Coordinate in the form Latitude: $f, Longitude: $f.
*
* @return A String representation of the GPSCoordinate Class.
*/
public String toString() {
return String.format("Latitude: %f, Longitude: %f", latitude, longitude);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
GPSCoordinate that = (GPSCoordinate) o;
if (Math.abs(this.latitude - that.latitude) > 1e-7) return false;
return (Math.abs(this.longitude - that.longitude) < 1e-7);
}
@Override
public int hashCode() {
int result;
long temp;
temp = Double.doubleToLongBits(latitude);
result = (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(longitude);
result = 31 * result + (int) (temp ^ (temp >>> 32));
return result;
}
}
@@ -0,0 +1,103 @@
package SharedModel;
import org.geotools.referencing.GeodeticCalculator;
/**
* Created by cbt24 on 6/03/17.
*/
public class Leg {
private String name; //nautical miles
private double distance;
private Marker startMarker;
private Marker endMarker;
private int legNumber;
/**
* Leg Initialiser
*
* @param name Name of the Leg
* @param start marker
* @param end marker
* @param number Leg's position in race
*/
public Leg(String name, Marker start, Marker end, int number) {
this.name = name;
this.startMarker = start;
this.endMarker = end;
this.legNumber = number;
calculateDistance();
}
/**
* Construction Method
*
* @param name Name of the Leg
* @param number leg number
*/
public Leg(String name, int number) {
this.name = name;
this.legNumber = number;
}
/**
* Returns the name of the Leg
*
* @return Returns the name of the Leg
*/
public String getName() {
return name;
}
/**
* Get the distance in nautical miles
*
* @return Returns the total distance of the leg.
*/
public double getDistance() {
return distance;
}
/**
* Returns the leg number that the leg exists in the Race
*
* @return Returns the Leg
* @see Race
*/
public int getLegNumber() {
return legNumber;
}
public Marker getStartMarker() {
return startMarker;
}
public void setStartMarker(Marker startMarker) {
this.startMarker = startMarker;
}
public Marker getEndMarker() {
return endMarker;
}
public void setEndMarker(Marker endMarker) {
this.endMarker = endMarker;
}
/**
* Calculates the distance that the legs are in nautical miles (1.852 km).
*/
public void calculateDistance() {
GeodeticCalculator calc = new GeodeticCalculator();
//Load start and end of leg
GPSCoordinate startMarker = this.startMarker.getAverageGPSCoordinate();
GPSCoordinate endMarker = this.endMarker.getAverageGPSCoordinate();
calc.setStartingGeographicPoint(startMarker.getLongitude(), startMarker.getLatitude());
calc.setDestinationGeographicPoint(endMarker.getLongitude(), endMarker.getLatitude());
this.distance = calc.getOrthodromicDistance() / Constants.NMToMetersConversion;
}
}
@@ -0,0 +1,75 @@
package SharedModel;
import org.geotools.referencing.GeodeticCalculator;
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 String name;
private boolean doubleMarker = false;
public Marker(GPSCoordinate mark1) {
this.mark1 = mark1;
this.mark2 = mark1;
this.averageGPSCoordinate = calculateAverage();
}
public Marker(GPSCoordinate mark1, GPSCoordinate mark2) {
this.mark1 = mark1;
this.mark2 = mark2;
this.averageGPSCoordinate = calculateAverage();
}
public Marker(String name, GPSCoordinate mark1, GPSCoordinate mark2) {
this.name = name;
this.mark1 = mark1;
this.mark2 = mark2;
this.averageGPSCoordinate = calculateAverage();
}
public GPSCoordinate getMark1() {
return mark1;
}
public GPSCoordinate getMark2() {
return mark2;
}
public GPSCoordinate getAverageGPSCoordinate() {
return averageGPSCoordinate;
}
public String getName() {
return name;
}
private GPSCoordinate calculateAverage() {
GeodeticCalculator calc = new GeodeticCalculator();
calc.setStartingGeographicPoint(mark1.getLongitude(), mark1.getLatitude());
calc.setDestinationGeographicPoint(mark2.getLongitude(), mark2.getLatitude());
double azimuth = calc.getAzimuth();
double distance = calc.getOrthodromicDistance();
GeodeticCalculator middleCalc = new GeodeticCalculator();
middleCalc.setStartingGeographicPoint(mark1.getLongitude(), mark1.getLatitude());
middleCalc.setDirection(azimuth, distance / 2);
Point2D middlePoint = middleCalc.getDestinationGeographicPoint();
return new GPSCoordinate(middlePoint.getY(), middlePoint.getX());
}
}
@@ -0,0 +1,99 @@
package SharedModel;
/**
* Created by jjg64 on 19/04/17.
*/
public class Regatta {
int regattaID;
String RegattaName;
int raceID = 0;
String courseName;
double centralLatitude;
double centralLongitude;
double centralAltitude;
float utcOffset;
float magneticVariation;
public Regatta(int regattaID, String regattaName, String courseName, double centralLatitude, double centralLongitude, double centralAltitude, float utcOffset, float magneticVariation) {
this.regattaID = regattaID;
this.RegattaName = regattaName;
this.courseName = courseName;
this.centralLatitude = centralLatitude;
this.centralLongitude = centralLongitude;
this.centralAltitude = centralAltitude;
this.utcOffset = utcOffset;
this.magneticVariation = magneticVariation;
}
public int getRegattaID() {
return regattaID;
}
public void setRegattaID(int ID) {
this.regattaID = ID;
}
public String getRegattaName() {
return RegattaName;
}
public void setRegattaName(String regattaName) {
RegattaName = regattaName;
}
public int getRaceID() {
return raceID;
}
public void setRaceID(int raceID) {
this.raceID = raceID;
}
public String getCourseName() {
return courseName;
}
public void setCourseName(String courseName) {
this.courseName = courseName;
}
public double getCentralLatitude() {
return centralLatitude;
}
public void setCentralLatitude(double centralLatitude) {
this.centralLatitude = centralLatitude;
}
public double getCentralLongitude() {
return centralLongitude;
}
public void setCentralLongitude(double centralLongitude) {
this.centralLongitude = centralLongitude;
}
public double getCentralAltitude() {
return centralAltitude;
}
public void setCentralAltitude(double centralAltitude) {
this.centralAltitude = centralAltitude;
}
public float getUtcOffset() {
return utcOffset;
}
public void setUtcOffset(float utcOffset) {
this.utcOffset = utcOffset;
}
public float getMagneticVariation() {
return magneticVariation;
}
public void setMagneticVariation(float magneticVariation) {
this.magneticVariation = magneticVariation;
}
}
@@ -0,0 +1,13 @@
package seng302;
/**
* Created by f123 on 27-Apr-17.
*/
public class App {
public static void main(String[] args) {
}
}