mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-14 08:40:29 +00:00
Adjust untravelable individual legs.
This commit is contained in:
parent
e60eabaa92
commit
affb7ef0ba
1 changed files with 27 additions and 0 deletions
|
@ -184,6 +184,27 @@ public final class Trip implements Serializable
|
|||
return true;
|
||||
}
|
||||
|
||||
/** If an individual leg overlaps, try to adjust so that it doesn't. */
|
||||
public void adjustUntravelableIndividualLegs()
|
||||
{
|
||||
final int numLegs = legs.size();
|
||||
if (numLegs < 1)
|
||||
return;
|
||||
|
||||
for (int i = 1; i < numLegs; i++)
|
||||
{
|
||||
final Trip.Leg leg = legs.get(i);
|
||||
|
||||
if (leg instanceof Trip.Individual)
|
||||
{
|
||||
final Trip.Leg previous = legs.get(i - 1);
|
||||
|
||||
if (leg.getDepartureTime().before(previous.getArrivalTime()))
|
||||
legs.set(i, ((Trip.Individual) leg).movedClone(previous.getArrivalTime()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Set<Product> products()
|
||||
{
|
||||
final Set<Product> products = EnumSet.noneOf(Product.class);
|
||||
|
@ -431,6 +452,12 @@ public final class Trip implements Serializable
|
|||
this.distance = distance;
|
||||
}
|
||||
|
||||
public Individual movedClone(final Date departureTime)
|
||||
{
|
||||
final Date arrivalTime = new Date(departureTime.getTime() + this.arrivalTime.getTime() - this.departureTime.getTime());
|
||||
return new Trip.Individual(this.type, this.departure, departureTime, this.arrival, arrivalTime, this.path, this.distance);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getDepartureTime()
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue