Class Selectable<V>

java.lang.Object
org.wpilib.tunable.Selectable<V>
Type Parameters:
V - The type of the values to be stored
All Implemented Interfaces:
ComplexTunable

public final class Selectable<V> extends Object implements ComplexTunable
The Selectable class is a useful tool for presenting a selection of options as a tunable.
  • Constructor Details

    • Selectable

      public Selectable()
      Constructs a selectable tunable.
  • Method Details

    • add

      public void add(String name, V object)
      Adds the given object to the list of options.
      Parameters:
      name - the name of the option
      object - the option
    • addDefault

      public void addDefault(String name, V object)
      Adds the given object to the list of options and marks it as the default.
      Parameters:
      name - the name of the option
      object - the option
    • remove

      public void remove(String name)
      Removes the option with the given name. If the removed option is the default, the default is reset. Does not change the selected option; getSelected() will fall back to the default after this is called if the selected option name no longer matches an option.
      Parameters:
      name - the name of the option
    • setDefault

      public void setDefault(String name)
      Marks the given option as the default.
      Parameters:
      name - the name of the option
    • clear

      public void clear()
      Clears the list of options and resets the default. Does not change the selected option; getSelected() will return null after this is called until a new matching option or default is added.
    • getSelected

      public V getSelected()
      Returns the selected option. If there is none selected, it will return the default. If there is none or invalid option selected and no default, then it will return null.
      Returns:
      the option selected
    • onChange

      public void onChange(Consumer<V> listener)
      Bind a listener that's called when the selected value changes. Only one listener can be bound. Calling this function will replace the previous listener.
      Parameters:
      listener - The function to call that accepts the new value
    • publishTunable

      public void publishTunable(TunableTable table)
      Description copied from interface: ComplexTunable
      Publishes the tunable to the given table.

      This function may be called when the tunable is initially published or republished during backend migration, and it must not throw. If an exception escapes, registry and backend state is not guaranteed to be restored.

      Specified by:
      publishTunable in interface ComplexTunable
      Parameters:
      table - table
    • getTunableType

      public String getTunableType()
      Description copied from interface: ComplexTunable
      Gets the tunable table type. Default is no specified table type (null).
      Specified by:
      getTunableType in interface ComplexTunable
      Returns:
      Table type