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 ExpressionType
E - 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 Details

    • ExpressionAdapter

      public ExpressionAdapter()
  • Method Details

    • marshal

      public String marshal(E value)
      Specified by:
      marshal in class javax.xml.bind.annotation.adapters.XmlAdapter<String,E extends ExpressionType<T>>
    • marshal

      protected final String marshal(E value, Function<T,String> stringFunction)
      Marshaling of ExpressionType. If the ExpressionType contains an expression, it is returned with brackets. Otherwise a String representation of the contained value is returned using the supplied function.
      Parameters:
      value - ExpressionType<?>; value.
      stringFunction - Function<T, String>; function to get a String representation of a contained value.
      Returns:
      Marshaled String of an ExpressionType.
    • unmarshal

      public abstract E unmarshal(String v)
      Specified by:
      unmarshal in class javax.xml.bind.annotation.adapters.XmlAdapter<String,E extends ExpressionType<T>>
    • isExpression

      protected static boolean isExpression(String field) throws IllegalArgumentException
      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

      protected static String trimBrackets(String field) throws IllegalArgumentException
      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