public class Preferences extends java.lang.Object
This class loads and saves from a file inside the roboRIO. The user can not access the file directly, but may modify values at specific fields which will then be automatically saved to the file by the NetworkTables server.
This class is thread safe.
This will also interact with NetworkTable
by creating a table called "Preferences"
with all the key-value pairs.
Modifier and Type | Method and Description |
---|---|
boolean |
containsKey(java.lang.String key)
Returns whether or not there is a key with the given name.
|
boolean |
getBoolean(java.lang.String key,
boolean backup)
Returns the boolean at the given key.
|
double |
getDouble(java.lang.String key,
double backup)
Returns the double at the given key.
|
float |
getFloat(java.lang.String key,
float backup)
Returns the float at the given key.
|
static Preferences |
getInstance()
Returns the preferences instance.
|
int |
getInt(java.lang.String key,
int backup)
Returns the int at the given key.
|
java.util.Vector |
getKeys()
Gets the vector of keys.
|
long |
getLong(java.lang.String key,
long backup)
Returns the long at the given key.
|
java.lang.String |
getString(java.lang.String key,
java.lang.String backup)
Returns the string at the given key.
|
void |
putBoolean(java.lang.String key,
boolean value)
Puts the given boolean into the preferences table.
|
void |
putDouble(java.lang.String key,
double value)
Puts the given double into the preferences table.
|
void |
putFloat(java.lang.String key,
float value)
Puts the given float into the preferences table.
|
void |
putInt(java.lang.String key,
int value)
Puts the given int into the preferences table.
|
void |
putLong(java.lang.String key,
long value)
Puts the given long into the preferences table.
|
void |
putString(java.lang.String key,
java.lang.String value)
Puts the given string into the preferences table.
|
void |
remove(java.lang.String key)
Remove a preference.
|
void |
save()
Deprecated.
backwards compatibility shim
|
public static Preferences getInstance()
public java.util.Vector getKeys()
public void putString(java.lang.String key, java.lang.String value)
key
- the keyvalue
- the valuejava.lang.NullPointerException
- if value is nullpublic void putInt(java.lang.String key, int value)
key
- the keyvalue
- the valuepublic void putDouble(java.lang.String key, double value)
key
- the keyvalue
- the valuepublic void putFloat(java.lang.String key, float value)
key
- the keyvalue
- the valuepublic void putBoolean(java.lang.String key, boolean value)
key
- the keyvalue
- the valuepublic void putLong(java.lang.String key, long value)
key
- the keyvalue
- the valuepublic boolean containsKey(java.lang.String key)
key
- the keypublic void remove(java.lang.String key)
key
- the keypublic java.lang.String getString(java.lang.String key, java.lang.String backup)
key
- the keybackup
- the value to return if none exists in the tablepublic int getInt(java.lang.String key, int backup)
key
- the keybackup
- the value to return if none exists in the tablepublic double getDouble(java.lang.String key, double backup)
key
- the keybackup
- the value to return if none exists in the tablepublic boolean getBoolean(java.lang.String key, boolean backup)
key
- the keybackup
- the value to return if none exists in the tablepublic float getFloat(java.lang.String key, float backup)
key
- the keybackup
- the value to return if none exists in the tablepublic long getLong(java.lang.String key, long backup)
key
- the keybackup
- the value to return if none exists in the table@Deprecated public void save()