View Javadoc
1   package org.opentrafficsim.road.gtu.lane.perception;
2   
3   import java.io.Serializable;
4   
5   import org.djunits.value.vdouble.scalar.Length;
6   
7   import nl.tudelft.simulation.language.Throw;
8   
9   /**
10   * Contains information by which drivers know when they need to leave a lane in order to be able to stay on the infrastructure
11   * and follow their route.
12   * <p>
13   * Copyright (c) 2013-2017 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
14   * BSD-style license. See <a href="http://opentrafficsim.org/docs/current/license.html">OpenTrafficSim License</a>.
15   * <p>
16   * @version $Revision$, $LastChangedDate$, by $Author$, initial version May 2, 2016 <br>
17   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
18   */
19  
20  public class InfrastructureLaneChangeInfo implements Comparable<InfrastructureLaneChangeInfo>, Serializable
21  {
22  
23      /** */
24      private static final long serialVersionUID = 20160811L;
25  
26      /** Required number of lane changes. */
27      private final int requiredNumberOfLaneChanges;
28  
29      /** Remaining distance to perform required lane changes. */
30      private final Length remainingDistance;
31  
32      /** Whether this reason to change lane is due to a dead-end. */
33      private final boolean deadEnd;
34  
35      /**
36       * Constructor.
37       * @param requiredNumberOfLaneChanges required number of lane changes
38       * @param remainingDistance remaining distance to perform required lane changes
39       * @param deadEnd whether this reason to change lane is due to a dead-end
40       * @throws IllegalArgumentException if required number of lane changes or remaining distance is negative
41       * @throws NullPointerException if remaining distance is null
42       */
43      public InfrastructureLaneChangeInfo(final int requiredNumberOfLaneChanges, final Length remainingDistance,
44              final boolean deadEnd)
45      {
46          Throw.when(requiredNumberOfLaneChanges < 0, IllegalArgumentException.class,
47                  "Required number of lane changes may not be negative.");
48          Throw.whenNull(remainingDistance, "Remaining distance may not be null.");
49          Throw.when(remainingDistance.si < 0, IllegalArgumentException.class, "Remaining distance may not be negative.");
50          this.requiredNumberOfLaneChanges = requiredNumberOfLaneChanges;
51          this.remainingDistance = remainingDistance;
52          this.deadEnd = deadEnd;
53      }
54  
55      /**
56       * @return requiredNumberOfLaneChanges required number of lane changes.
57       */
58      public final int getRequiredNumberOfLaneChanges()
59      {
60          return this.requiredNumberOfLaneChanges;
61      }
62  
63      /**
64       * @return remainingDistance remaining distance to perform required lane changes.
65       */
66      public final Length getRemainingDistance()
67      {
68          return this.remainingDistance;
69      }
70  
71      /**
72       * @return whether this reason to change lane is due to a dead-end.
73       */
74      public boolean isDeadEnd()
75      {
76          return this.deadEnd;
77      }
78  
79      /** {@inheritDoc} */
80      @SuppressWarnings("checkstyle:designforextension")
81      @Override
82      public String toString()
83      {
84          return "InfrastructureLaneChangeInfo [requiredNumberOfLaneChanges=" + this.requiredNumberOfLaneChanges
85                  + ", remainingDistance=" + this.remainingDistance + "]";
86      }
87  
88      /** {@inheritDoc} */
89      @Override
90      public final int compareTo(final InfrastructureLaneChangeInfo infrastructureLaneChangeInfo)
91      {
92          return this.remainingDistance.compareTo(infrastructureLaneChangeInfo.getRemainingDistance());
93      }
94  
95  }