Class PyArgParser
java.lang.Object
com.inductiveautomation.ignition.common.script.PyArgParser
Roughly equivalent to the older 
PyArgumentMap, but with stricter validation of types and some more "modern"
 conveniences.- 
Method SummaryModifier and TypeMethodDescriptionbooleancontainsKey(String keyword) Retrieve the argument specified bykeywordas a plain list.Retrieve the argument specified bykeywordas a typed list ofclazz.Retrieve the argument specified bykeywordas an untyped map.Retrieve the argument specified bykeywordas a typed map.getBoolean(String keyword) Getskeyword, if and only if it was supplied as a boolean.Getskeyword, if and only if it was supplied as a Date.Getskeyword, if and only if it was supplied as a double.Getskeyword, if and only if it was supplied as a float.getInteger(String keyword) Getskeyword, if and only if it was supplied as an integer.Getskeyword, if and only if it was supplied as a long.getNullableBoolean(String keyword) Retrieve argumentkeyword, if and only if it was supplied as a Boolean.getNullableDate(String keyword) Retrieve argumentkeyword, if and only if it was supplied as a Date.getNullableDouble(String keyword) Retrieve argumentkeyword, if and only if it was supplied as a Double.getNullableFloat(String keyword) Retrieve argumentkeyword, if and only if it was supplied as a Float.getNullableInteger(String keyword) Retrieve argumentkeyword, if and only if it was supplied as a Integer.getNullableLong(String keyword) Retrieve argumentkeyword, if and only if it was supplied as a Long.getNullableString(String keyword) Retrieve argumentkeyword, if and only if it was supplied as a String.<T> TgetNullSafe(String keyword, Class<T> clazz) Optional<org.python.core.PyObject>getPyObject(String keyword) Getskeyword, directly as a PyObject; i.e., without doing any casting.Getskeyword, if and only if it was supplied as a String.<T> Optional<T>Ifkeywordwas supplied, return it (type-safe) or throw a TypeError.static PyArgParserparseArgs(org.python.core.PyObject[] args, String[] keywords, Class<?> callingClass, String methodName) Similar toPyArgumentMap.interpretPyArgs(PyObject[], String[], Class, String), but with more explicit type-checking behavior.static PyArgParserparseArgs(org.python.core.PyObject[] args, String[] keywords, String[] expectedKeywords, Class<?>[] expectedTypes, String functionName) Similar toPyArgumentMap.interpretPyArgs(PyObject[], String[], String[], Class[]), but with more explicit type-checking behavior.booleanrequireBoolean(String keyword) Retrieve required argumentkeyword, if and only if it was supplied as a boolean.requireDate(String keyword) Retrieve required argumentkeyword, if and only if it was supplied as a Date.doublerequireDouble(String keyword) Retrieve required argumentkeyword, if and only if it was supplied as a double.floatrequireFloat(String keyword) Retrieve required argumentkeyword, if and only if it was supplied as a float.intrequireInteger(String keyword) Retrieve required argumentkeyword, if and only if it was supplied as an integer.requireList(String keyword) Retrieve required argumentkeywordif and only if it was supplied as a list.<T> List<T>requireList(String keyword, Class<T> clazz) Retrieve required argumentkeywordif and only if it was supplied as a list ofclazz.longrequireLong(String keyword) Retrieve required argumentkeyword, if and only if it was supplied as a long.org.python.core.PyObjectrequirePyObject(String keyword) Retrievekeyword, directly as a PyObject; i.e., without doing any casting.requireString(String keyword) Retrieve required argumentkeyword, if and only if it was supplied as a String.<T> TrequireTyped(String keyword, Class<T> clazz) Retrieve required argumentkeyword, if and only if the supplied value can be coerced toclazz.
- 
Method Details- 
parseArgspublic static PyArgParser parseArgs(org.python.core.PyObject[] args, String[] keywords, String[] expectedKeywords, Class<?>[] expectedTypes, String functionName) Similar toPyArgumentMap.interpretPyArgs(PyObject[], String[], String[], Class[]), but with more explicit type-checking behavior.- Parameters:
- args- args from a function call
- keywords- keyword names from a function call
- expectedKeywords- expected keyword arguments
- expectedTypes- expected argument types
- functionName- the name of the function; used for better contextual error messages
- Returns:
- a PyArgParser instance
- Throws:
- IllegalArgumentException- if the provided method cannot be found, or is missing the KeywordArgs annotation.
- AssertionError- if- keywordsis shorter than- args, or the list of expected keywords doesn't match the list of expected types.
 
- 
parseArgspublic static PyArgParser parseArgs(org.python.core.PyObject[] args, String[] keywords, Class<?> callingClass, String methodName) Similar toPyArgumentMap.interpretPyArgs(PyObject[], String[], Class, String), but with more explicit type-checking behavior.- Parameters:
- args- args from a function call
- keywords- keyword names from a function call
- callingClass- the class the method is contained in. Will be checked reflectively for the- KeywordArgsannotation.
- methodName- the name of the method. Used to look up annotations reflectively, and for thrown errors.
- Returns:
- a PyArgParser instance
- Throws:
- IllegalArgumentException- if the provided method cannot be found, or is missing the KeywordArgs annotation.
- AssertionError- if- keywordsis shorter than- args, or the list of expected keywords doesn't match the list of expected types.
- org.python.core.PyException- TypeError if more arguments are provided than expected argument names
 
- 
getTypedIfkeywordwas supplied, return it (type-safe) or throw a TypeError. If not specified or None was supplied, returns an empty optional.- Throws:
- org.python.core.PyException- TypeError if the supplied value cannot be coerced to- clazz.
- IllegalArgumentException- if the provided keyword is not an expected argument for the function
 
- 
requireTypedRetrieve required argumentkeyword, if and only if the supplied value can be coerced toclazz.- Returns:
- the retrieved value of keywordcoerced toclazz.
- Throws:
- org.python.core.PyException- TypeError if the supplied value cannot be coerced to- clazz.
- IllegalArgumentException- if the provided keyword is not an expected argument for the function.
 
- 
getNullSafe
- 
getBooleanGetskeyword, if and only if it was supplied as a boolean.- Returns:
- the boolean value of keyword, if supplied, or an empty optional.
- Throws:
- org.python.core.PyException- TypeError if the supplied value was not a boolean.
- IllegalArgumentException- if the provided keyword is not an expected argument for the function
- See Also:
 
- 
requireBooleanRetrieve required argumentkeyword, if and only if it was supplied as a boolean.- Returns:
- the boolean value of keyword
- Throws:
- org.python.core.PyException- TypeError if the supplied value was not a boolean, or was not specified.
- IllegalArgumentException- if the provided keyword is not an expected argument for the function
- See Also:
 
- 
getNullableBooleanRetrieve argumentkeyword, if and only if it was supplied as a Boolean. UnlikerequireBoolean(String), will accept a supplied value ofPyNoneand return null.- Returns:
- the Boolean value of keyword, or null.
- Throws:
- org.python.core.PyException- TypeError if the supplied value was not a Boolean
- IllegalArgumentException- if the provided keyword is not an expected argument for the function
- See Also:
 
- 
getIntegerGetskeyword, if and only if it was supplied as an integer.- Returns:
- the integer value of keyword, if supplied, or an empty optional.
- Throws:
- org.python.core.PyException- TypeError if the supplied value was not a integer.
- IllegalArgumentException- if the provided keyword is not an expected argument for the function
- See Also:
 
- 
requireIntegerRetrieve required argumentkeyword, if and only if it was supplied as an integer.- Returns:
- the integer value of keyword
- Throws:
- org.python.core.PyException- TypeError if the supplied value was not a integer, or was not specified.
- IllegalArgumentException- if the provided keyword is not an expected argument for the function
- See Also:
 
- 
getNullableIntegerRetrieve argumentkeyword, if and only if it was supplied as a Integer. UnlikerequireInteger(String), will accept a supplied value ofPyNoneand return null.- Returns:
- the Integer value of keyword, or null.
- Throws:
- org.python.core.PyException- TypeError if the supplied value was not a Integer
- IllegalArgumentException- if the provided keyword is not an expected argument for the function
- See Also:
 
- 
getLongGetskeyword, if and only if it was supplied as a long.- Returns:
- the long value of keyword, if supplied, or an empty optional.
- Throws:
- org.python.core.PyException- TypeError if the supplied value was not a long.
- IllegalArgumentException- if the provided keyword is not an expected argument for the function
- See Also:
 
- 
requireLongRetrieve required argumentkeyword, if and only if it was supplied as a long.- Returns:
- the long value of keyword
- Throws:
- org.python.core.PyException- TypeError if the supplied value was not a long, or was not specified.
- IllegalArgumentException- if the provided keyword is not an expected argument for the function
- See Also:
 
- 
getNullableLongRetrieve argumentkeyword, if and only if it was supplied as a Long. UnlikerequireLong(String), will accept a supplied value ofPyNoneand return null.- Returns:
- the Long value of keyword, or null.
- Throws:
- org.python.core.PyException- TypeError if the supplied value was not a Long
- IllegalArgumentException- if the provided keyword is not an expected argument for the function
- See Also:
 
- 
getFloatGetskeyword, if and only if it was supplied as a float.- Returns:
- the float value of keyword, if supplied, or an empty optional.
- Throws:
- org.python.core.PyException- TypeError if the supplied value was not a float.
- IllegalArgumentException- if the provided keyword is not an expected argument for the function
- See Also:
 
- 
requireFloatRetrieve required argumentkeyword, if and only if it was supplied as a float.- Returns:
- the float value of keyword
- Throws:
- org.python.core.PyException- TypeError if the supplied value was not a float, or was not specified.
- IllegalArgumentException- if the provided keyword is not an expected argument for the function
- See Also:
 
- 
getNullableFloatRetrieve argumentkeyword, if and only if it was supplied as a Float. UnlikerequireFloat(String), will accept a supplied value ofPyNoneand return null.- Returns:
- the Float value of keyword, or null.
- Throws:
- org.python.core.PyException- TypeError if the supplied value was not a Float
- IllegalArgumentException- if the provided keyword is not an expected argument for the function
- See Also:
 
- 
getDoubleGetskeyword, if and only if it was supplied as a double.- Returns:
- the double value of keyword, if supplied, or an empty optional.
- Throws:
- org.python.core.PyException- TypeError if the supplied value was not a double.
- IllegalArgumentException- if the provided keyword is not an expected argument for the function
- See Also:
 
- 
requireDoubleRetrieve required argumentkeyword, if and only if it was supplied as a double.- Returns:
- the double value of keyword
- Throws:
- org.python.core.PyException- TypeError if the supplied value was not a double, or was not specified.
- IllegalArgumentException- if the provided keyword is not an expected argument for the function
- See Also:
 
- 
getNullableDoubleRetrieve argumentkeyword, if and only if it was supplied as a Double. UnlikerequireDouble(String), will accept a supplied value ofPyNoneand return null.- Returns:
- the Double value of keyword, or null.
- Throws:
- org.python.core.PyException- TypeError if the supplied value was not a Double
- IllegalArgumentException- if the provided keyword is not an expected argument for the function
- See Also:
 
- 
getDateGetskeyword, if and only if it was supplied as a Date.- Returns:
- the Date value of keyword, if supplied, or an empty optional.
- Throws:
- org.python.core.PyException- TypeError if the supplied value was not a Date.
- IllegalArgumentException- if the provided keyword is not an expected argument for the function
- See Also:
 
- 
requireDateRetrieve required argumentkeyword, if and only if it was supplied as a Date.- Returns:
- the Date value of keyword
- Throws:
- org.python.core.PyException- TypeError if the supplied value was not a Date, or was not specified.
- IllegalArgumentException- if the provided keyword is not an expected argument for the function
- See Also:
 
- 
getNullableDateRetrieve argumentkeyword, if and only if it was supplied as a Date. UnlikerequireDate(String), will accept a supplied value ofPyNoneand return null.- Returns:
- the Date value of keyword, or null.
- Throws:
- org.python.core.PyException- TypeError if the supplied value was not a Date
- IllegalArgumentException- if the provided keyword is not an expected argument for the function
- See Also:
 
- 
getStringGetskeyword, if and only if it was supplied as a String.- Returns:
- the String value of keyword, if supplied, or an empty optional.
- Throws:
- org.python.core.PyException- TypeError if the supplied value was not a String.
- IllegalArgumentException- if the provided keyword is not an expected argument for the function
- See Also:
 
- 
requireStringRetrieve required argumentkeyword, if and only if it was supplied as a String.- Returns:
- the String value of keyword
- Throws:
- org.python.core.PyException- TypeError if the supplied value was not a String, or was not specified.
- IllegalArgumentException- if the provided keyword is not an expected argument for the function
- See Also:
 
- 
getNullableStringRetrieve argumentkeyword, if and only if it was supplied as a String. UnlikerequireString(String), will accept a supplied value ofPyNoneand return null.- Returns:
- the String value of keyword, or null.
- Throws:
- org.python.core.PyException- TypeError if the supplied value was not a String
- IllegalArgumentException- if the provided keyword is not an expected argument for the function
- See Also:
 
- 
getPyObjectGetskeyword, directly as a PyObject; i.e., without doing any casting.- Returns:
- the PyObject value of keyword, if supplied, or an empty optional. Can bePy.Noneif None was supplied.
- Throws:
- IllegalArgumentException- if the provided keyword is not an expected argument for the function
- See Also:
 
- 
requirePyObjectRetrievekeyword, directly as a PyObject; i.e., without doing any casting.- Returns:
- the PyObject value of keyword
- Throws:
- org.python.core.PyException- TypeError if the supplied value was not provided.
- IllegalArgumentException- if the provided keyword is not an expected argument for the function
- See Also:
 
- 
containsKey
- 
getAsListRetrieve the argument specified bykeywordas a typed list ofclazz. Will be a shallow copy.- Throws:
- org.python.core.PyException-
- TypeError if any elements of the PyList supplied as an argument can't be coerced to
- clazz
- TypeError if the supplied PyObject is not iterable
- TypeError if any elements of the PyList supplied as an argument can't be coerced to
 
- 
requireListRetrieve required argumentkeywordif and only if it was supplied as a list ofclazz. Will be a shallow copy.- Throws:
- org.python.core.PyException-- TypeError if any elements of the PyList supplied as an argument can't be coerced to clazz
- TypeError if the supplied PyObject is not iterable
 
- TypeError if any elements of the PyList supplied as an argument can't be coerced to 
- IllegalArgumentException- if the provided keyword is not an expected argument for the function
 
- 
getAsListRetrieve the argument specified bykeywordas a plain list. Will be a shallow copy.- Throws:
- org.python.core.PyException-
- TypeError if the supplied PyObject is not iterable
 
- 
requireListRetrieve required argumentkeywordif and only if it was supplied as a list. Will be a shallow copy.- Throws:
- org.python.core.PyException-- TypeError if the supplied PyObject is not iterable
 
- IllegalArgumentException- if the provided keyword is not an expected argument for the function
 
- 
getAsMapRetrieve the argument specified bykeywordas a typed map. Will be a shallow copy.- Throws:
- org.python.core.PyException-
- TypeError if any elements of the PyDictionary supplied as an argument can't be coerced to the right class
- TypeError if the supplied PyObject is not iterable
 
- 
getAsMapRetrieve the argument specified bykeywordas an untyped map. Will be a shallow copy.- Throws:
- org.python.core.PyException-
- TypeError if the supplied PyObject is not iterable
 
 
-