View Javadoc
1   package org.opentrafficsim.road.network;
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-2023 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
11   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
12   * </p>
13   * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
14   * @author <a href="https://tudelft.nl/staff/p.knoppers-1">Peter Knoppers</a>
15   * @author <a href="https://dittlab.tudelft.nl">Wouter Schakel</a>
16   */
17  public class LaneChangeInfo implements Comparable<LaneChangeInfo>
18  {
19  
20      /** Required number of lane changes. */
21      private final int n;
22  
23      /** Remaining distance. */
24      private final Length remainingDistance;
25  
26      /** Whether the need to change lane comes from a dead-end. */
27      private final boolean deadEnd;
28  
29      /** Lateral directionality of required lane changes. */
30      private final LateralDirectionality lat;
31  
32      /**
33       * Constructor.
34       * @param n int; required number of lane changes
35       * @param remainingDistance Length; remaining distance
36       * @param deadEnd boolean; whether the need to change lane comes from a dead-end
37       * @param lat LateralDirectionality; lateral directionality of required lane changes
38       */
39      public LaneChangeInfo(final int n, final Length remainingDistance, final boolean deadEnd, final LateralDirectionality lat)
40      {
41          Throw.whenNull(remainingDistance, "remainingDistance may not be null");
42          Throw.whenNull(lat, "lat may not be null");
43          this.n = n;
44          this.remainingDistance = remainingDistance;
45          this.deadEnd = deadEnd;
46          this.lat = lat;
47      }
48  
49      /**
50       * Returns the required number of lane changes.
51       * @return int; required number of lane changes
52       */
53      public int getNumberOfLaneChanges()
54      {
55          return this.n;
56      }
57  
58      /**
59       * Return the remaining distance.
60       * @return Length; remaining distance
61       */
62      public Length getRemainingDistance()
63      {
64          return this.remainingDistance;
65      }
66  
67      /**
68       * Returns whether the need to change lane comes from a dead-end.
69       * @return boolean; whether the need to change lane comes from a dead-end
70       */
71      public boolean deadEnd()
72      {
73          return this.deadEnd;
74      }
75  
76      /**
77       * Returns the lateral directionality of the required lane changes.
78       * @return LateralDirectionality; lateral directionality of the required lane changes
79       */
80      public final LateralDirectionality getLateralDirectionality()
81      {
82          return this.lat;
83      }
84  
85      /** {@inheritDoc} */
86      @Override
87      public int compareTo(final LaneChangeInfo o)
88      {
89          if (o == null)
90          {
91              return 1;
92          }
93          if (o.remainingDistance.equals(this.remainingDistance))
94          {
95              return Integer.compare(this.n, o.n);
96          }
97          return this.remainingDistance.compareTo(o.remainingDistance);
98      }
99  
100 }