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-2016 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      /**
33       * Constructor.
34       * @param requiredNumberOfLaneChanges required number of lane changes
35       * @param remainingDistance remaining distance to perform required lane changes
36       * @throws IllegalArgumentException if required number of lane changes or remaining distance is negative
37       * @throws NullPointerException if remaining distance is null
38       */
39      public InfrastructureLaneChangeInfo(final int requiredNumberOfLaneChanges, final Length remainingDistance)
40      {
41          Throw.when(requiredNumberOfLaneChanges < 0, IllegalArgumentException.class,
42              "Required number of lane changes may not be negative.");
43          Throw.whenNull(remainingDistance, "Remaining distance may not be null.");
44          Throw.when(remainingDistance.si < 0, IllegalArgumentException.class, "Remaining distance may not be negative.");
45          this.requiredNumberOfLaneChanges = requiredNumberOfLaneChanges;
46          this.remainingDistance = remainingDistance;
47      }
48  
49      /**
50       * @return requiredNumberOfLaneChanges required number of lane changes.
51       */
52      public final int getRequiredNumberOfLaneChanges()
53      {
54          return this.requiredNumberOfLaneChanges;
55      }
56  
57      /**
58       * @return remainingDistance remaining distance to perform required lane changes.
59       */
60      public final Length getRemainingDistance()
61      {
62          return this.remainingDistance;
63      }
64  
65      /** {@inheritDoc} */
66      @SuppressWarnings("checkstyle:designforextension")
67      @Override
68      public String toString()
69      {
70          return "InfrastructureLaneChangeInfo [requiredNumberOfLaneChanges=" + this.requiredNumberOfLaneChanges
71              + ", remainingDistance=" + this.remainingDistance + "]";
72      }
73  
74      /** {@inheritDoc} */
75      @Override
76      public final int compareTo(final InfrastructureLaneChangeInfo infrastructureLaneChangeInfo)
77      {
78          return this.remainingDistance.compareTo(infrastructureLaneChangeInfo.getRemainingDistance());
79      }
80  
81  }