java.lang.Object
com.aquima.interactions.foundation.convert.Converter
Direct Known Subclasses:
ProfileConverter

public class Converter extends Object
Utility class providing method to convert objects to IValue classes.
Since:
5.0
Author:
O. Kerpershoek
  • Field Details

    • LISTVALUE_SEPARATOR

      public static final String LISTVALUE_SEPARATOR
      The default separator that is used to separate multiple elements in a string.
      See Also:
  • Constructor Details

    • Converter

      public Converter()
      Constructs a converter without a delegate, thus providing standard conversion behavior.
    • Converter

      public Converter(IConverterDelegate delegate)
      This constructor accepts a delegate that will be used as a fallback when a certain object cannot be converted to the required data type by the normal conversion methods. The delegate will be invoked after the Converter has attempted to convert the object, but before the ConversionException is thrown.
      Parameters:
      delegate - The delegate that should be used when the default conversion fails.
  • Method Details

    • unknownFor

      public static IPrimitiveValue unknownFor(DataType type)
      This method returns the unknown value for the specified data type.
      Parameters:
      type - The data type for which the unknown value is requested.
      Returns:
      The unknown value for the specified data type.
    • unknownValue

      public IPrimitiveValue unknownValue(DataType type)
      This method returns the unknown value for the specified data type.
      Parameters:
      type - The data type for which the unknown value is requested.
      Returns:
      The unknown value for the specified data type.
    • parseObject

      public IValue parseObject(Object objValue, DataType type)
      This method will parse a given object to an IValue instance. Depending on the class of the argument, the return value will either be an IPrimitiveValue, an IListValue or null. When the provided object is null, then null is returned. When the provided object represents a plural of instances (when the object is a Collection, array, IListValue, Map or a string value that contains multiple values separated by LISTVALUE_SEPARATOR), then the return value will be an IListValue. Otherwise, the return value is an IPrimitiveValue.
      Parameters:
      objValue - The object that needs to be converted (can be null).
      type - The type the object needs to be converted to (cannot be null).
      Returns:
      an IPrimitiveValue, an IListValue or null.
      Throws:
      ConversionException - This exception is thrown when the object could not be converted.
    • parseCollection

      public IValue parseCollection(Object objValue, DataType type, boolean alwaysReturnList)
      This method will convert the given object to a ListValue containing primitive values of the given type. Depending on the value of the alwaysReturnList parameter, this method may also return a single value or null when the alwaysReturnList is set to false. When the alwaysReturnList parameter is set to true this method will always return a valid IListValue object, but the object might be empty (no values).
      Parameters:
      objValue - The object that needs to be converted.
      type - The type the object needs to be converted to.
      alwaysReturnList - Parameter used to indicate if the returned object must implement the IListValue interface.
      Returns:
      IValue object containing the result.
      Throws:
      ConversionException - This exception is thrown when the object could not be converted.
    • parseCollection

      public IValue parseCollection(Object objValue, DataType type, boolean alwaysReturnList, boolean isUniqueSet)
      This method will convert the given object to a ListValue containing primitive values of the given type. Depending on the value of the alwaysReturnList parameter, this method may also return a single value or null when the alwaysReturnList is set to false. When the alwaysReturnList parameter is set to true this method will always return a valid IListValue object, but the object might be empty (no values).
      Parameters:
      objValue - The object that needs to be converted.
      type - The type the object needs to be converted to.
      alwaysReturnList - Parameter used to indicate if the returned object must implement the IListValue interface.
      isUniqueSet - Parameter used to indicate if the list is unique or not.
      Returns:
      IValue object containing the result.
      Throws:
      ConversionException - This exception is thrown when the object could not be converted.
    • parse

      public IPrimitiveValue parse(Object obj, DataType type)
      This method converts the passed object to a single primitive value of the specified data type.
      Parameters:
      obj - The object that should be converted
      type - The data type to which the value should be converted.
      Returns:
      IPrimitiveValue containing the converted object
      Throws:
      ConversionException - This exception is thrown when the object could not be converted.
    • parseEntity

      protected EntityValue parseEntity(Object objValue)