View Javadoc
1   package org.opentrafficsim.xml.bindings;
2   
3   import org.djunits.value.vdouble.scalar.Length;
4   import org.djutils.logger.CategoryLogger;
5   
6   /**
7    * SignedLengthAdapter converts between the XML String for a Length and the DJUnits Length. The length can be positive or
8    * negative.
9    * <p>
10   * Copyright (c) 2013-2023 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
11   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
12   * </p>
13   * @author <a href="https://github.com/averbraeck" target="_blank">Alexander Verbraeck</a>
14   */
15  public class LengthAdapter extends UnitAdapter<Length>
16  {
17      /** {@inheritDoc} */
18      @Override
19      public Length unmarshal(final String field) throws IllegalArgumentException
20      {
21          try
22          {
23              return Length.valueOf(field);
24          }
25          catch (Exception exception)
26          {
27              CategoryLogger.always().error(exception, "Problem parsing Length '" + field + "'");
28              throw exception;
29          }
30      }
31  
32  }