View Javadoc
1   package org.opentrafficsim.road.gtu.lane.tactical.routesystem;
2   
3   import org.djunits.value.vdouble.scalar.Length;
4   import org.djutils.exceptions.Throw;
5   import org.opentrafficsim.core.network.LateralDirectionality;
6   
7   /**
8    * Lane change info.
9    * <p>
10   * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
11   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
12   * <p>
13   * @version $Revision$, $LastChangedDate$, by $Author$, initial version 7 nov. 2019 <br>
14   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
15   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
16   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
17   */
18  public class LaneChangeInfo implements Comparable<LaneChangeInfo>
19  {
20      
21      /** Required number of lane changes. */
22      private final int n;
23      
24      /** Remaining distance. */
25      private final Length remainingDistance;
26      
27      /** Whether the need to change lane comes from a dead-end. */
28      private final boolean deadEnd;
29  
30      /** Lateral directionality of required lane changes. */
31      private final LateralDirectionality lat;
32      
33      /**
34       * Constructor.
35       * @param n int; required number of lane changes
36       * @param remainingDistance Length; remaining distance
37       * @param deadEnd boolean; whether the need to change lane comes from a dead-end
38       * @param lat LateralDirectionality; lateral directionality of required lane changes
39       */
40      public LaneChangeInfo(final int n, final Length remainingDistance, final boolean deadEnd, final LateralDirectionality lat)
41      {
42          Throw.whenNull(remainingDistance, "remainingDistance may not be null");
43          Throw.whenNull(lat, "lat may not be null");
44          this.n = n;
45          this.remainingDistance = remainingDistance;
46          this.deadEnd = deadEnd;
47          this.lat = lat;
48      }
49  
50      /**
51       * Returns the required number of lane changes.
52       * @return int; required number of lane changes
53       */
54      public int getNumberOfLaneChanges()
55      {
56          return this.n;
57      }
58      
59      /**
60       * Return the remaining distance.
61       * @return Length; remaining distance
62       */
63      public Length getRemainingDistance()
64      {
65          return this.remainingDistance;
66      }
67      
68      /**
69       * Returns whether the need to change lane comes from a dead-end.
70       * @return boolean; whether the need to change lane comes from a dead-end
71       */
72      public boolean deadEnd()
73      {
74          return this.deadEnd;
75      }
76      
77      /**
78       * Returns the lateral directionality of the required lane changes.
79       * @return LateralDirectionality; lateral directionality of the required lane changes
80       */
81      public final LateralDirectionality getLateralDirectionality()
82      {
83          return this.lat;
84      }
85  
86      /** {@inheritDoc} */
87      @Override
88      public int compareTo(final LaneChangeInfo o)
89      {
90          if (o == null)
91          {
92              return 1;
93          }
94          if (o.remainingDistance.equals(this.remainingDistance))
95          {
96              return Integer.compare(this.n, o.n);
97          }
98          return this.remainingDistance.compareTo(o.remainingDistance);
99      }
100     
101 }