@ -43,7 +43,7 @@ public class MockRace extends RaceState {
/ * *
/ * *
* Registry for all collider object in this race
* Registry for all collider object in this race
* /
* /
pr otected ColliderRegistry colliderRegistry ;
pr ivate ColliderRegistry colliderRegistry ;
/ * *
/ * *
@ -58,6 +58,12 @@ public class MockRace extends RaceState {
private WindGenerator windGenerator ;
private WindGenerator windGenerator ;
/ * *
* The polars file to use for each boat .
* /
private Polars polars ;
/ * *
/ * *
* Constructs a race object with a given RaceDataSource , BoatDataSource , and RegattaDataSource and sends events to the given mockOutput .
* Constructs a race object with a given RaceDataSource , BoatDataSource , and RegattaDataSource and sends events to the given mockOutput .
@ -74,9 +80,10 @@ public class MockRace extends RaceState {
this . setRaceDataSource ( raceDataSource ) ;
this . setRaceDataSource ( raceDataSource ) ;
this . setRegattaDataSource ( regattaDataSource ) ;
this . setRegattaDataSource ( regattaDataSource ) ;
this . polars = polars ;
this . scaleFactor = timeScale ;
this . scaleFactor = timeScale ;
this . boats = this. generateMockBoats ( boatDataSource . getBoats ( ) , raceDataSource . getParticipants ( ) , polars ) ;
this . boats = new ArrayList < > ( ) ;
this . shrinkBoundary = GPSCoordinate . getShrinkBoundary ( this . getBoundary ( ) ) ;
this . shrinkBoundary = GPSCoordinate . getShrinkBoundary ( this . getBoundary ( ) ) ;
@ -100,31 +107,35 @@ public class MockRace extends RaceState {
/ * *
/ * *
* Generates a list of MockBoats given a list of Boats , and a list of participating boats .
* Generates a MockBoat from the BoatDataSource , given a source ID . Also adds it to the participant list .
* @param boats The map of Boats describing boats that are potentially in the race . Maps boat sourceID to boat .
* @param sourceID The source ID to assign the boat .
* @param sourceIDs The list of boat sourceIDs describing which specific boats are actually participating .
* @return A MockBoat that is now participating in the race .
* @param polars The polars table to be used for boat simulation .
* @return A list of MockBoats that are participating in the race .
* /
* /
private List < MockBoat > generateMockBoats ( Map < Integer , Boat > boats , List < Integer > sourceIDs , Polars polars ) {
public void generateMockBoat ( Integer sourceID ) {
List < MockBoat > mockBoats = new ArrayList < > ( sourceIDs . size ( ) ) ;
// For each sourceID participating.. .
//Get the boat associated with the sourceID.
for ( int sourceID : sourceIDs ) {
Boat boat = getBoatDataSource ( ) . getBoats ( ) . get ( sourceID ) ;
//Get the boat associated with the sourceID.
//Construct a MockBoat using the Boat and Polars.
Boat boat = boats . get ( sourceID ) ;
MockBoat mockBoat = new MockBoat ( boat , polars ) ;
mockBoat . setCurrentLeg ( this . getLegs ( ) . get ( 0 ) ) ;
//Construct a MockBoat using the Boat and Polars .
//Update participant list .
MockBoat mockBoat = new MockBoat ( boat , polars ) ;
getRaceDataSource ( ) . getParticipants ( ) . add ( sourceID ) ;
mockB oats. add ( mockBoat ) ;
this . b oats. add ( mockBoat ) ;
}
getRaceDataSource ( ) . incrementSequenceNumber ( ) ;
}
return mockBoats ;
/ * *
* Removes a MockBoat from the race , by sourceID . Also removes it from the participant list .
* @param sourceID Source ID of boat to remove .
* /
public void removeMockBoat ( Integer sourceID ) {
this . boats . removeIf ( mockBoat - > mockBoat . getSourceID ( ) = = sourceID ) ;
getRaceDataSource ( ) . getParticipants ( ) . remove ( sourceID ) ;
getRaceDataSource ( ) . incrementSequenceNumber ( ) ;
}
}