Utilities

Converters

General purpose converters (java.util.Functions) for performing value conversions throughout the automation interface are provided. These converters are referenced from the AutomationInterface documentation wherever they apply. The AutomationInterface is typed strongly. In some cases, however, e.g. when specifying file locations, it is desirable to allow for a range of possibly parameter types. This is achieved by accepting parameters of type Object and converting the given parameters to the desired type.

The following converters are provided:

ScriptConverters.TO_PATH

Attempts to convert arbitrary Objects to Paths using
IAutomationPathsApi.resolvePath(Object) IAutomationPathsApi.resolvePath.

ScriptConverters.TO_SCRIPT_PATH

Attempts to convert arbitrary Objects to Paths using IAutomationPathsApi.resolveScriptPath(Object) IAutomationPathsApi.resolveScriptPath.

ScriptConverters.TO_VERSION

Attempts to convert arbitrary Objects to IVersions. The following conversions are implemented:
  • For null or IVersion arguments the given argument is returned. No conversion is applied.
  • Strings are converted using Version.valueOf(String).
  • Numbers are converted by converting the int obtained from Number.intValue() using Version.valueOf(int).
  • All other Objects are converted by converting the String obtained from Object.toString().

ScriptConverters.TO_BIG_INTEGER

Attempts to convert arbitrary Objects to BigIntegers. The following conversions are implemented:
  • For null or BigInteger arguments the given argument is returned. No conversion is applied.
  • Integers, Longs, Shorts and Bytes are converted using BigInteger.valueOf(long).
  • All other types of objects are interpreted as Strings (Object.toString()) and passed to BigInteger.BigInteger(String).

ScriptConverters.TO_BIG_DECIMAL

Attempts to convert arbitrary Objects to Doubles. The following conversions are implemented:
  • For null or Double arguments the given argument is returned. No conversion is applied.
  • Floats and Doubles, are converted using Double.valueOf(double).
  • Integers, Longs, Shorts and Bytes are converted using Double.valueOf(double).
  • All other types of objects are interpreted as Strings (Object.toString()) and passed to Double.Double(String).

ModelConverters.TO_MDF

Attempts to convert arbitrary Objects to MDFObjects. The following conversions are implemented:
  • For null or MDFObject arguments the given argument is returned. No conversion is applied.
  • IHasModelObjects are converted using their IHasModelObject.getMdfObject() method.
  • IViewedModelObjects are converted using their IViewedModelObject.getMdfObject() method.
  • For all other Objects ClassCastExceptions are thrown.
For thrown Exceptions see the used functions described above.