Class DoubleScalarSerializer<U extends org.djunits.unit.Unit<U>,​S extends org.djunits.value.vdouble.scalar.base.DoubleScalarInterface<U,​S>>

java.lang.Object
org.djutils.data.serialization.DoubleScalarSerializer<U,​S>
Type Parameters:
U - the unit type
S - the scalar type
All Implemented Interfaces:
TextSerializer<S>

public class DoubleScalarSerializer<U extends org.djunits.unit.Unit<U>,​S extends org.djunits.value.vdouble.scalar.base.DoubleScalarInterface<U,​S>>
extends Object
implements TextSerializer<S>
ScalarSerializer (de)serializes DJUNITS scalars.

Copyright (c) 2020-2020 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information https://djutils.org. The DJUTILS project is distributed under a three-clause BSD-style license, which can be found at https://djutils.org/docs/license.html.
Author:
Alexander Verbraeck, Peter Knoppers, Wouter Schakel
  • Constructor Details

  • Method Details

    • serialize

      public String serialize​(Object value)
      Serialize a DoubleScalar value to text in such a way that it can be deserialized with the corresponding deserializer. In this case, it serializes the class name of the Scalar, followed by a hash sign, followed by the printed value of the scalar including the unit. So a Length of 12.5 kilometer will return "org.djunits.value.vdouble.scalar.Length#12.5 km".
      Specified by:
      serialize in interface TextSerializer<U extends org.djunits.unit.Unit<U>>
      Parameters:
      value - S; the scalar to serialize
      Returns:
      String; a string representation of the value that can later be deserialized
    • deserialize

      public S deserialize​(String text)
      Deserialize a String to the correct DoubleScalar value in line with the DoubleScalarSerializer.serialize method. In this case, it assumes a string with the class name of the Scalar, followed by a hash sign, followed by the printed value of the scalar including the unit. So, the String "org.djunits.value.vdouble.scalar.Length#12.5 km" will be deserialized into a Length of 12500 m with LengthUnit.KILOMETER as the display unit. The method caches the valueOf(String) method for repeated use.
      Specified by:
      deserialize in interface TextSerializer<U extends org.djunits.unit.Unit<U>>
      Parameters:
      text - String; the text to deserialize
      Returns:
      S; the reconstructed scalar