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