Class PyArgParser
- java.lang.Object
- 
- com.inductiveautomation.ignition.common.script.PyArgParser
 
- 
 public class PyArgParser extends java.lang.ObjectRoughly equivalent to the olderPyArgumentMap, but with stricter validation of types and some more "modern" conveniences.
- 
- 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontainsKey(java.lang.String keyword)java.util.Optional<java.util.List<java.lang.Object>>getAsList(java.lang.String keyword)Retrieve the argument specified bykeywordas a plain list.<T> java.util.Optional<java.util.List<T>>getAsList(java.lang.String keyword, java.lang.Class<T> clazz)Retrieve the argument specified bykeywordas a typed list ofclazz.java.util.Optional<java.util.Map<java.lang.Object,java.lang.Object>>getAsMap(java.lang.String keyword)Retrieve the argument specified bykeywordas an untyped map.<K,V>
 java.util.Optional<java.util.Map<K,V>>getAsMap(java.lang.String keyword, java.lang.Class<K> keyType, java.lang.Class<V> valueType)Retrieve the argument specified bykeywordas a typed map.java.util.Optional<java.lang.Boolean>getBoolean(java.lang.String keyword)Getskeyword, if and only if it was supplied as a boolean.java.util.Optional<java.util.Date>getDate(java.lang.String keyword)Getskeyword, if and only if it was supplied as a Date.java.util.Optional<java.lang.Double>getDouble(java.lang.String keyword)Getskeyword, if and only if it was supplied as a double.java.util.Optional<java.lang.Float>getFloat(java.lang.String keyword)Getskeyword, if and only if it was supplied as a float.java.util.Optional<java.lang.Integer>getInteger(java.lang.String keyword)Getskeyword, if and only if it was supplied as an integer.java.util.Optional<java.lang.Long>getLong(java.lang.String keyword)Getskeyword, if and only if it was supplied as a long.java.lang.BooleangetNullableBoolean(java.lang.String keyword)Retrieve argumentkeyword, if and only if it was supplied as a Boolean.java.util.DategetNullableDate(java.lang.String keyword)Retrieve argumentkeyword, if and only if it was supplied as a Date.java.lang.DoublegetNullableDouble(java.lang.String keyword)Retrieve argumentkeyword, if and only if it was supplied as a Double.java.lang.FloatgetNullableFloat(java.lang.String keyword)Retrieve argumentkeyword, if and only if it was supplied as a Float.java.lang.IntegergetNullableInteger(java.lang.String keyword)Retrieve argumentkeyword, if and only if it was supplied as a Integer.java.lang.LonggetNullableLong(java.lang.String keyword)Retrieve argumentkeyword, if and only if it was supplied as a Long.java.lang.StringgetNullableString(java.lang.String keyword)Retrieve argumentkeyword, if and only if it was supplied as a String.<T> TgetNullSafe(java.lang.String keyword, java.lang.Class<T> clazz)java.util.Optional<org.python.core.PyObject>getPyObject(java.lang.String keyword)Getskeyword, directly as a PyObject; i.e., without doing any casting.java.util.Optional<java.lang.String>getString(java.lang.String keyword)Getskeyword, if and only if it was supplied as a String.<T> java.util.Optional<T>getTyped(java.lang.String keyword, java.lang.Class<T> clazz)Ifkeywordwas supplied, return it (type-safe) or throw a TypeError.static PyArgParserparseArgs(org.python.core.PyObject[] args, java.lang.String[] keywords, java.lang.Class<?> callingClass, java.lang.String methodName)Similar toPyArgumentMap.interpretPyArgs(PyObject[], String[], Class, String), but with more explicit type-checking behavior.static PyArgParserparseArgs(org.python.core.PyObject[] args, java.lang.String[] keywords, java.lang.String[] expectedKeywords, java.lang.Class<?>[] expectedTypes, java.lang.String functionName)Similar toPyArgumentMap.interpretPyArgs(PyObject[], String[], String[], Class[]), but with more explicit type-checking behavior.booleanrequireBoolean(java.lang.String keyword)Retrieve required argumentkeyword, if and only if it was supplied as a boolean.java.util.DaterequireDate(java.lang.String keyword)Retrieve required argumentkeyword, if and only if it was supplied as a Date.doublerequireDouble(java.lang.String keyword)Retrieve required argumentkeyword, if and only if it was supplied as a double.floatrequireFloat(java.lang.String keyword)Retrieve required argumentkeyword, if and only if it was supplied as a float.intrequireInteger(java.lang.String keyword)Retrieve required argumentkeyword, if and only if it was supplied as an integer.longrequireLong(java.lang.String keyword)Retrieve required argumentkeyword, if and only if it was supplied as a long.org.python.core.PyObjectrequirePyObject(java.lang.String keyword)Retrievekeyword, directly as a PyObject; i.e., without doing any casting.java.lang.StringrequireString(java.lang.String keyword)Retrieve required argumentkeyword, if and only if it was supplied as a String.<T> TrequireTyped(java.lang.String keyword, java.lang.Class<T> clazz)Retrieve required argumentkeyword, if and only if the supplied value can be coerced toclazz.
 
- 
- 
- 
Method Detail- 
parseArgspublic static PyArgParser parseArgs(org.python.core.PyObject[] args, java.lang.String[] keywords, java.lang.String[] expectedKeywords, java.lang.Class<?>[] expectedTypes, java.lang.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:
- java.lang.IllegalArgumentException- if the provided method cannot be found, or is missing the KeywordArgs annotation.
- java.lang.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, java.lang.String[] keywords, java.lang.Class<?> callingClass, java.lang.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:
- java.lang.IllegalArgumentException- if the provided method cannot be found, or is missing the KeywordArgs annotation.
- java.lang.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
 
 - 
getTypedpublic <T> java.util.Optional<T> getTyped(java.lang.String keyword, java.lang.Class<T> clazz)Ifkeywordwas 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.
- java.lang.IllegalArgumentException- if the provided keyword is not an expected argument for the function
 
 - 
requireTypedpublic <T> T requireTyped(java.lang.String keyword, java.lang.Class<T> clazz)Retrieve 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.
- java.lang.IllegalArgumentException- if the provided keyword is not an expected argument for the function.
 
 - 
getNullSafe@Nullable public <T> T getNullSafe(java.lang.String keyword, java.lang.Class<T> clazz)
 - 
getBooleanpublic java.util.Optional<java.lang.Boolean> getBoolean(java.lang.String keyword) Getskeyword, 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.
- java.lang.IllegalArgumentException- if the provided keyword is not an expected argument for the function
- See Also:
- requireBoolean(String)
 
 - 
requireBooleanpublic boolean requireBoolean(java.lang.String keyword) Retrieve 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.
- java.lang.IllegalArgumentException- if the provided keyword is not an expected argument for the function
- See Also:
- getBoolean(String)
 
 - 
getNullableBoolean@Nullable public java.lang.Boolean getNullableBoolean(java.lang.String keyword) Retrieve 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
- java.lang.IllegalArgumentException- if the provided keyword is not an expected argument for the function
- See Also:
- requireBoolean(String)
 
 - 
getIntegerpublic java.util.Optional<java.lang.Integer> getInteger(java.lang.String keyword) Getskeyword, 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.
- java.lang.IllegalArgumentException- if the provided keyword is not an expected argument for the function
- See Also:
- requireInteger(String)
 
 - 
requireIntegerpublic int requireInteger(java.lang.String keyword) Retrieve 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.
- java.lang.IllegalArgumentException- if the provided keyword is not an expected argument for the function
- See Also:
- getInteger(String)
 
 - 
getNullableInteger@Nullable public java.lang.Integer getNullableInteger(java.lang.String keyword) Retrieve 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
- java.lang.IllegalArgumentException- if the provided keyword is not an expected argument for the function
- See Also:
- requireInteger(String)
 
 - 
getLongpublic java.util.Optional<java.lang.Long> getLong(java.lang.String keyword) Getskeyword, 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.
- java.lang.IllegalArgumentException- if the provided keyword is not an expected argument for the function
- See Also:
- requireLong(String)
 
 - 
requireLongpublic long requireLong(java.lang.String keyword) Retrieve 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.
- java.lang.IllegalArgumentException- if the provided keyword is not an expected argument for the function
- See Also:
- getLong(String)
 
 - 
getNullableLong@Nullable public java.lang.Long getNullableLong(java.lang.String keyword) Retrieve 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
- java.lang.IllegalArgumentException- if the provided keyword is not an expected argument for the function
- See Also:
- requireLong(String)
 
 - 
getFloatpublic java.util.Optional<java.lang.Float> getFloat(java.lang.String keyword) Getskeyword, 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.
- java.lang.IllegalArgumentException- if the provided keyword is not an expected argument for the function
- See Also:
- requireFloat(String)
 
 - 
requireFloatpublic float requireFloat(java.lang.String keyword) Retrieve 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.
- java.lang.IllegalArgumentException- if the provided keyword is not an expected argument for the function
- See Also:
- getFloat(String)
 
 - 
getNullableFloat@Nullable public java.lang.Float getNullableFloat(java.lang.String keyword) Retrieve 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
- java.lang.IllegalArgumentException- if the provided keyword is not an expected argument for the function
- See Also:
- requireFloat(String)
 
 - 
getDoublepublic java.util.Optional<java.lang.Double> getDouble(java.lang.String keyword) Getskeyword, 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.
- java.lang.IllegalArgumentException- if the provided keyword is not an expected argument for the function
- See Also:
- requireDouble(String)
 
 - 
requireDoublepublic double requireDouble(java.lang.String keyword) Retrieve 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.
- java.lang.IllegalArgumentException- if the provided keyword is not an expected argument for the function
- See Also:
- getDouble(String)
 
 - 
getNullableDouble@Nullable public java.lang.Double getNullableDouble(java.lang.String keyword) Retrieve 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
- java.lang.IllegalArgumentException- if the provided keyword is not an expected argument for the function
- See Also:
- requireDouble(String)
 
 - 
getDatepublic java.util.Optional<java.util.Date> getDate(java.lang.String keyword) Getskeyword, 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.
- java.lang.IllegalArgumentException- if the provided keyword is not an expected argument for the function
- See Also:
- requireDate(String)
 
 - 
requireDatepublic java.util.Date requireDate(java.lang.String keyword) Retrieve 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.
- java.lang.IllegalArgumentException- if the provided keyword is not an expected argument for the function
- See Also:
- getDate(String)
 
 - 
getNullableDate@Nullable public java.util.Date getNullableDate(java.lang.String keyword) Retrieve 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
- java.lang.IllegalArgumentException- if the provided keyword is not an expected argument for the function
- See Also:
- requireDate(String)
 
 - 
getStringpublic java.util.Optional<java.lang.String> getString(java.lang.String keyword) Getskeyword, 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.
- java.lang.IllegalArgumentException- if the provided keyword is not an expected argument for the function
- See Also:
- requireString(String)
 
 - 
requireString@Nonnull public java.lang.String requireString(java.lang.String keyword) Retrieve 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.
- java.lang.IllegalArgumentException- if the provided keyword is not an expected argument for the function
- See Also:
- getString(String)
 
 - 
getNullableString@Nullable public java.lang.String getNullableString(java.lang.String keyword) Retrieve 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
- java.lang.IllegalArgumentException- if the provided keyword is not an expected argument for the function
- See Also:
- requireString(String)
 
 - 
getPyObjectpublic java.util.Optional<org.python.core.PyObject> getPyObject(java.lang.String keyword) Getskeyword, 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:
- java.lang.IllegalArgumentException- if the provided keyword is not an expected argument for the function
- See Also:
- requirePyObject(String)
 
 - 
requirePyObjectpublic org.python.core.PyObject requirePyObject(java.lang.String keyword) Retrievekeyword, 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.
- java.lang.IllegalArgumentException- if the provided keyword is not an expected argument for the function
- See Also:
- getPyObject(String)
 
 - 
containsKeypublic boolean containsKey(java.lang.String keyword) 
 - 
getAsListpublic <T> java.util.Optional<java.util.List<T>> getAsList(java.lang.String keyword, java.lang.Class<T> clazz)Retrieve 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
 
 - 
getAsListpublic java.util.Optional<java.util.List<java.lang.Object>> getAsList(java.lang.String keyword) Retrieve 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
 
 - 
getAsMappublic <K,V> java.util.Optional<java.util.Map<K,V>> getAsMap(java.lang.String keyword, java.lang.Class<K> keyType, java.lang.Class<V> valueType)Retrieve 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
 
 - 
getAsMappublic java.util.Optional<java.util.Map<java.lang.Object,java.lang.Object>> getAsMap(java.lang.String keyword) Retrieve 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
 
 
- 
 
-