View Javadoc
1   package org.opentrafficsim.xml.bindings;
2   
3   import org.djunits.value.vdouble.scalar.Duration;
4   import org.djutils.logger.CategoryLogger;
5   import org.opentrafficsim.xml.bindings.types.DurationType;
6   
7   /**
8    * DurationAdapter converts between the XML String for a Duration and the DJUnits Duration.
9    * <p>
10   * Copyright (c) 2013-2024 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   * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
15   */
16  public class DurationAdapter extends ScalarAdapter<Duration, DurationType>
17  {
18      
19      /** {@inheritDoc} */
20      @Override
21      public DurationType unmarshal(final String field)
22      {
23          if (isExpression(field))
24          {
25              return new DurationType(trimBrackets(field));
26          }
27          try
28          {
29              return new DurationType(Duration.valueOf(field));
30          }
31          catch (Exception exception)
32          {
33              CategoryLogger.always().error(exception, "Problem parsing Duration '" + field + "'");
34              throw exception;
35          }
36      }
37  
38  }