Class TunableConfig
java.lang.Object
org.wpilib.tunable.TunableConfig
Additional optional configuration for tunables. This class is immutable.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumDefines when the backend should poll the tunable's local value. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a TunableConfig with default configuration: no properties, robust=false, no type string, isMutable=true, no callback, and polling=DEFAULT.TunableConfig(Map<String, String> propertiesMap, boolean robust, String typeString, boolean isMutable, Runnable onTune, boolean alwaysGet) Creates a TunableConfig.TunableConfig(Map<String, String> propertiesMap, boolean robust, String typeString, boolean isMutable, Runnable onTune, TunableConfig.Polling polling) Creates a TunableConfig. -
Method Summary
Modifier and TypeMethodDescriptionReturns callback to call when the tunable is modified via tune().Returns when the backend should poll the tunable's local value.Gets properties as a JSON string.Returns the custom type string for the tunable.booleanReturns whether the tunable should always get its value.booleanReturns whether the tunable is mutable.booleanisRobust()Returns whether the tunable should separately echo back its new value after being set.static TunableConfigof(TunableOption... options) Creates a TunableConfig from an array of TunableOption.withAlwaysGet(boolean alwaysGet) Sets the polling behavior to always get or get on change.withMutable(boolean isMutable) Sets the mutable flag.withOnTune(Runnable onTune) Sets the onTune callback.withPolling(TunableConfig.Polling polling) Sets the polling behavior.withProperty(String key, String value) Sets a property value.withRobust(boolean robust) Sets the robust flag.withTypeString(String typeString) Sets the type string.
-
Constructor Details
-
TunableConfig
public TunableConfig()Creates a TunableConfig with default configuration: no properties, robust=false, no type string, isMutable=true, no callback, and polling=DEFAULT. -
TunableConfig
public TunableConfig(Map<String, String> propertiesMap, boolean robust, String typeString, boolean isMutable, Runnable onTune, boolean alwaysGet) Creates a TunableConfig.- Parameters:
propertiesMap- propertiesrobust- robust flagtypeString- type stringisMutable- mutable flagonTune- onTune callback; must not throwalwaysGet- always get flag
-
TunableConfig
public TunableConfig(Map<String, String> propertiesMap, boolean robust, String typeString, boolean isMutable, Runnable onTune, TunableConfig.Polling polling) Creates a TunableConfig.- Parameters:
propertiesMap- propertiesrobust- robust flagtypeString- type stringisMutable- mutable flagonTune- onTune callback; must not throwpolling- polling behavior
-
-
Method Details
-
of
Creates a TunableConfig from an array of TunableOption.- Parameters:
options- options- Returns:
- tunable config
-
withProperty
Sets a property value.- Parameters:
key- property keyvalue- property value; must be a valid JSON value string (e.g. quoted string, number, true, false, null, object, or array)- Returns:
- new TunableConfig with the property set
-
withRobust
Sets the robust flag.- Parameters:
robust- whether the tunable should separately echo back its value after setting- Returns:
- new TunableConfig with the robust flag set
-
withTypeString
Sets the type string.- Parameters:
typeString- the type string to use for the tunable- Returns:
- new TunableConfig with the type string set
-
withMutable
Sets the mutable flag.- Parameters:
isMutable- whether the tunable is mutable; setting this to false makes the tunable immutable, meaning that the Tunable's set() function will not be called- Returns:
- new TunableConfig with the mutable flag set
-
withOnTune
Sets the onTune callback.- Parameters:
onTune- callback to call when the tunable is modified via tune(); this is called immediately after the tunable's tune() function is called. The callback will be called byTunableRegistry.update(). This callback must not throw.- Returns:
- new TunableConfig with the onTune callback set
-
withAlwaysGet
Sets the polling behavior to always get or get on change.- Parameters:
alwaysGet- whether the tunable should always get its value- Returns:
- new TunableConfig with the polling behavior set
-
withPolling
Sets the polling behavior.- Parameters:
polling- polling behavior- Returns:
- new TunableConfig with the polling behavior set
-
getProperties
-
isRobust
public boolean isRobust()Returns whether the tunable should separately echo back its new value after being set.- Returns:
- whether the tunable is robust
-
getTypeString
Returns the custom type string for the tunable.- Returns:
- the type string, or null if none was set
-
isMutable
public boolean isMutable()Returns whether the tunable is mutable. Setting this to false makes the tunable immutable, meaning that the Tunable's set() function will not be called.- Returns:
- whether the tunable is mutable
-
getOnTune
Returns callback to call when the tunable is modified via tune(). This is called immediately after the tunable's tune() function is called. The callback will be called byTunableRegistry.update()and must not throw.- Returns:
- the onTune callback
-
isAlwaysGet
public boolean isAlwaysGet()Returns whether the tunable should always get its value.- Returns:
- whether the tunable should always get its value
-
getPolling
Returns when the backend should poll the tunable's local value.- Returns:
- polling behavior
-