Package org.hyperonline.hyperlib.pref
Class Preference
- java.lang.Object
-
- org.hyperonline.hyperlib.pref.Preference
-
- Direct Known Subclasses:
BooleanPreference
,DoublePreference
,IntPreference
,StringPreference
public abstract class Preference extends java.lang.Object
ThePreference
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. BecausePreferences
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 newPreference
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.
-
-
-
Constructor Detail
-
Preference
public Preference(java.lang.String name)
Create a newPreference
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.
-
-