Class CaptainsState

    • Field Detail

      • rnd

        @Autowired
        private java.util.Random rnd
      • map

        @Autowired
        private IMap map
      • date

        @Autowired
        private Date date
      • captains

        private java.util.List<ICaptain> captains
    • Constructor Detail

      • CaptainsState

        public CaptainsState()
    • Method Detail

      • addCaptain

        public void addCaptain​(ICity city,
                               java.time.LocalDateTime arrival,
                               ICaptain captain)
      • 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 leaving
        captain - 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()