From d6cfdd3bae529aa8def9cddcfaa6a387f461ae21 Mon Sep 17 00:00:00 2001 From: Noam Zaks Date: Thu, 6 May 2021 18:25:37 +0300 Subject: [PATCH] [wpilib] Preferences: Deprecate Put* in favor of Set* (#3337) This naming is more consistent with other APIs. Co-authored-by: Tyler Veness --- wpilibc/src/main/native/cpp/Preferences.cpp | 36 ++++++-- .../src/main/native/include/frc/Preferences.h | 68 +++++++++++++++ .../edu/wpi/first/wpilibj/Preferences.java | 86 +++++++++++++++++-- 3 files changed, 177 insertions(+), 13 deletions(-) diff --git a/wpilibc/src/main/native/cpp/Preferences.cpp b/wpilibc/src/main/native/cpp/Preferences.cpp index 8526c943b5..c80e966ca7 100644 --- a/wpilibc/src/main/native/cpp/Preferences.cpp +++ b/wpilibc/src/main/native/cpp/Preferences.cpp @@ -49,67 +49,91 @@ int64_t Preferences::GetLong(wpi::StringRef key, int64_t defaultValue) { return static_cast(m_table->GetNumber(key, defaultValue)); } -void Preferences::PutString(wpi::StringRef key, wpi::StringRef value) { +void Preferences::SetString(wpi::StringRef key, wpi::StringRef value) { auto entry = m_table->GetEntry(key); entry.SetString(value); entry.SetPersistent(); } +void Preferences::PutString(wpi::StringRef key, wpi::StringRef value) { + SetString(key, value); +} + void Preferences::InitString(wpi::StringRef key, wpi::StringRef value) { auto entry = m_table->GetEntry(key); entry.SetDefaultString(value); } -void Preferences::PutInt(wpi::StringRef key, int value) { +void Preferences::SetInt(wpi::StringRef key, int value) { auto entry = m_table->GetEntry(key); entry.SetDouble(value); entry.SetPersistent(); } +void Preferences::PutInt(wpi::StringRef key, int value) { + SetInt(key, value); +} + void Preferences::InitInt(wpi::StringRef key, int value) { auto entry = m_table->GetEntry(key); entry.SetDefaultDouble(value); } -void Preferences::PutDouble(wpi::StringRef key, double value) { +void Preferences::SetDouble(wpi::StringRef key, double value) { auto entry = m_table->GetEntry(key); entry.SetDouble(value); entry.SetPersistent(); } +void Preferences::PutDouble(wpi::StringRef key, double value) { + SetDouble(key, value); +} + void Preferences::InitDouble(wpi::StringRef key, double value) { auto entry = m_table->GetEntry(key); entry.SetDefaultDouble(value); } -void Preferences::PutFloat(wpi::StringRef key, float value) { +void Preferences::SetFloat(wpi::StringRef key, float value) { auto entry = m_table->GetEntry(key); entry.SetDouble(value); entry.SetPersistent(); } +void Preferences::PutFloat(wpi::StringRef key, float value) { + SetFloat(key, value); +} + void Preferences::InitFloat(wpi::StringRef key, float value) { auto entry = m_table->GetEntry(key); entry.SetDefaultDouble(value); } -void Preferences::PutBoolean(wpi::StringRef key, bool value) { +void Preferences::SetBoolean(wpi::StringRef key, bool value) { auto entry = m_table->GetEntry(key); entry.SetBoolean(value); entry.SetPersistent(); } +void Preferences::PutBoolean(wpi::StringRef key, bool value) { + SetBoolean(key, value); +} + void Preferences::InitBoolean(wpi::StringRef key, bool value) { auto entry = m_table->GetEntry(key); entry.SetDefaultBoolean(value); } -void Preferences::PutLong(wpi::StringRef key, int64_t value) { +void Preferences::SetLong(wpi::StringRef key, int64_t value) { auto entry = m_table->GetEntry(key); entry.SetDouble(value); entry.SetPersistent(); } +void Preferences::PutLong(wpi::StringRef key, int64_t value) { + SetLong(key, value); +} + void Preferences::InitLong(wpi::StringRef key, int64_t value) { auto entry = m_table->GetEntry(key); entry.SetDefaultDouble(value); diff --git a/wpilibc/src/main/native/include/frc/Preferences.h b/wpilibc/src/main/native/include/frc/Preferences.h index 7ecf25a008..c22c9af97e 100644 --- a/wpilibc/src/main/native/include/frc/Preferences.h +++ b/wpilibc/src/main/native/include/frc/Preferences.h @@ -11,6 +11,7 @@ #include #include +#include namespace frc { @@ -114,6 +115,18 @@ class Preferences { * @param key the key * @param value the value */ + void SetString(wpi::StringRef key, wpi::StringRef value); + + /** + * Puts the given string into the preferences table. + * + * The value may not have quotation marks, nor may the key have any whitespace + * nor an equals sign. + * + * @param key the key + * @param value the value + */ + WPI_DEPRECATED("Use SetString instead.") void PutString(wpi::StringRef key, wpi::StringRef value); /** @@ -130,6 +143,17 @@ class Preferences { * @param key the key * @param value the value */ + void SetInt(wpi::StringRef key, int value); + + /** + * Puts the given int into the preferences table. + * + * The key may not have any whitespace nor an equals sign. + * + * @param key the key + * @param value the value + */ + WPI_DEPRECATED("Use SetInt instead.") void PutInt(wpi::StringRef key, int value); /** @@ -146,6 +170,17 @@ class Preferences { * @param key the key * @param value the value */ + void SetDouble(wpi::StringRef key, double value); + + /** + * Puts the given double into the preferences table. + * + * The key may not have any whitespace nor an equals sign. + * + * @param key the key + * @param value the value + */ + WPI_DEPRECATED("Use SetDouble instead.") void PutDouble(wpi::StringRef key, double value); /** @@ -162,6 +197,17 @@ class Preferences { * @param key the key * @param value the value */ + void SetFloat(wpi::StringRef key, float value); + + /** + * Puts the given float into the preferences table. + * + * The key may not have any whitespace nor an equals sign. + * + * @param key the key + * @param value the value + */ + WPI_DEPRECATED("Use SetFloat instead.") void PutFloat(wpi::StringRef key, float value); /** @@ -178,6 +224,17 @@ class Preferences { * @param key the key * @param value the value */ + void SetBoolean(wpi::StringRef key, bool value); + + /** + * Puts the given boolean into the preferences table. + * + * The key may not have any whitespace nor an equals sign. + * + * @param key the key + * @param value the value + */ + WPI_DEPRECATED("Use SetBoolean instead.") void PutBoolean(wpi::StringRef key, bool value); /** @@ -194,6 +251,17 @@ class Preferences { * @param key the key * @param value the value */ + void SetLong(wpi::StringRef key, int64_t value); + + /** + * Puts the given long (int64_t) into the preferences table. + * + * The key may not have any whitespace nor an equals sign. + * + * @param key the key + * @param value the value + */ + WPI_DEPRECATED("Use SetLong instead.") void PutLong(wpi::StringRef key, int64_t value); /** diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Preferences.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Preferences.java index 018b0b24fd..43a8b02ac3 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Preferences.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Preferences.java @@ -75,14 +75,27 @@ public final class Preferences { * @param value the value * @throws NullPointerException if value is null */ - public void putString(String key, String value) { - requireNonNullParam(value, "value", "putString"); + public void setString(String key, String value) { + requireNonNullParam(value, "value", "setString"); NetworkTableEntry entry = m_table.getEntry(key); entry.setString(value); entry.setPersistent(); } + /** + * Puts the given string into the preferences table. + * + * @param key the key + * @param value the value + * @throws NullPointerException if value is null + * @deprecated Use {@link #setString(String, String)} + */ + @Deprecated + public void putString(String key, String value) { + setString(key, value); + } + /** * Puts the given string into the preferences table if it doesn't already exist. * @@ -100,12 +113,24 @@ public final class Preferences { * @param key the key * @param value the value */ - public void putInt(String key, int value) { + public void setInt(String key, int value) { NetworkTableEntry entry = m_table.getEntry(key); entry.setDouble(value); entry.setPersistent(); } + /** + * Puts the given int into the preferences table. + * + * @param key the key + * @param value the value + * @deprecated Use {@link #setInt(String, int)} + */ + @Deprecated + public void putInt(String key, int value) { + setInt(key, value); + } + /** * Puts the given int into the preferences table if it doesn't already exist. * @@ -123,12 +148,23 @@ public final class Preferences { * @param key the key * @param value the value */ - public void putDouble(String key, double value) { + public void setDouble(String key, double value) { NetworkTableEntry entry = m_table.getEntry(key); entry.setDouble(value); entry.setPersistent(); } + /** + * Puts the given double into the preferences table. + * + * @param key the key + * @param value the value + * @deprecated Use {@link #setDouble(String, double)} + */ + public void putDouble(String key, double value) { + setDouble(key, value); + } + /** * Puts the given double into the preferences table if it doesn't already exist. * @@ -146,12 +182,24 @@ public final class Preferences { * @param key the key * @param value the value */ - public void putFloat(String key, float value) { + public void setFloat(String key, float value) { NetworkTableEntry entry = m_table.getEntry(key); entry.setDouble(value); entry.setPersistent(); } + /** + * Puts the given float into the preferences table. + * + * @param key the key + * @param value the value + * @deprecated Use {@link #setFloat(String, float)} + */ + @Deprecated + public void putFloat(String key, float value) { + setFloat(key, value); + } + /** * Puts the given float into the preferences table if it doesn't already exist. * @@ -169,12 +217,24 @@ public final class Preferences { * @param key the key * @param value the value */ - public void putBoolean(String key, boolean value) { + public void setBoolean(String key, boolean value) { NetworkTableEntry entry = m_table.getEntry(key); entry.setBoolean(value); entry.setPersistent(); } + /** + * Puts the given boolean into the preferences table. + * + * @param key the key + * @param value the value + * @deprecated Use {@link #setBoolean(String, boolean)} + */ + @Deprecated + public void putBoolean(String key, boolean value) { + setBoolean(key, value); + } + /** * Puts the given boolean into the preferences table if it doesn't already exist. * @@ -192,12 +252,24 @@ public final class Preferences { * @param key the key * @param value the value */ - public void putLong(String key, long value) { + public void setLong(String key, long value) { NetworkTableEntry entry = m_table.getEntry(key); entry.setDouble(value); entry.setPersistent(); } + /** + * Puts the given long into the preferences table. + * + * @param key the key + * @param value the value + * @deprecated Use {@link #setLong(String, long)} + */ + @Deprecated + public void putLong(String key, long value) { + setLong(key, value); + } + /** * Puts the given long into the preferences table if it doesn't already exist. *