Esempio n. 1
0
        /// <summary>
        /// Merges the current <see cref="Freight.Itinerary"/> with the provided <see cref="Freight.Itinerary"/>
        /// </summary>
        /// <param name="other">itinerary</param>
        /// <returns>A merge between the current itinerary and the provided itinerary
        /// that describes a continuous route even if the cargo is currently misdirected.</returns>
        public virtual Itinerary ItineraryMergedWith(Itinerary other)
        {
            if (RoutingStatus == RoutingStatus.NOT_ROUTED)
            {
                return(other);
            }

            if (IsMisdirected && TransportStatus == TransportStatus.ONBOARD_CARRIER)
            {
                var currentLeg = Leg.DeriveLeg(CurrentVoyage, LastKnownLocation,
                                               CurrentVoyage.ArrivalLocationWhenDepartedFrom(LastKnownLocation));

                return(Itinerary.TruncatedAfter(LastKnownLocation).WithLeg(currentLeg).AppendBy(other));
            }

            return(Itinerary.TruncatedAfter(EarliestReroutingLocation).AppendBy(other));
        }
Esempio n. 2
0
        internal Itinerary TruncatedAfter(Location location)
        {
            var newLegs = new List <Leg>();

            foreach (var leg in Legs)
            {
                if (leg.Voyage.Locations.Contains(location))
                {
                    newLegs.Add(Leg.DeriveLeg(leg.Voyage, leg.LoadLocation, location));
                    break;
                }
                else
                {
                    newLegs.Add(leg);
                    if (leg.UnloadLocation.sameAs(location))
                    {
                        break;
                    }
                }
            }

            return(new Itinerary(newLegs));
        }