Class Preference

  • Direct Known Subclasses:
    BooleanPreference, DoublePreference, IntPreference, StringPreference

    public abstract class Preference
    extends java.lang.Object
    The Preference class is an abstract class representing a single preference entry in the preferences file. This is used to perform common operations, like checking if the preference is set, and putting the default value. Because Preferences in WPILib is not generic, we must use an abstract class with subclasses for each type of preference.
    See Also:
    Preferences
    • Constructor Summary

      Constructors 
      Constructor Description
      Preference​(java.lang.String name)
      Create a new Preference with the given name.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String getName()
      The name is the string id of the preference, as it appears on the dashboard and in the preferences file.
      protected abstract boolean hasChanged()
      Check if the value has changed since last being checked, or if this is the first time this method was called and the value has changed from the default.
      void putDefaultIfEmpty()
      Check if a preference with the same name as this one already exists in the preferences file.
      protected abstract void putDefaultValue()
      Put an entry with the default value.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Preference

        public Preference​(java.lang.String name)
        Create a new Preference with the given name. No modification is made yet to the preferences file.
        Parameters:
        name - The string id of the preference
    • Method Detail

      • getName

        public java.lang.String getName()
        The name is the string id of the preference, as it appears on the dashboard and in the preferences file.
        Returns:
        The name of the preference
      • putDefaultIfEmpty

        public void putDefaultIfEmpty()
        Check if a preference with the same name as this one already exists in the preferences file. If not, then create the preference using the default value.
      • hasChanged

        protected abstract boolean hasChanged()
        Check if the value has changed since last being checked, or if this is the first time this method was called and the value has changed from the default.
        Returns:
        true if the value has changed, false otherwise
      • putDefaultValue

        protected abstract void putDefaultValue()
        Put an entry with the default value.