@ -9,6 +9,8 @@ import seng302.Constants;
import seng302.GPSCoordinate ;
import java.awt.geom.Point2D ;
import java.util.Queue ;
import java.util.concurrent.ConcurrentLinkedQueue ;
/ * *
* Boat in the Race extends Boat .
@ -26,6 +28,10 @@ public class BoatInRace extends Boat {
private StringProperty currentLegName ;
private boolean started = false ;
private StringProperty position ;
private Queue < GPSCoordinate > track = new ConcurrentLinkedQueue < GPSCoordinate > ( ) ;
private long nextValidTime = 0 ;
private final int TRACK_POINT_TIME_INTERVAL = 1000 ; // every 2 seconds
private final int TRACK_POINT_LIMIT = 10 ;
/ * *
* Constructor method .
@ -250,4 +256,20 @@ public class BoatInRace extends Boat {
public void setPosition ( int position ) {
this . position . set ( Integer . toString ( position + 1 ) ) ;
}
public boolean addTrackPoint ( GPSCoordinate coordinate ) {
Boolean added = System . currentTimeMillis ( ) > = nextValidTime ;
if ( added & & this . started & & ! this . finished ) {
nextValidTime = System . currentTimeMillis ( ) + TRACK_POINT_TIME_INTERVAL ;
track . add ( coordinate ) ;
if ( track . size ( ) > TRACK_POINT_LIMIT ) {
track . remove ( ) ;
}
}
return added ;
}
public Queue < GPSCoordinate > getTrack ( ) {
return track ;
}
}