View Javadoc
1   package org.opentrafficsim.xml.bindings;
2   
3   import org.djunits.value.vdouble.scalar.Duration;
4   import org.djutils.logger.CategoryLogger;
5   
6   /**
7    * DurationAdapter converts between the XML String for a Duration and the DJUnits Duration.
8    * <p>
9    * Copyright (c) 2013-2023 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   */
14  public class DurationAdapter extends UnitAdapter<Duration>
15  {
16      /** {@inheritDoc} */
17      @Override
18      public Duration unmarshal(final String field) throws IllegalArgumentException
19      {
20          try
21          {
22              return Duration.valueOf(field);
23          }
24          catch (Exception exception)
25          {
26              CategoryLogger.always().error(exception, "Problem parsing Duration '" + field + "'");
27              throw exception;
28          }
29      }
30  
31  }