Package com.alumiboti5590.eop.properties
Class RobotProperty
- java.lang.Object
-
- java.util.Dictionary<K,V>
-
- java.util.Hashtable<java.lang.Object,java.lang.Object>
-
- java.util.Properties
-
- com.alumiboti5590.eop.properties.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 theFilesystem.getDeployDirectory()
provided by WPILib.Access to properties should be done via the
getAs...
static methods, such asgetString()
,getInt()
,getDouble()
, andgetBoolean()
. 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
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static boolean
getBoolean(java.lang.Object keyObj)
Same asgetBoolean(java.lang.String)
but takes anything with atoString()
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 asgetBoolean(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 asgetBoolean(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 purposesstatic double
getDouble(java.lang.Object keyObj)
Same asgetDouble(java.lang.String)
but takes anything with atoString()
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 asgetDouble(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 asgetDouble(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 asgetInt(java.lang.String)
but takes anything with atoString()
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 asgetInt(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 asgetInt(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 JavaProperties.getProperty(String)
method, but usegetString(String)
instead.static java.lang.String
getString(java.lang.Object keyObj)
Same asgetString(java.lang.String)
but takes anything with atoString()
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 asgetString(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 asgetString(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
-
-
-
-
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. AnInvalidParameterException
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 asgetString(java.lang.String)
but takes anything with atoString()
method - which is everything in Java - so you can pass enumerations and the sort.- Parameters:
keyObj
- the object to calltoString()
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 asgetString(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 asgetString(java.lang.Object)
but takes a default value if the property is not defined, instead of raising an exception.- Parameters:
keyObj
- the object to calltoString()
on to get the desired property namedefaultValue
- 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. AnInvalidParameterException
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 asgetInt(java.lang.String)
but takes anything with atoString()
method - which is everything in Java - so you can pass enumerations and the sort.- Parameters:
keyObj
- the object to calltoString()
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 asgetInt(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 asgetInt(java.lang.Object)
but takes a default value if the property is not defined, instead of raising an exception.- Parameters:
keyObj
- the object to calltoString()
on to get the desired property namedefaultValue
- 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. AnInvalidParameterException
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 asgetBoolean(java.lang.String)
but takes anything with atoString()
method - which is everything in Java - so you can pass enumerations and the sort.- Parameters:
keyObj
- the object to calltoString()
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 asgetBoolean(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 asgetBoolean(java.lang.Object)
but takes a default value if the property is not defined, instead of raising an exception.- Parameters:
keyObj
- the object to calltoString()
on to get the desired property namedefaultValue
- 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. AnInvalidParameterException
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 asgetDouble(java.lang.String)
but takes anything with atoString()
method - which is everything in Java - so you can pass enumerations and the sort.- Parameters:
keyObj
- the object to calltoString()
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 asgetDouble(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 asgetDouble(java.lang.Object)
but takes a default value if the property is not defined, instead of raising an exception.- Parameters:
keyObj
- the object to calltoString()
on to get the desired property namedefaultValue
- 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 JavaProperties.getProperty(String)
method, but usegetString(String)
instead.- Overrides:
getProperty
in classjava.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.
-
-