View Javadoc
1   package org.opentrafficsim.xml.bindings.types;
2   
3   import org.djunits.value.vdouble.scalar.Length;
4   
5   /**
6    * LengthBeginEnd contains the information from the LengthBeginEndType. Examples of type instances are<br>
7    * - BEGIN <br>
8    * - END <br>
9    * - END - 10m <br>
10   * - 25 ft <br>
11   * - 0.8 <br>
12   * - 80% <br>
13   * <br>
14   * Copyright (c) 2003-2018 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See
15   * for project information <a href="https://www.simulation.tudelft.nl/" target="_blank">www.simulation.tudelft.nl</a>. The
16   * source code and binary code of this software is proprietary information of Delft University of Technology.
17   * @author <a href="https://www.tudelft.nl/averbraeck" target="_blank">Alexander Verbraeck</a>
18   */
19  public class LengthBeginEnd
20  {
21      /** begin or end? */
22      private final boolean begin;
23  
24      /** absolute offset or relative fraction? */
25      private final boolean absolute;
26  
27      /** the offset in case absolute == true. */
28      private final Length offset;
29  
30      /** the fraction in case absolute == false. */
31      private final double fraction;
32  
33      /**
34       * @param begin boolean; begin or end?
35       * @param offset the offset; absolute = true
36       */
37      public LengthBeginEnd(final boolean begin, final Length offset)
38      {
39          this.begin = begin;
40          this.absolute = true;
41          this.offset = offset;
42          this.fraction = 0.0;
43      }
44  
45      /**
46       * @param fraction the fraction; absolute = false
47       */
48      public LengthBeginEnd(final double fraction)
49      {
50          this.begin = true;
51          this.absolute = false;
52          this.offset = Length.ZERO;
53          this.fraction = fraction;
54      }
55  
56      /**
57       * @return begin
58       */
59      public final boolean isBegin()
60      {
61          return this.begin;
62      }
63  
64      /**
65       * @return absolute
66       */
67      public final boolean isAbsolute()
68      {
69          return this.absolute;
70      }
71  
72      /**
73       * @return offset
74       */
75      public final Length getOffset()
76      {
77          return this.offset;
78      }
79  
80      /**
81       * @return fraction
82       */
83      public final double getFraction()
84      {
85          return this.fraction;
86      }
87  
88      /** {@inheritDoc} */
89      @Override
90      public int hashCode()
91      {
92          final int prime = 31;
93          int result = 1;
94          result = prime * result + (this.absolute ? 1231 : 1237);
95          result = prime * result + (this.begin ? 1231 : 1237);
96          long temp;
97          temp = Double.doubleToLongBits(this.fraction);
98          result = prime * result + (int) (temp ^ (temp >>> 32));
99          result = prime * result + ((this.offset == null) ? 0 : this.offset.hashCode());
100         return result;
101     }
102 
103     /** {@inheritDoc} */
104     @Override
105     public boolean equals(Object obj)
106     {
107         if (this == obj)
108             return true;
109         if (obj == null)
110             return false;
111         if (getClass() != obj.getClass())
112             return false;
113         LengthBeginEnd other = (LengthBeginEnd) obj;
114         if (this.absolute != other.absolute)
115             return false;
116         if (this.begin != other.begin)
117             return false;
118         if (Double.doubleToLongBits(this.fraction) != Double.doubleToLongBits(other.fraction))
119             return false;
120         if (this.offset == null)
121         {
122             if (other.offset != null)
123                 return false;
124         }
125         else if (!this.offset.equals(other.offset))
126             return false;
127         return true;
128     }
129 
130     /** {@inheritDoc} */
131     @Override
132     public String toString()
133     {
134         return "LengthBeginEnd [begin=" + this.begin + ", absolute=" + this.absolute + ", offset=" + this.offset + ", fraction="
135                 + this.fraction + "]";
136     }
137 
138 }