Class AdeptDataConversion

java.lang.Object
de.aristaflow.adept2.model.datamanagement.AdeptDataConversion

public final class AdeptDataConversion extends Object
Provides methods to derive the ADEPT2 data type of a value from its class, to convert values of one ADEPT2 data type to another where possible, to convert a value into its typed text form and back, and to check the values of a parameter map against a parameter collection.
  • Field Details

    • MAX_TYPED_TEXT_LENGTH

      public static final int MAX_TYPED_TEXT_LENGTH
      The maximum number of characters of the typed text form of an accepted value.
      See Also:
  • Method Details

    • getDataType

      public static ProcessConstants.AdeptDataType getDataType(Object value)
      Gets the ADEPT2 data type of the designated value derived from its class: INTEGER for a Long, FLOAT for a Double, BOOLEAN for a Boolean, STRING for a String, DATE for a Date, URI for a URI and USERDEFINED for a UDTValue. A placeholder has the data type of the value it stands for.
      Parameters:
      value - The value of which to get the data type. This must not be null.
      Returns:
      The ADEPT2 data type of the designated value or null if its class has none.
      Throws:
      NullArgumentException - If the designated value is null, a NullArgumentException will be thrown.
    • convert

      public static Serializable convert(Serializable value, ProcessConstants.AdeptDataType targetDataType) throws ConversionException
      Converts the given value to the specified target data type and returns it.
      Conversions between data types.
      BOOLEAN INTEGER
      (accepts all Numbers
      FLOAT
      (accepts all Numbers
      STRING DATE URI USERDEFINED
      BOOLEAN -> as is false -> 0L
      true -> 1L
      false -> 0d
      true -> 1d
      false -> "false"
      true -> "true"
      - - -
      INTEGER -> 0 -> false; true otherwise as is
      (cast to Long if necessary)
      cast to Double signed decimal representation taken as milliseconds since 1970-01-01, 00:00:00 GMT - -
      FLOAT -> 0 -> false; true otherwise
      (accepts all Numbers)
      discards fractional digits while casting to Long
      (accepts all Numbers)
      as is
      (accepts all Numbers; will be cast to Double)
      computerized scientific notation taken as milliseconds since 1970-01-01, 00:00:00 GMT; discards fractional digits - -
      STRING -> "true" (ignoring case) -> true, false otherwise (Boolean.parseBoolean(String)) parsed as signed decimal representation (Long.parseLong(String)) parsed as computerized scientific notation (Double.parseDouble(String)) as is parsed as ISO 8601 parsed as URI (URI.create(String)) encoded as UTF-8
      DATE -> - milliseconds since 1970-01-01, 00:00:00 GMT as Long milliseconds since 1970-01-01, 00:00:00 GMT as Double formatted as ISO 8601 as is - -
      URI -> - - - as string - as is -
      USERDEFINED -> - - - decoded as UTF-8 - - as is (cloned)
      Parameters:
      value - the value to be converted; this should typically be a direct equivalent to an ADEPT2 data type. The caller is responsible for closing.
      targetDataType - the target data type to which the value should be converted
      Returns:
      the converted value. The caller is responsible for closing if appropriate.
      Throws:
      ConversionException - if the conversion is not possible
    • toTypedText

      public static String toTypedText(Object value) throws ConversionException
      Converts the designated value into its typed text form: the name of its data type, a colon and its text form as written by ConfigurationTools, e. g. INTEGER:7, STRING:7 or DATE:2026-10-01T04:00:00Z, a date being an ISO-8601 instant. A UDTValue is USERDEFINED, a colon, its UDT name, a colon and its content gzipped and Base64-encoded. The first colon ends the data type, whose names contain none, and the last colon ends a UDT name, since Base64 contains none, so the text needs no escape. parseTypedText(String) parses a typed text form without further information.
      Parameters:
      value - The value to convert. This must not be null. The caller stays responsible for closing a UDTValue.
      Returns:
      The typed text form of the designated value. This will never be null.
      Throws:
      ConversionException - If the class of the designated value has no ADEPT2 data type, the value is a placeholder or a UDTValue without a name, or the content of a UDTValue cannot be read, a ConversionException will be thrown.
      NullArgumentException - If the designated value is null, a NullArgumentException will be thrown.
    • parseTypedText

      public static Serializable parseTypedText(String typedText) throws ConversionException
      Parses the designated typed text form, as toTypedText(Object) writes it, into the value it represents. The text after the data type is read as ConfigurationTools reads it, so it may also have another form that ConfigurationTools accepts, e. g. BOOLEAN:yes.
      Parameters:
      typedText - The typed text form to parse. This must not be null.
      Returns:
      The value which the designated typed text form represents. This will never be null. The caller is responsible for closing a UDTValue.
      Throws:
      ConversionException - If the designated text does not start with the name of an ADEPT2 data type and a colon or the text after it is no value of this data type, a ConversionException will be thrown.
      NullArgumentException - If the designated text is null, a NullArgumentException will be thrown.
    • rejectParams

      public static Map<String,String> rejectParams(Map<String,?> paramValues, Collection<? extends Parameter> acceptedParams)
      Gets the values in the designated parameter map which the designated parameter collection does not accept, each with the first of these reasons which applies: the value is null, there is no parameter of its name, the value has another ADEPT2 data type than its parameter, it has no typed text form, or its typed text form has more than 4000 characters. A UDTValue fits a parameter of the data type USERDEFINED whatever its UDT name, as in a data container. The reasons do not say what the parameters belong to; a caller adds this in its own messages, e. g. the template whose input parameters they are.
      Parameters:
      paramValues - The parameter map, from the name of a parameter to its value. This must not be null. The caller stays responsible for closing a UDTValue.
      acceptedParams - The collection of accepted parameters or null if it is unknown, in which case only the checks which do not depend on it apply.
      Returns:
      The reasons why values (or parameters) are not accepted, indexed by the names of their parameters in the order of the designated parameter map. This will never be null.
      Throws:
      NullArgumentException - If the designated parameter value map is null, a NullArgumentException will be thrown.
    • getMissingValues

      public static Collection<String> getMissingValues(Map<String,?> paramValues, Collection<? extends Parameter> acceptedParams)
      Gets the names of the parameters in the designated parameter collection which are not optional and have no value in the designated parameter map, a null value counting as none. A value which rejectParams(Map, Collection) reports counts as a value, so a caller which drops the rejected values asks for the missing ones afterwards.
      Parameters:
      paramValues - The parameter map, from the name of a parameter to its value. This must not be null.
      acceptedParams - The parameter collection or null if it is unknown, in which case none is reported.
      Returns:
      The names of the parameters which are not optional and have no value, in the order of the designated parameter collection. This will never be null.
      Throws:
      NullArgumentException - If the designated parameter value map is null, a NullArgumentException will be thrown.