[wpilib] Add init methods to Preferences (#2443)

This commit is contained in:
Prateek Machiraju
2020-04-01 23:26:49 -04:00
committed by GitHub
parent b9ee3ae030
commit 8f33d21bc2
3 changed files with 136 additions and 3 deletions

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */
/* Copyright (c) 2008-2020 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -31,6 +31,7 @@ import static edu.wpi.first.wpilibj.util.ErrorMessages.requireNonNullParam;
* <p> This will also interact with {@link NetworkTable} by creating a table called "Preferences"
* with all the key-value pairs. </p>
*/
@SuppressWarnings("PMD.TooManyMethods")
public final class Preferences {
/**
* The Preferences table name.
@@ -94,6 +95,17 @@ public final class Preferences {
entry.setPersistent();
}
/**
* Puts the given string into the preferences table if it doesn't already exist.
*
* @param key The key
* @param value The value
*/
public void initString(String key, String value) {
NetworkTableEntry entry = m_table.getEntry(key);
entry.setDefaultString(value);
}
/**
* Puts the given int into the preferences table.
*
@@ -106,6 +118,17 @@ public final class Preferences {
entry.setPersistent();
}
/**
* Puts the given int into the preferences table if it doesn't already exist.
*
* @param key The key
* @param value The value
*/
public void initInt(String key, int value) {
NetworkTableEntry entry = m_table.getEntry(key);
entry.setDefaultDouble(value);
}
/**
* Puts the given double into the preferences table.
*
@@ -118,6 +141,17 @@ public final class Preferences {
entry.setPersistent();
}
/**
* Puts the given double into the preferences table if it doesn't already exist.
*
* @param key The key
* @param value The value
*/
public void initDouble(String key, double value) {
NetworkTableEntry entry = m_table.getEntry(key);
entry.setDefaultDouble(value);
}
/**
* Puts the given float into the preferences table.
*
@@ -130,6 +164,17 @@ public final class Preferences {
entry.setPersistent();
}
/**
* Puts the given float into the preferences table if it doesn't already exist.
*
* @param key The key
* @param value The value
*/
public void initFloat(String key, float value) {
NetworkTableEntry entry = m_table.getEntry(key);
entry.setDefaultDouble(value);
}
/**
* Puts the given boolean into the preferences table.
*
@@ -142,6 +187,17 @@ public final class Preferences {
entry.setPersistent();
}
/**
* Puts the given boolean into the preferences table if it doesn't already exist.
*
* @param key The key
* @param value The value
*/
public void initBoolean(String key, boolean value) {
NetworkTableEntry entry = m_table.getEntry(key);
entry.setDefaultBoolean(value);
}
/**
* Puts the given long into the preferences table.
*
@@ -154,6 +210,17 @@ public final class Preferences {
entry.setPersistent();
}
/**
* Puts the given long into the preferences table if it doesn't already exist.
*
* @param key The key
* @param value The value
*/
public void initLong(String key, long value) {
NetworkTableEntry entry = m_table.getEntry(key);
entry.setDefaultDouble(value);
}
/**
* Returns whether or not there is a key with the given name.
*