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>

public class PyArgumentMap extends HashMap<String,Object>
See Also:
  • 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 on expectedTypes
    • empty

      public static PyArgumentMap empty()
    • getStringArray

      @Nullable public String[] getStringArray(String name)
    • getStringArray

      @Nullable public String[] getStringArray(String name, String[] def)
    • getStringArg

      @Nullable public String getStringArg(String name)
      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

      @Nullable public String getStringArg(String name, String def)
      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

      @Nullable public Integer getIntArg(String name)
      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

      @Nullable public Integer getIntArg(String name, Integer def)
      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

      @Nullable public Long getLongArg(String name)
      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

      @Nullable public Long getLongArg(String name, Long def)
      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

      @Nullable public Boolean getBooleanArg(String name)
      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

      @Nullable public Boolean getBooleanArg(String name, Boolean def)
      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

      @Nullable public Double getDoubleArg(String name)
      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

      @Nullable public Double getDoubleArg(String name, Double def)
      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

      @Nullable public Date getDateArg(String name)
      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

      @Nullable public Date getDateArg(String name, Date def)
      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

      @Nullable public Object getArg(String name)
      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

      @Nullable public Object getArg(String name, Object defaultValue)
      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 contain name
      Throws:
      ClassCastException - if the argument is present but cannot be coerced to the expected type.
    • getAndCast

      public <T> Optional<T> getAndCast(String name, Function<Object,T> castFunction)
      Get a given argument from the argument map, without doing any automatic coercion.
      Parameters:
      name - argument to retrieve
      castFunction - A function that converts an Object to type T. 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

      public Optional<String> getIfString(String name)
      Get name if and only if it is already a String; does not perform coercion
    • getIfBoolean

      public Optional<Boolean> getIfBoolean(String name)
      Get name if and only if it is already a Boolean; does not perform coercion
    • getIfInteger

      public Optional<Integer> getIfInteger(String name)
      Get name if and only if it is already an Integer; does not perform coercion
    • getIfLong

      public Optional<Long> getIfLong(String name)
      Get name if and only if it is already a Long; does not perform coercion
    • getIfFloat

      public Optional<Float> getIfFloat(String name)
      Get name if and only if it is already a Float; does not perform coercion
    • getIfDouble

      public Optional<Double> getIfDouble(String name)
      Get name if and only if it is already a Double; does not perform coercion
    • getIfPyObject

      public Optional<org.python.core.PyObject> getIfPyObject(String name)
      Get name if and only if it is already a PyObject; does not perform coercion