Class CaptainsState
- java.lang.Object
-
- ch.sahits.game.openpatrician.model.people.impl.CaptainsState
-
@Component @Lazy @DependentInitialisation(StartNewGameBean.class) public class CaptainsState extends java.lang.Object
Containing the states of the captains- Author:
- Andi Hotz, (c) Sahits GmbH, 2013 Created on Feb 2, 2013
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<CaptainTownMapping>
captainMapping
private CaptainProperties
captainProperties
private java.util.List<ICaptain>
captains
private Date
date
private IMap
map
private java.util.Random
rnd
-
Constructor Summary
Constructors Constructor Description CaptainsState()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addCaptain(ICity city, java.time.LocalDateTime arrival, ICaptain captain)
void
assignCaptainToCity(ICaptain captain, ICity city, java.time.LocalDateTime arrivalDate)
Assign the captain to a new town.java.util.Optional<ICity>
findCaptainsCurrentCity(ICaptain captain)
Find the current city of a captain.java.util.List<ICaptain>
getAllFreeCaptains()
Retrieve a list of all captains that are not assigned to a town.java.time.LocalDateTime
getArrivalDate(ICaptain captain)
Retrieve the arrival date of a captain in a town.java.util.Optional<ICaptain>
getCaptain(ICity city)
Return a captain for a town if there is one.int
getMaxDaysPresent()
private ICity
getRandomCity()
void
hireCaptain(ICaptain captain, ICity city)
Remove the captain from the availables.
-
-
-
Field Detail
-
rnd
@Autowired private java.util.Random rnd
-
map
@Autowired private IMap map
-
captainProperties
@Autowired private CaptainProperties captainProperties
-
date
@Autowired private Date date
-
captainMapping
private java.util.List<CaptainTownMapping> captainMapping
-
captains
private java.util.List<ICaptain> captains
-
-
Method Detail
-
getRandomCity
private ICity getRandomCity()
-
assignCaptainToCity
public void assignCaptainToCity(ICaptain captain, ICity city, java.time.LocalDateTime arrivalDate)
Assign the captain to a new town. The arrival there is delayed due to traveling time.- Parameters:
city
- current town that the captain is leavingcaptain
- which travels to a new town.
-
getCaptain
public java.util.Optional<ICaptain> getCaptain(ICity city)
Return a captain for a town if there is one. There may be more than one.- Parameters:
city
- for which the captain is retrieved- Returns:
- absent if no captain is in the town.
-
getArrivalDate
public java.time.LocalDateTime getArrivalDate(ICaptain captain)
Retrieve the arrival date of a captain in a town. The captain must be present in a town, otherwise an IllegalStateException is thrown.- Parameters:
captain
- captain residing in a town- Returns:
- time of his arrival.
-
hireCaptain
public void hireCaptain(ICaptain captain, ICity city)
Remove the captain from the availables.- Parameters:
captain
- that is hired.city
- where the captain was hired.
-
getAllFreeCaptains
public java.util.List<ICaptain> getAllFreeCaptains()
Retrieve a list of all captains that are not assigned to a town.- Returns:
- List of all free captains
-
findCaptainsCurrentCity
public java.util.Optional<ICity> findCaptainsCurrentCity(ICaptain captain)
Find the current city of a captain.- Parameters:
captain
- for which city is checked- Returns:
- absent if the captain is in no town because he is hired on a ship.
-
getMaxDaysPresent
public int getMaxDaysPresent()
-
-