Package org.opentrafficsim.xml.bindings
Class ExpressionAdapter<T,E extends ExpressionType<T>>
java.lang.Object
javax.xml.bind.annotation.adapters.XmlAdapter<String,E>
org.opentrafficsim.xml.bindings.ExpressionAdapter<T,E>
- Type Parameters:
T
- value type wrapped in ExpressionTypeE
- ExpressionType
- Direct Known Subclasses:
AccelerationUnitAdapter
,ArcDirectionAdapter
,BooleanAdapter
,ClassAdapter
,ColorAdapter
,DoubleAdapter
,DoublePositiveAdapter
,DoublePositiveInclusiveAdapter
,DoubleUnitIntervalAdapter
,DurationUnitAdapter
,FractionAdapter
,FrequencyUnitAdapter
,IntegerAdapter
,LengthBeginEndAdapter
,LengthUnitAdapter
,LinearDensityUnitAdapter
,LongAdapter
,Point2dAdapter
,PositiveFactorAdapter
,PositiveIntegerAdapter
,PriorityAdapter
,ScalarAdapter
,SpaceAdapter
,SpeedUnitAdapter
,StaticFieldAdapter
,StaticFieldNameAdapter
,StringAdapter
,StripeTypeAdapter
public abstract class ExpressionAdapter<T,E extends ExpressionType<T>>
extends javax.xml.bind.annotation.adapters.XmlAdapter<String,E>
Super class for adapters of expression types. This class performs default marshaling by using the expression, or
toString()
on the value (or an empty String
if its null
). Sub-classes may overwrite the
marshal(E value)
method, calling marshal(E value, Function stringFunction)
to use a different form of
representing the value as a String
and/or to implement value checks.
Copyright (c) 2023-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.
- Author:
- Wouter Schakel
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected static boolean
isExpression
(String field) Checks whether field value is a bracketed expression.protected final String
Marshaling ofExpressionType
.protected static String
trimBrackets
(String field) Trims the brackets from an expression.abstract E
-
Constructor Details
-
ExpressionAdapter
public ExpressionAdapter()
-
-
Method Details
-
marshal
- Specified by:
marshal
in classjavax.xml.bind.annotation.adapters.XmlAdapter<String,
E extends ExpressionType<T>>
-
marshal
Marshaling ofExpressionType
. If theExpressionType
contains an expression, it is returned with brackets. Otherwise aString
representation of the contained value is returned using the supplied function.- Parameters:
value
- ExpressionType<?>; value.stringFunction
- Function<T, String>; function to get aString
representation of a contained value.- Returns:
- Marshaled
String
of anExpressionType
.
-
unmarshal
- Specified by:
unmarshal
in classjavax.xml.bind.annotation.adapters.XmlAdapter<String,
E extends ExpressionType<T>>
-
isExpression
Checks whether field value is a bracketed expression.- Parameters:
field
- String; field value.- Returns:
- boolean; whether field value is a bracketed expression.
- Throws:
IllegalArgumentException
- when the fields starts with { but does not end with }
-
trimBrackets
Trims the brackets from an expression.- Parameters:
field
- String; expression with brackets.- Returns:
- String; expression trimmed from brackets.
- Throws:
IllegalArgumentException
- when the field is not a valid expression between brackets
-