View Javadoc
1   package org.opentrafficsim.xml.bindings;
2   
3   import org.djunits.value.vdouble.scalar.Length;
4   import org.opentrafficsim.xml.bindings.types.LengthType;
5   
6   /**
7    * LengthAdapter converts between the XML String for a Length and the DJUnits Length.
8    * <p>
9    * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
10   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
11   * </p>
12   * @author <a href="https://github.com/averbraeck" target="_blank">Alexander Verbraeck</a>
13   * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
14   */
15  public class LengthAdapter extends ScalarAdapter<Length, LengthType>
16  {
17      
18      /** {@inheritDoc} */
19      @Override
20      public LengthType unmarshal(final String field)
21      {
22          if (isExpression(field))
23          {
24              return new LengthType(trimBrackets(field));
25          }
26          try
27          {
28              return new LengthType(Length.valueOf(field));
29          }
30          catch (Exception exception)
31          {
32              throw exception;
33          }
34      }
35  
36  }