Package edu.wpi.first.wpilibj
Class Preferences
java.lang.Object
edu.wpi.first.wpilibj.Preferences
The preferences class provides a relatively simple way to save important values to the roboRIO to
access the next time the roboRIO is booted.
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.
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleancontainsKey(String key) Returns whether there is a key with the given name.static booleangetBoolean(String key, boolean backup) Returns the boolean at the given key.static doubleReturns the double at the given key.static floatReturns the float at the given key.static intReturns the int at the given key.static Collection<String>getKeys()Gets the preferences keys.static longReturns the long at the given key.static StringReturns the string at the given key.static voidinitBoolean(String key, boolean value) Puts the given boolean into the preferences table if it doesn't already exist.static voidinitDouble(String key, double value) Puts the given double into the preferences table if it doesn't already exist.static voidPuts the given float into the preferences table if it doesn't already exist.static voidPuts the given int into the preferences table if it doesn't already exist.static voidPuts the given long into the preferences table if it doesn't already exist.static voidinitString(String key, String value) Puts the given string into the preferences table if it doesn't already exist.static voidRemove a preference.static voidRemove all preferences.static voidsetBoolean(String key, boolean value) Puts the given boolean into the preferences table.static voidPuts the given double into the preferences table.static voidPuts the given float into the preferences table.static voidPuts the given int into the preferences table.static voidPuts the given long into the preferences table.static voidSet the NetworkTable instance used for entries.static voidPuts the given string into the preferences table.
-
Method Details
-
setNetworkTableInstance
Set the NetworkTable instance used for entries. For testing purposes; use with caution.- Parameters:
inst- NetworkTable instance
-
getKeys
Gets the preferences keys.- Returns:
- a collection of the keys
-
setString
Puts the given string into the preferences table.- Parameters:
key- the keyvalue- the value- Throws:
NullPointerException- if value is null
-
initString
Puts the given string into the preferences table if it doesn't already exist.- Parameters:
key- The keyvalue- The value
-
setInt
Puts the given int into the preferences table.- Parameters:
key- the keyvalue- the value
-
initInt
Puts the given int into the preferences table if it doesn't already exist.- Parameters:
key- The keyvalue- The value
-
setDouble
Puts the given double into the preferences table.- Parameters:
key- the keyvalue- the value
-
initDouble
Puts the given double into the preferences table if it doesn't already exist.- Parameters:
key- The keyvalue- The value
-
setFloat
Puts the given float into the preferences table.- Parameters:
key- the keyvalue- the value
-
initFloat
Puts the given float into the preferences table if it doesn't already exist.- Parameters:
key- The keyvalue- The value
-
setBoolean
Puts the given boolean into the preferences table.- Parameters:
key- the keyvalue- the value
-
initBoolean
Puts the given boolean into the preferences table if it doesn't already exist.- Parameters:
key- The keyvalue- The value
-
setLong
Puts the given long into the preferences table.- Parameters:
key- the keyvalue- the value
-
initLong
Puts the given long into the preferences table if it doesn't already exist.- Parameters:
key- The keyvalue- The value
-
containsKey
Returns whether there is a key with the given name.- Parameters:
key- the key- Returns:
- if there is a value at the given key
-
remove
Remove a preference.- Parameters:
key- the key
-
removeAll
Remove all preferences. -
getString
Returns the string at the given key. If this table does not have a value for that position, then the given backup value will be returned.- Parameters:
key- the keybackup- the value to return if none exists in the table- Returns:
- either the value in the table, or the backup
-
getInt
Returns the int at the given key. If this table does not have a value for that position, then the given backup value will be returned.- Parameters:
key- the keybackup- the value to return if none exists in the table- Returns:
- either the value in the table, or the backup
-
getDouble
Returns the double at the given key. If this table does not have a value for that position, then the given backup value will be returned.- Parameters:
key- the keybackup- the value to return if none exists in the table- Returns:
- either the value in the table, or the backup
-
getBoolean
Returns the boolean at the given key. If this table does not have a value for that position, then the given backup value will be returned.- Parameters:
key- the keybackup- the value to return if none exists in the table- Returns:
- either the value in the table, or the backup
-
getFloat
Returns the float at the given key. If this table does not have a value for that position, then the given backup value will be returned.- Parameters:
key- the keybackup- the value to return if none exists in the table- Returns:
- either the value in the table, or the backup
-
getLong
Returns the long at the given key. If this table does not have a value for that position, then the given backup value will be returned.- Parameters:
key- the keybackup- the value to return if none exists in the table- Returns:
- either the value in the table, or the backup
-