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 PyArgumentMap
empty()
<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) Getname
if and only if it is already a Boolean; does not perform coerciongetIfDouble
(String name) Getname
if and only if it is already a Double; does not perform coerciongetIfFloat
(String name) Getname
if and only if it is already a Float; does not perform coerciongetIfInteger
(String name) Getname
if and only if it is already an Integer; does not perform coercionGetname
if and only if it is already a Long; does not perform coercionOptional<org.python.core.PyObject>
getIfPyObject
(String name) Getname
if and only if it is already a PyObject; does not perform coerciongetIfString
(String name) Getname
if 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 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.static PyArgumentMap
interpretPyArgs
(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, values
Methods 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
null
if 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
null
if 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
null
if 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
null
if 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
null
if 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
null
if 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
null
if 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
defaultValue
if 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
Getname
if and only if it is already a String; does not perform coercion -
getIfBoolean
Getname
if and only if it is already a Boolean; does not perform coercion -
getIfInteger
Getname
if and only if it is already an Integer; does not perform coercion -
getIfLong
Getname
if and only if it is already a Long; does not perform coercion -
getIfFloat
Getname
if and only if it is already a Float; does not perform coercion -
getIfDouble
Getname
if and only if it is already a Double; does not perform coercion -
getIfPyObject
Getname
if and only if it is already a PyObject; does not perform coercion
-