1 package org.opentrafficsim.xml.bindings;
2
3 import org.djutils.exceptions.Throw;
4 import org.opentrafficsim.xml.bindings.types.DoubleType;
5
6
7
8
9
10
11
12
13
14 public class DoublePositiveInclusiveAdapter extends ExpressionAdapter<Double, DoubleType>
15 {
16
17
18 @Override
19 public DoubleType unmarshal(final String field)
20 {
21 if (isExpression(field))
22 {
23 return new DoubleType(trimBrackets(field));
24 }
25 double value = Double.valueOf(field);
26 Throw.when(value < 0.0, IllegalArgumentException.class, "DoublePositiveInclusive value %s is negative.", value);
27 return new DoubleType(value);
28 }
29
30
31 @Override
32 public String marshal(final DoubleType value)
33 {
34 Throw.when(!value.isExpression() && value.getValue() < 0.0, IllegalArgumentException.class,
35 "DoublePositiveInclusive value %s is negative.", value.getValue());
36 return super.marshal(value);
37 }
38
39 }