|
" 2013 FRC Java API " |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.wpi.first.wpilibj.Preferences
public class Preferences
The preferences class provides a relatively simple way to save important values to the cRIO to access the next time the cRIO is booted.
This class loads and saves from a file
inside the cRIO. The user can not access the file directly, but may modify values at specific
fields which will then be saved to the file when save()
is called.
This class is thread safe.
This will also interact with NetworkTable
by creating a table called "Preferences" with all the
key-value pairs. To save using NetworkTable
, simply set the boolean at position ~S A V E~ to true.
Also, if the value of any variable is " in the NetworkTable
, then that represents non-existence in the
Preferences
table
Nested Class Summary | |
---|---|
static class |
Preferences.ImproperPreferenceKeyException
Should be thrown if a string can not be used as a key in the preferences file. |
static class |
Preferences.IncompatibleTypeException
This exception is thrown if the a value requested cannot be converted to the requested type. |
Method Summary | |
---|---|
boolean |
containsKey(String key)
Returns whether or not there is a key with the given name. |
boolean |
getBoolean(String key,
boolean backup)
Returns the boolean at the given key. |
double |
getDouble(String key,
double backup)
Returns the double at the given key. |
float |
getFloat(String key,
float backup)
Returns the float at the given key. |
static Preferences |
getInstance()
Returns the preferences instance. |
int |
getInt(String key,
int backup)
Returns the int at the given key. |
Vector |
getKeys()
|
long |
getLong(String key,
long backup)
Returns the long at the given key. |
String |
getString(String key,
String backup)
Returns the string at the given key. |
void |
putBoolean(String key,
boolean value)
Puts the given boolean into the preferences table. |
void |
putDouble(String key,
double value)
Puts the given double into the preferences table. |
void |
putFloat(String key,
float value)
Puts the given float into the preferences table. |
void |
putInt(String key,
int value)
Puts the given int into the preferences table. |
void |
putLong(String key,
long value)
Puts the given long into the preferences table. |
void |
putString(String key,
String value)
Puts the given string into the preferences table. |
void |
remove(String key)
Remove a preference |
void |
save()
Saves the preferences to a file on the cRIO. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static Preferences getInstance()
public Vector getKeys()
public void putString(String key, String value)
The value may not have quotation marks, nor may the key have any whitespace nor an equals sign
This will NOT save the value to memory between power cycles,
to do that you must call save()
(which must be used with care).
at some point after calling this.
key
- the keyvalue
- the value
NullPointerException
- if value is null
IllegalArgumentException
- if value contains a quotation mark
Preferences.ImproperPreferenceKeyException
- if the key contains any whitespace or an equals signpublic void putInt(String key, int value)
The key may not have any whitespace nor an equals sign
This will NOT save the value to memory between power cycles,
to do that you must call save()
(which must be used with care)
at some point after calling this.
key
- the keyvalue
- the value
Preferences.ImproperPreferenceKeyException
- if the key contains any whitespace or an equals signpublic void putDouble(String key, double value)
The key may not have any whitespace nor an equals sign
This will NOT save the value to memory between power cycles,
to do that you must call save()
(which must be used with care)
at some point after calling this.
key
- the keyvalue
- the value
Preferences.ImproperPreferenceKeyException
- if the key contains any whitespace or an equals signpublic void putFloat(String key, float value)
The key may not have any whitespace nor an equals sign
This will NOT save the value to memory between power cycles,
to do that you must call save()
(which must be used with care)
at some point after calling this.
key
- the keyvalue
- the value
Preferences.ImproperPreferenceKeyException
- if the key contains any whitespace or an equals signpublic void putBoolean(String key, boolean value)
The key may not have any whitespace nor an equals sign
This will NOT save the value to memory between power cycles,
to do that you must call save()
(which must be used with care)
at some point after calling this.
key
- the keyvalue
- the value
Preferences.ImproperPreferenceKeyException
- if the key contains any whitespace or an equals signpublic void putLong(String key, long value)
The key may not have any whitespace nor an equals sign
This will NOT save the value to memory between power cycles,
to do that you must call save()
(which must be used with care)
at some point after calling this.
key
- the keyvalue
- the value
Preferences.ImproperPreferenceKeyException
- if the key contains any whitespace or an equals signpublic boolean containsKey(String key)
key
- the key
NullPointerException
- if key is nullpublic void remove(String key)
key
- the key
NullPointerException
- if key is nullpublic String getString(String key, String backup)
key
- the keybackup
- the value to return if none exists in the table
NullPointerException
- if the key is nullpublic int getInt(String key, int backup)
key
- the keybackup
- the value to return if none exists in the table
Preferences.IncompatibleTypeException
- if the value in the table can not be converted to an intpublic double getDouble(String key, double backup)
key
- the keybackup
- the value to return if none exists in the table
Preferences.IncompatibleTypeException
- if the value in the table can not be converted to an doublepublic boolean getBoolean(String key, boolean backup)
key
- the keybackup
- the value to return if none exists in the table
Preferences.IncompatibleTypeException
- if the value in the table can not be converted to a booleanpublic float getFloat(String key, float backup)
key
- the keybackup
- the value to return if none exists in the table
Preferences.IncompatibleTypeException
- if the value in the table can not be converted to a floatpublic long getLong(String key, long backup)
key
- the keybackup
- the value to return if none exists in the table
Preferences.IncompatibleTypeException
- if the value in the table can not be converted to a longpublic void save()
This should NOT be called often.
Too many writes can damage the cRIO's flash memory.
While it is ok to save once or twice a match, this should never
be called every run of IterativeRobot.teleopPeriodic()
.
The actual writing of the file is done in a separate thread. However, any call to a get or put method will wait until the table is fully saved before continuing.
|
" 2013 FRC Java API " |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |