Class PyArgumentMap
java.lang.Object
java.util.AbstractMap<K,V>
java.util.HashMap<String,Object>
com.inductiveautomation.ignition.common.script.builtin.PyArgumentMap
- All Implemented Interfaces:
Serializable,Cloneable,Map<String,Object>
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object, V extends Object> -
Method Summary
Modifier and TypeMethodDescriptionstatic PyArgumentMapempty()<T> Optional<T>getAndCast(String name, Function<Object, T> castFunction) Get a given argument from the argument map, without doing any automatic coercion.getBooleanArg(String name) getBooleanArg(String name, Boolean def) getDateArg(String name) getDateArg(String name, Date def) getDoubleArg(String name) getDoubleArg(String name, Double def) getIfBoolean(String name) Getnameif and only if it is already a Boolean; does not perform coerciongetIfDouble(String name) Getnameif and only if it is already a Double; does not perform coerciongetIfFloat(String name) Getnameif and only if it is already a Float; does not perform coerciongetIfInteger(String name) Getnameif and only if it is already an Integer; does not perform coercionGetnameif and only if it is already a Long; does not perform coercionOptional<org.python.core.PyObject>getIfPyObject(String name) Getnameif and only if it is already a PyObject; does not perform coerciongetIfString(String name) Getnameif and only if it is already a String; does not perform coerciongetLongArg(String name) getLongArg(String name, Long def) getStringArg(String name) getStringArg(String name, String def) String[]getStringArray(String name) String[]getStringArray(String name, String[] def) static PyArgumentMapinterpretPyArgs(org.python.core.PyObject[] args, String[] keywords, Class<?> callingClass, String methodName) Helper for scripting functions that want to use python's keyword-style function invocation.static PyArgumentMapinterpretPyArgs(org.python.core.PyObject[] args, String[] keywords, String[] expectedKeywords, Class<?>[] expectedTypes) Methods inherited from class java.util.HashMap
clear, clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, valuesMethods inherited from class java.util.AbstractMap
equals, hashCode, toString
-
Method Details
-
interpretPyArgs
public static PyArgumentMap interpretPyArgs(org.python.core.PyObject[] args, String[] keywords, Class<?> callingClass, String methodName) Helper for scripting functions that want to use python's keyword-style function invocation. This version uses reflection to look for the @KeywordArgs annotation to find the expected params and their types. -
interpretPyArgs
public static PyArgumentMap interpretPyArgs(org.python.core.PyObject[] args, String[] keywords, String[] expectedKeywords, Class<?>[] expectedTypes) - Throws:
ClassCastException- if an argument failed to be coerced into the expected type based onexpectedTypes
-
empty
-
getStringArray
-
getStringArray
-
getStringArg
- Parameters:
name- keyword name of argument to retrieve. If not invoked with kwargs, will return the parameter at the expected numeric index.- Returns:
- the argument as a string, or
nullif the invocation passed null. - Throws:
ClassCastException- if the argument is present but cannot be coerced to the expected type.
-
getStringArg
- Parameters:
name- keyword name of argument to retrieve. If not invoked with kwargs, will return the parameter at the expected numeric index.def- a fallback value to be used if the specified keyword was not present in the PyArgumentMap- Returns:
- the argument as a String, or the fallback value
def. - Throws:
ClassCastException- if the argument is present but cannot be coerced to the expected type.
-
getIntArg
- Parameters:
name- keyword name of argument to retrieve. If not invoked with kwargs, will return the parameter at the expected numeric index.- Returns:
- the argument as an Integer, or
nullif the invocation passed null. - Throws:
ClassCastException- if the argument is present but cannot be coerced to the expected type.
-
getIntArg
- Parameters:
name- keyword name of argument to retrieve. If not invoked with kwargs, will return the parameter at the expected numeric index.def- a fallback value to be used if the specified keyword was not present in the PyArgumentMap- Returns:
- the argument as an Integer, or the fallback value
def. - Throws:
ClassCastException- if the argument is present but cannot be coerced to the expected type.
-
getLongArg
- Parameters:
name- keyword name of argument to retrieve. If not invoked with kwargs, will return the parameter at the expected numeric index.- Returns:
- the argument as a Long, or
nullif the invocation passed null. - Throws:
ClassCastException- if the argument is present but cannot be coerced to the expected type.
-
getLongArg
- Parameters:
name- keyword name of argument to retrieve. If not invoked with kwargs, will return the parameter at the expected numeric index.def- a fallback value to be used if the specified keyword was not present in the PyArgumentMap- Returns:
- the argument as a Long, or the fallback value
def. - Throws:
ClassCastException- if the argument is present but cannot be coerced to the expected type.
-
getBooleanArg
- Parameters:
name- keyword name of argument to retrieve. If not invoked with kwargs, will return the parameter at the expected numeric index.- Returns:
- the argument as a Boolean, or
nullif the invocation passed null. - Throws:
ClassCastException- if the argument is present but cannot be coerced to the expected type.
-
getBooleanArg
- Parameters:
name- keyword name of argument to retrieve. If not invoked with kwargs, will return the parameter at the expected numeric index.def- a fallback value to be used if the specified keyword was not present in the PyArgumentMap- Returns:
- the argument as a Boolean, or the fallback value
def. - Throws:
ClassCastException- if the argument is present but cannot be coerced to the expected type.
-
getDoubleArg
- Parameters:
name- keyword name of argument to retrieve. If not invoked with kwargs, will return the parameter at the expected numeric index.- Returns:
- the argument as a Double, or
nullif the invocation passed null. - Throws:
ClassCastException- if the argument is present but cannot be coerced to the expected type.
-
getDoubleArg
- Parameters:
name- keyword name of argument to retrieve. If not invoked with kwargs, will return the parameter at the expected numeric index.def- a fallback value to be used if the specified keyword was not present in the PyArgumentMap- Returns:
- the argument as a Double, or the fallback value
def. - Throws:
ClassCastException- if the argument is present but cannot be coerced to the expected type.
-
getDateArg
- Parameters:
name- keyword name of argument to retrieve. If not invoked with kwargs, will return the parameter at the expected numeric index.- Returns:
- the argument as a Date, or
nullif the invocation passed null. - Throws:
ClassCastException- if the argument is present but cannot be coerced to the expected type.
-
getDateArg
- Parameters:
name- keyword name of argument to retrieve. If not invoked with kwargs, will return the parameter at the expected numeric index.def- a fallback value to be used if the specified keyword was not present in the PyArgumentMap- Returns:
- the argument as a Date, or the fallback value
def. - Throws:
ClassCastException- if the argument is present but cannot be coerced to the expected type.
-
getArg
- Parameters:
name- keyword name of argument to retrieve. If not invoked with kwargs, will return the parameter at the expected numeric index.- Returns:
- the argument without coercion, or
nullif the invocation passed null. - Throws:
ClassCastException- if the argument is present but cannot be coerced to the expected type.
-
getArg
- Parameters:
name- keyword name of argument to retrieve. If not invoked with kwargs, will return the parameter at the expected numeric index.defaultValue- a fallback value to be used if the specified keyword was not present in the PyArgumentMap- Returns:
- the argument without coercion, or
defaultValueif the map did not containname - Throws:
ClassCastException- if the argument is present but cannot be coerced to the expected type.
-
getAndCast
Get a given argument from the argument map, without doing any automatic coercion.- Parameters:
name- argument to retrievecastFunction- A function that converts an Object to typeT. If caseFunction returns null or throws, getAndCast will return an empty Optional.- Returns:
- an Optional containing the result object, or nothing if the cast function failed.
-
getIfString
Getnameif and only if it is already a String; does not perform coercion -
getIfBoolean
Getnameif and only if it is already a Boolean; does not perform coercion -
getIfInteger
Getnameif and only if it is already an Integer; does not perform coercion -
getIfLong
Getnameif and only if it is already a Long; does not perform coercion -
getIfFloat
Getnameif and only if it is already a Float; does not perform coercion -
getIfDouble
Getnameif and only if it is already a Double; does not perform coercion -
getIfPyObject
Getnameif and only if it is already a PyObject; does not perform coercion
-