Class Tunable<T>

java.lang.Object
org.wpilib.tunable.TunableBase
org.wpilib.tunable.Tunable<T>
Type Parameters:
T - value class
All Implemented Interfaces:
Consumer<T>, Supplier<T>
Direct Known Subclasses:
Tunable.TunableProtobuf, Tunable.TunableStruct, Tunable.TunableStructArray

public abstract class Tunable<T> extends TunableBase implements Supplier<T>, Consumer<T>
A tunable value.
  • Constructor Details

    • Tunable

      protected Tunable(TunableConfig config)
      Constructs a tunable.
      Parameters:
      config - tunable config
    • Tunable

      protected Tunable(TunableConfig config, boolean supportsChangeNotification)
      Constructs a tunable.
      Parameters:
      config - tunable config
      supportsChangeNotification - whether the tunable notifies backends when it changes
  • Method Details

    • createNull

      public static <T> Tunable<T> createNull(Class<T> cls)
      Creates a tunable object with a null initial value.
      Type Parameters:
      T - data type
      Parameters:
      cls - class of the tunable type
      Returns:
      Tunable
    • createNullConfig

      public static <T> Tunable<T> createNullConfig(Class<T> cls, TunableConfig config)
      Creates a tunable object with the given config and a null initial value.
      Type Parameters:
      T - data type
      Parameters:
      cls - class of the tunable type
      config - tunable config
      Returns:
      Tunable
    • create

      public static <T> Tunable<T> create(T initialValue)
      Creates a tunable object with the given initial value.
      Type Parameters:
      T - data type
      Parameters:
      initialValue - the initial value
      Returns:
      Tunable
    • create

      public static <T> Tunable<T> create(T initialValue, Struct<T> struct)
      Creates a tunable object with a specific Struct serializer.
      Type Parameters:
      T - data type
      Parameters:
      initialValue - the initial value
      struct - struct serializer
      Returns:
      Tunable
    • create

      public static <T> Tunable<T> create(T initialValue, Protobuf<T,?> proto)
      Creates a tunable object with a specific Protobuf serializer.
      Type Parameters:
      T - data type
      Parameters:
      initialValue - the initial value
      proto - protobuf serializer
      Returns:
      Tunable
    • create

      public static <T> Tunable<T> create(Supplier<T> getter, Consumer<T> setter, Class<T> cls)
      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 value
      setter - setter for the tunable value
      cls - class of the tunable type
      Returns:
      Tunable
    • createConfig

      public static <T> Tunable<T> createConfig(T initialValue, TunableConfig config)
      Creates a tunable object with the given config and initial value.
      Type Parameters:
      T - data type
      Parameters:
      initialValue - the initial value
      config - tunable config
      Returns:
      Tunable
    • createConfig

      public static <T> Tunable<T> createConfig(T initialValue, Struct<T> struct, TunableConfig config)
      Creates a tunable object with a specific Struct serializer.
      Type Parameters:
      T - data type
      Parameters:
      initialValue - the initial value (may be null)
      struct - struct serializer
      config - 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 serializer
      config - 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 value
      setter - setter for the tunable value
      cls - class of the tunable type
      config - tunable config
      Returns:
      Tunable
    • set

      public abstract void set(T value)
      Sets the value.

      Implementations must not throw.

      Parameters:
      value - value
    • get

      public abstract T get()
      Gets the value.

      Implementations must not throw.

      Specified by:
      get in interface Supplier<T>
      Returns:
      value
    • mutate

      public T 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 bypass set(Object) and not notify backends. For immutable values, prefer set(Object). For variable-length arrays, use set(Object) with a new array to change the length.

      Returns:
      mutable value
    • accept

      public void accept(T value)
      Specified by:
      accept in interface Consumer<T>
    • getTypeClass

      public abstract Class<T> getTypeClass()
      Gets the class of the tunable type. This is used for determining which type handler to use.
      Returns:
      class of the tunable type