View Javadoc
1   package org.opentrafficsim.core.network;
2   
3   /**
4    * Permitted longitudinal driving directions.
5    * <p>
6    * Copyright (c) 2013-2017 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
7    * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
8    * <p>
9    * $LastChangedDate: 2017-04-29 12:51:08 +0200 (Sat, 29 Apr 2017) $, @version $Revision: 3570 $, by $Author: averbraeck $,
10   * initial version Oct 15, 2014 <br>
11   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
12   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
13   * @author <a href="http://www.citg.tudelft.nl">Guus Tamminga</a>
14   */
15  public enum LongitudinalDirectionality
16  {
17      /** Direction the same as the direction of the graph, increasing fractional position when driving in this direction. */
18      DIR_PLUS,
19      /** Direction opposite to the direction of the graph, decreasing fractional position when driving in this direction. */
20      DIR_MINUS,
21      /** Bidirectional. */
22      DIR_BOTH,
23      /** No traffic possible. */
24      DIR_NONE;
25  
26      /**
27       * This method looks if this directionality "contains" the provided other directionality. The logic table looks as follows:
28       * <table border="1" summary="">
29       * <tr>
30       * <td><b>THIS &darr; &nbsp; OTHER &rarr;</b></td>
31       * <td><b>DIR_BOTH&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b></td>
32       * <td><b>DIR_PLUS&nbsp;&nbsp;&nbsp;</b></td>
33       * <td><b>DIR_MINUS</b></td>
34       * <td><b>DIR_NONE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b></td>
35       * </tr>
36       * <tr>
37       * <td><b>DIR_BOTH</b></td>
38       * <td>true</td>
39       * <td>true</td>
40       * <td>true</td>
41       * <td>true</td>
42       * </tr>
43       * <tr>
44       * <td><b>DIR_PLUS</b></td>
45       * <td>false</td>
46       * <td>true</td>
47       * <td>false</td>
48       * <td>true</td>
49       * </tr>
50       * <tr>
51       * <td><b>DIR_MINUS</b></td>
52       * <td>false</td>
53       * <td>false</td>
54       * <td>true</td>
55       * <td>true</td>
56       * </tr>
57       * <tr>
58       * <td><b>DIR_NONE</b></td>
59       * <td>false</td>
60       * <td>false</td>
61       * <td>false</td>
62       * <td>true</td>
63       * </tr>
64       * </table>
65       * @param directionality the directionality to compare with
66       * @return whether this directionality "contains" the provided other directionality
67       */
68      public final boolean contains(final LongitudinalDirectionality directionality)
69      {
70          return (this.equals(directionality) || this.equals(DIR_BOTH) || directionality.equals(DIR_NONE)) ? true : false;
71      }
72  
73      /**
74       * Easy access method to test if the directionality is FORWARD or BOTH.
75       * @return whether the directionality is FORWARD or BOTH
76       */
77      public final boolean isForwardOrBoth()
78      {
79          return this.equals(DIR_PLUS) || this.equals(DIR_BOTH);
80      }
81  
82      /**
83       * Easy access method to test if the directionality is BACKWARD or BOTH.
84       * @return whether the directionality is BACKWARD or BOTH
85       */
86      public final boolean isBackwardOrBoth()
87      {
88          return this.equals(DIR_MINUS) || this.equals(DIR_BOTH);
89      }
90  
91      /**
92       * Easy access method to test if the directionality is FORWARD.
93       * @return whether the directionality is FORWARD
94       */
95      public final boolean isForward()
96      {
97          return this.equals(DIR_PLUS);
98      }
99  
100     /**
101      * Easy access method to test if the directionality is BACKWARD.
102      * @return whether the directionality is BACKWARD
103      */
104     public final boolean isBackward()
105     {
106         return this.equals(DIR_MINUS);
107     }
108 
109     /**
110      * Easy access method to test if the directionality is BACKWARD or BOTH.
111      * @return whether the directionality is BACKWARD or BOTH
112      */
113     public final boolean isBoth()
114     {
115         return this.equals(DIR_BOTH);
116     }
117 }