Class RobotProperty

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.util.Map<java.lang.Object,​java.lang.Object>

    public class RobotProperty
    extends java.util.Properties
    RobotProperty is an extension of normal Java Properties, but can be accessed in a static manner. The properties file loaded is found by ammending the Robot name found under /etc/robot on the RoboRio to the Filesystem.getDeployDirectory() provided by WPILib.

    Access to properties should be done via the getAs... static methods, such as getString(), getInt(), getDouble(), and getBoolean(). Each also accepts a second parameter representing the default value if the property key is not defined.

    Examples include:

       String val = RobotProperty.getString("my_property");
       int motorId = RobotProperty.getInt("arm_motor_id");
       boolean isInverted = RobotProperty.getInt("is_inverted");
       double pValue = RobotProperty.getDouble("pid_p");
    
       // You can also use enumerations, or anything with a 'toString()' value to resolve
       public enum KnownProperties {
         drivetrain_left_motor_id;
       }
    
       int motorId = RobotProperty.getInt(KnownProperties.drivetrain_left_motor_id);
     
    See Also:
    WPILib Deployed Files, Serialized Form
    • Field Summary

      • Fields inherited from class java.util.Properties

        defaults
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean getBoolean​(java.lang.Object keyObj)
      Same as getBoolean(java.lang.String) but takes anything with a toString() method - which is everything in Java - so you can pass enumerations and the sort.
      static boolean getBoolean​(java.lang.Object keyObj, java.lang.String defaultValue)
      Same as getBoolean(java.lang.Object) but takes a default value if the property is not defined, instead of raising an exception.
      static boolean getBoolean​(java.lang.String key)
      Returns the property as a boolean.
      static boolean getBoolean​(java.lang.String key, boolean defaultValue)
      Same as getBoolean(java.lang.String) but takes a default value if the property is not defined, instead of raising an exception.
      java.lang.String getCurrentPropertyPath()
      Returns the currently loaded property file path for debugging purposes
      static double getDouble​(java.lang.Object keyObj)
      Same as getDouble(java.lang.String) but takes anything with a toString() method - which is everything in Java - so you can pass enumerations and the sort.
      static double getDouble​(java.lang.Object keyObj, java.lang.String defaultValue)
      Same as getDouble(java.lang.Object) but takes a default value if the property is not defined, instead of raising an exception.
      static double getDouble​(java.lang.String key)
      Returns the property as a double.
      static double getDouble​(java.lang.String key, double defaultValue)
      Same as getDouble(java.lang.String) but takes a default value if the property is not defined, instead of raising an exception.
      static int getInt​(java.lang.Object keyObj)
      Same as getInt(java.lang.String) but takes anything with a toString() method - which is everything in Java - so you can pass enumerations and the sort.
      static int getInt​(java.lang.Object keyObj, java.lang.String defaultValue)
      Same as getInt(java.lang.Object) but takes a default value if the property is not defined, instead of raising an exception.
      static int getInt​(java.lang.String key)
      Returns the property as an integer.
      static int getInt​(java.lang.String key, int defaultValue)
      Same as getInt(java.lang.String) but takes a default value if the property is not defined, instead of raising an exception.
      java.lang.String getProperty​(java.lang.String key)
      An override of the Java Properties.getProperty(String) method, but use getString(String) instead.
      static java.lang.String getString​(java.lang.Object keyObj)
      Same as getString(java.lang.String) but takes anything with a toString() method - which is everything in Java - so you can pass enumerations and the sort.
      static java.lang.String getString​(java.lang.Object keyObj, java.lang.String defaultValue)
      Same as getString(java.lang.Object) but takes a default value if the property is not defined, instead of raising an exception.
      static java.lang.String getString​(java.lang.String key)
      Returns the property as a string.
      static java.lang.String getString​(java.lang.String key, java.lang.String defaultValue)
      Same as getString(java.lang.String) but takes a default value if the property is not defined, instead of raising an exception.
      static void UNSAFE_setSingleton​(java.lang.String propertyPath)
      Used only for testing, so do not call this in code.
      • Methods inherited from class java.util.Properties

        clear, clone, compute, computeIfAbsent, computeIfPresent, contains, containsKey, containsValue, elements, entrySet, equals, forEach, get, getOrDefault, getProperty, hashCode, isEmpty, keys, keySet, list, list, load, load, loadFromXML, merge, propertyNames, put, putAll, putIfAbsent, rehash, remove, remove, replace, replace, replaceAll, save, setProperty, size, store, store, storeToXML, storeToXML, storeToXML, stringPropertyNames, toString, values
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
    • Method Detail

      • getString

        public static java.lang.String getString​(java.lang.String key)
        Returns the property as a string. This is the same as `getProperty()`, but matches the type-generation of the other static methods. An InvalidParameterException will be raised if a property is loaded that does not exist.
        Parameters:
        key - The property key to fetch.
        Returns:
        The String value of the property.
      • getString

        public static java.lang.String getString​(java.lang.Object keyObj)
        Same as getString(java.lang.String) but takes anything with a toString() method - which is everything in Java - so you can pass enumerations and the sort.
        Parameters:
        keyObj - the object to call toString() on to get the desired property name
        Returns:
        The String value of the property.
      • getString

        public static java.lang.String getString​(java.lang.String key,
                                                 java.lang.String defaultValue)
        Same as getString(java.lang.String) but takes a default value if the property is not defined, instead of raising an exception.
        Parameters:
        key - The property key to fetch.
        defaultValue - The default value if the property does not exist.
        Returns:
        The String value of the property.
      • getString

        public static java.lang.String getString​(java.lang.Object keyObj,
                                                 java.lang.String defaultValue)
        Same as getString(java.lang.Object) but takes a default value if the property is not defined, instead of raising an exception.
        Parameters:
        keyObj - the object to call toString() on to get the desired property name
        defaultValue - The default value if the property does not exist.
        Returns:
        The String value of the property.
      • getInt

        public static int getInt​(java.lang.String key)
        Returns the property as an integer. An InvalidParameterException will be raised if a property is loaded that does not exist.
        Parameters:
        key - The property key to fetch.
        Returns:
        The integer value of the property.
      • getInt

        public static int getInt​(java.lang.Object keyObj)
        Same as getInt(java.lang.String) but takes anything with a toString() method - which is everything in Java - so you can pass enumerations and the sort.
        Parameters:
        keyObj - the object to call toString() on to get the desired property name
        Returns:
        The integer value of the property.
      • getInt

        public static int getInt​(java.lang.String key,
                                 int defaultValue)
        Same as getInt(java.lang.String) but takes a default value if the property is not defined, instead of raising an exception.
        Parameters:
        key - The property key to fetch.
        defaultValue - The default value if the property does not exist.
        Returns:
        The integer value of the property.
      • getInt

        public static int getInt​(java.lang.Object keyObj,
                                 java.lang.String defaultValue)
        Same as getInt(java.lang.Object) but takes a default value if the property is not defined, instead of raising an exception.
        Parameters:
        keyObj - the object to call toString() on to get the desired property name
        defaultValue - The default value if the property does not exist.
        Returns:
        The integer value of the property.
      • getBoolean

        public static boolean getBoolean​(java.lang.String key)
        Returns the property as a boolean. An InvalidParameterException will be raised if a property is loaded that does not exist.
        Parameters:
        key - The property key to fetch.
        Returns:
        The boolean value of the property.
      • getBoolean

        public static boolean getBoolean​(java.lang.Object keyObj)
        Same as getBoolean(java.lang.String) but takes anything with a toString() method - which is everything in Java - so you can pass enumerations and the sort.
        Parameters:
        keyObj - the object to call toString() on to get the desired property name
        Returns:
        The boolean value of the property.
      • getBoolean

        public static boolean getBoolean​(java.lang.String key,
                                         boolean defaultValue)
        Same as getBoolean(java.lang.String) but takes a default value if the property is not defined, instead of raising an exception.
        Parameters:
        key - The property key to fetch.
        defaultValue - The default value if the property does not exist.
        Returns:
        The boolean value of the property.
      • getBoolean

        public static boolean getBoolean​(java.lang.Object keyObj,
                                         java.lang.String defaultValue)
        Same as getBoolean(java.lang.Object) but takes a default value if the property is not defined, instead of raising an exception.
        Parameters:
        keyObj - the object to call toString() on to get the desired property name
        defaultValue - The default value if the property does not exist.
        Returns:
        The boolean value of the property.
      • getDouble

        public static double getDouble​(java.lang.String key)
        Returns the property as a double. An InvalidParameterException will be raised if a property is loaded that does not exist.
        Parameters:
        key - The property key to fetch.
        Returns:
        The double value of the property.
      • getDouble

        public static double getDouble​(java.lang.Object keyObj)
        Same as getDouble(java.lang.String) but takes anything with a toString() method - which is everything in Java - so you can pass enumerations and the sort.
        Parameters:
        keyObj - the object to call toString() on to get the desired property name
        Returns:
        The double value of the property.
      • getDouble

        public static double getDouble​(java.lang.String key,
                                       double defaultValue)
        Same as getDouble(java.lang.String) but takes a default value if the property is not defined, instead of raising an exception.
        Parameters:
        key - The property key to fetch.
        defaultValue - The default value if the property does not exist.
        Returns:
        The double value of the property.
      • getDouble

        public static double getDouble​(java.lang.Object keyObj,
                                       java.lang.String defaultValue)
        Same as getDouble(java.lang.Object) but takes a default value if the property is not defined, instead of raising an exception.
        Parameters:
        keyObj - the object to call toString() on to get the desired property name
        defaultValue - The default value if the property does not exist.
        Returns:
        The double value of the property.
      • getCurrentPropertyPath

        public java.lang.String getCurrentPropertyPath()
        Returns the currently loaded property file path for debugging purposes
        Returns:
        the full path to the current properties file
      • getProperty

        public java.lang.String getProperty​(java.lang.String key)
        An override of the Java Properties.getProperty(String) method, but use getString(String) instead.
        Overrides:
        getProperty in class java.util.Properties
      • UNSAFE_setSingleton

        public static void UNSAFE_setSingleton​(java.lang.String propertyPath)
        Used only for testing, so do not call this in code.
        Parameters:
        propertyPath - The property path that determines the file properties are loaded from.