Class Tunable<T>
java.lang.Object
org.wpilib.tunable.TunableBase
org.wpilib.tunable.Tunable<T>
- Type Parameters:
T- value class
- Direct Known Subclasses:
Tunable.TunableProtobuf, Tunable.TunableStruct, Tunable.TunableStructArray
A tunable value.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields inherited from class TunableBase
m_changed -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedTunable(TunableConfig config) Constructs a tunable.protectedTunable(TunableConfig config, boolean supportsChangeNotification) Constructs a tunable. -
Method Summary
Modifier and TypeMethodDescriptionvoidstatic <T> Tunable<T> Creates a tunable object with the given getter and setter.static <T> Tunable<T> create(T initialValue) Creates a tunable object with the given initial value.static <T> Tunable<T> Creates a tunable object with a specific Protobuf serializer.static <T> Tunable<T> Creates a tunable object with a specific Struct serializer.static <T> Tunable<T> createConfig(Supplier<T> getter, Consumer<T> setter, Class<T> cls, TunableConfig config) Creates a tunable object with the given getter and setter and config.static <T> Tunable<T> createConfig(T initialValue, TunableConfig config) Creates a tunable object with the given config and initial value.static <T> Tunable<T> createConfig(T initialValue, Protobuf<T, ?> proto, TunableConfig config) Creates a tunable object with a specific Protobuf serializer.static <T> Tunable<T> createConfig(T initialValue, Struct<T> struct, TunableConfig config) Creates a tunable object with a specific Struct serializer.static <T> Tunable<T> createNull(Class<T> cls) Creates a tunable object with a null initial value.static <T> Tunable<T> createNullConfig(Class<T> cls, TunableConfig config) Creates a tunable object with the given config and a null initial value.abstract Tget()Gets the value.Gets the class of the tunable type.mutate()Gets the value for in-place mutation and marks this tunable changed.abstract voidSets the value.Methods inherited from class TunableBase
getConfig, getProperties, hasChanged, isRobust, markChanged, resetChanged, supportsChangeNotification
-
Constructor Details
-
Tunable
-
Tunable
Constructs a tunable.- Parameters:
config- tunable configsupportsChangeNotification- whether the tunable notifies backends when it changes
-
-
Method Details
-
createNull
-
createNullConfig
Creates a tunable object with the given config and a null initial value.- Type Parameters:
T- data type- Parameters:
cls- class of the tunable typeconfig- tunable config- Returns:
- Tunable
-
create
Creates a tunable object with the given initial value.- Type Parameters:
T- data type- Parameters:
initialValue- the initial value- Returns:
- Tunable
-
create
-
create
-
create
Creates a tunable object with the given getter and setter.The getter and setter must not throw.
- Type Parameters:
T- data type- Parameters:
getter- getter for the tunable valuesetter- setter for the tunable valuecls- class of the tunable type- Returns:
- Tunable
-
createConfig
Creates a tunable object with the given config and initial value.- Type Parameters:
T- data type- Parameters:
initialValue- the initial valueconfig- tunable config- Returns:
- Tunable
-
createConfig
Creates a tunable object with a specific Struct serializer.- Type Parameters:
T- data type- Parameters:
initialValue- the initial value (may be null)struct- struct serializerconfig- tunable config- Returns:
- Tunable
-
createConfig
public static <T> Tunable<T> createConfig(T initialValue, Protobuf<T, ?> proto, TunableConfig config) Creates a tunable object with a specific Protobuf serializer.- Type Parameters:
T- data type- Parameters:
initialValue- the initial value (may be null)proto- protobuf serializerconfig- tunable config- Returns:
- Tunable
-
createConfig
public static <T> Tunable<T> createConfig(Supplier<T> getter, Consumer<T> setter, Class<T> cls, TunableConfig config) Creates a tunable object with the given getter and setter and config.The getter and setter must not throw.
- Type Parameters:
T- data type- Parameters:
getter- getter for the tunable valuesetter- setter for the tunable valuecls- class of the tunable typeconfig- tunable config- Returns:
- Tunable
-
set
Sets the value.Implementations must not throw.
- Parameters:
value- value
-
get
-
mutate
Gets the value for in-place mutation and marks this tunable changed.This is useful for mutable structured/protobuf values where modifying the object returned by
get()would otherwise bypassset(Object)and not notify backends. For immutable values, preferset(Object). For variable-length arrays, useset(Object)with a new array to change the length.- Returns:
- mutable value
-
accept
-
getTypeClass
-