From d910b0b2a2e9481f03e41d3719862bd054137ce4 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Fri, 4 Aug 2017 14:02:28 -0500 Subject: [PATCH] Remove deprecated throwing get functions. (#213) --- .../wpilibj/networktables/NetworkTable.java | 162 +------------- .../NetworkTableKeyNotDefined.java | 23 -- .../networktables/NetworkTablesJNI.java | 12 -- .../edu/wpi/first/wpilibj/tables/ITable.java | 162 +------------- .../tables/TableKeyNotDefinedException.java | 20 -- src/main/native/cpp/jni/NetworkTablesJNI.cpp | 204 +----------------- .../native/cpp/networktables/NetworkTable.cpp | 31 --- .../tables/TableKeyNotDefinedException.cpp | 19 -- .../include/networktables/NetworkTable.h | 45 ---- src/main/native/include/tables/ITable.h | 45 ---- .../tables/TableKeyNotDefinedException.h | 36 ---- 11 files changed, 12 insertions(+), 747 deletions(-) delete mode 100644 src/main/java/edu/wpi/first/wpilibj/networktables/NetworkTableKeyNotDefined.java delete mode 100644 src/main/java/edu/wpi/first/wpilibj/tables/TableKeyNotDefinedException.java delete mode 100644 src/main/native/cpp/tables/TableKeyNotDefinedException.cpp delete mode 100644 src/main/native/include/tables/TableKeyNotDefinedException.h diff --git a/src/main/java/edu/wpi/first/wpilibj/networktables/NetworkTable.java b/src/main/java/edu/wpi/first/wpilibj/networktables/NetworkTable.java index 009e45b..1f813c8 100644 --- a/src/main/java/edu/wpi/first/wpilibj/networktables/NetworkTable.java +++ b/src/main/java/edu/wpi/first/wpilibj/networktables/NetworkTable.java @@ -562,17 +562,6 @@ public boolean setDefaultNumber(String key, double defaultValue) { defaultValue); } - /** - * {@inheritDoc} - * @deprecated This exception-raising method has been replaced by the - * default-taking method {@link #getNumber(String, double)}. - */ - @Override - @Deprecated - public double getNumber(String key) throws TableKeyNotDefinedException { - return NetworkTablesJNI.getDouble(pathWithSep + key); - } - /** * {@inheritDoc} */ @@ -597,17 +586,6 @@ public boolean setDefaultString(String key, String defaultValue) { defaultValue); } - /** - * {@inheritDoc} - * @deprecated This exception-raising method has been replaced by the - * default-taking method {@link #getString(String, String)}. - */ - @Override - @Deprecated - public String getString(String key) throws TableKeyNotDefinedException { - return NetworkTablesJNI.getString(pathWithSep + key); - } - /** * {@inheritDoc} */ @@ -632,17 +610,6 @@ public boolean setDefaultBoolean(String key, boolean defaultValue) { defaultValue); } - /** - * {@inheritDoc} - * @deprecated This exception-raising method has been replaced by the - * default-taking method {@link #getBoolean(String, boolean)}. - */ - @Override - @Deprecated - public boolean getBoolean(String key) throws TableKeyNotDefinedException { - return NetworkTablesJNI.getBoolean(pathWithSep + key); - } - /** * {@inheritDoc} */ @@ -683,17 +650,6 @@ public boolean setDefaultBooleanArray(String key, Boolean[] defaultValue) { toNative(defaultValue)); } - /** - * {@inheritDoc} - * @deprecated This exception-raising method has been replaced by the - * default-taking method {@link #getBooleanArray(String, boolean[])}. - */ - @Override - @Deprecated - public boolean[] getBooleanArray(String key) throws TableKeyNotDefinedException { - return NetworkTablesJNI.getBooleanArray(pathWithSep + key); - } - /** * {@inheritDoc} */ @@ -707,11 +663,7 @@ public boolean[] getBooleanArray(String key, boolean[] defaultValue) { */ @Override public Boolean[] getBooleanArray(String key, Boolean[] defaultValue) { - try { - return fromNative(getBooleanArray(key)); - } catch (TableKeyNotDefinedException e) { - return defaultValue; - } + return fromNative(getBooleanArray(key, toNative(defaultValue))); } /** @@ -746,17 +698,6 @@ public boolean setDefaultNumberArray(String key, Double[] defaultValue) { toNative(defaultValue)); } - /** - * {@inheritDoc} - * @deprecated This exception-raising method has been replaced by the - * default-taking method {@link #getNumberArray(String, double[])}. - */ - @Override - @Deprecated - public double[] getNumberArray(String key) throws TableKeyNotDefinedException { - return NetworkTablesJNI.getDoubleArray(pathWithSep + key); - } - /** * {@inheritDoc} */ @@ -770,11 +711,7 @@ public double[] getNumberArray(String key, double[] defaultValue) { */ @Override public Double[] getNumberArray(String key, Double[] defaultValue) { - try { - return fromNative(getNumberArray(key)); - } catch (TableKeyNotDefinedException e) { - return defaultValue; - } + return fromNative(getNumberArray(key, toNative(defaultValue))); } /** @@ -793,17 +730,6 @@ public boolean setDefaultStringArray(String key, String[] defaultValue) { defaultValue); } - /** - * {@inheritDoc} - * @deprecated This exception-raising method has been replaced by the - * default-taking method {@link #getStringArray(String, String[])}. - */ - @Override - @Deprecated - public String[] getStringArray(String key) throws TableKeyNotDefinedException { - return NetworkTablesJNI.getStringArray(pathWithSep + key); - } - /** * {@inheritDoc} */ @@ -840,17 +766,6 @@ public boolean putRaw(String key, ByteBuffer value, int len) { return NetworkTablesJNI.putRaw(pathWithSep + key, value, len); } - /** - * {@inheritDoc} - * @deprecated This exception-raising method has been replaced by the - * default-taking method {@link #getRaw(String, byte[])}. - */ - @Override - @Deprecated - public byte[] getRaw(String key) throws TableKeyNotDefinedException { - return NetworkTablesJNI.getRaw(pathWithSep + key); - } - /** * {@inheritDoc} */ @@ -892,35 +807,6 @@ else if (value instanceof StringArray) throw new IllegalArgumentException("Value of type " + value.getClass().getName() + " cannot be put into a table"); } - /** - * {@inheritDoc} - * @deprecated Use get*Array functions instead. - */ - @Override - @Deprecated - public void retrieveValue(String key, Object externalData) throws TableKeyNotDefinedException { - Object value = getValue(key); - if (value instanceof boolean[] && externalData instanceof BooleanArray) - ((ArrayData)externalData).setDataArray(fromNative((boolean[])value)); - else if (value instanceof double[] && externalData instanceof NumberArray) - ((ArrayData)externalData).setDataArray(fromNative((double[])value)); - else if (value instanceof String[] && externalData instanceof StringArray) - ((ArrayData)externalData).setDataArray((String[])value); - else - throw new TableKeyNotDefinedException(key); - } - - /** - * {@inheritDoc} - * @deprecated This exception-raising method has been replaced by the - * default-taking method {@link #getValue(String, Object)}. - */ - @Override - @Deprecated - public Object getValue(String key) throws TableKeyNotDefinedException { - return NetworkTablesJNI.getValue(pathWithSep + key); - } - /** * {@inheritDoc} */ @@ -1039,40 +925,6 @@ public static String[] loadPersistent(String filename) throws PersistentExceptio * Deprecated Methods */ - /** - * {@inheritDoc} - * @deprecated Use {@link #putNumber(String, double)} instead. - */ - @Override - @Deprecated - public boolean putInt(String key, int value) { - return putNumber(key, value); - } - - /** - * {@inheritDoc} - * @deprecated Use {@link #getNumber(String, double)} instead. - */ - @Override - @Deprecated - public int getInt(String key) throws TableKeyNotDefinedException { - return (int)getNumber(key); - } - - /** - * {@inheritDoc} - * @deprecated Use {@link #getNumber(String, double)} instead. - */ - @Override - @Deprecated - public int getInt(String key, int defaultValue) throws TableKeyNotDefinedException { - try { - return (int)getNumber(key); - } catch (NoSuchElementException ex) { - return defaultValue; - } - } - /** * {@inheritDoc} * @deprecated Use {@link #putNumber(String, double)} instead. @@ -1083,16 +935,6 @@ public boolean putDouble(String key, double value) { return putNumber(key, value); } - /** - * {@inheritDoc} - * @deprecated Use {@link #getNumber(String, double)} instead. - */ - @Override - @Deprecated - public double getDouble(String key) throws TableKeyNotDefinedException { - return getNumber(key); - } - /** * {@inheritDoc} * @deprecated Use {@link #getNumber(String, double)} instead. diff --git a/src/main/java/edu/wpi/first/wpilibj/networktables/NetworkTableKeyNotDefined.java b/src/main/java/edu/wpi/first/wpilibj/networktables/NetworkTableKeyNotDefined.java deleted file mode 100644 index 144094c..0000000 --- a/src/main/java/edu/wpi/first/wpilibj/networktables/NetworkTableKeyNotDefined.java +++ /dev/null @@ -1,23 +0,0 @@ -package edu.wpi.first.wpilibj.networktables; - -import edu.wpi.first.wpilibj.tables.TableKeyNotDefinedException; - -/** - * An exception throw when the lookup a a key-value fails in a {@link NetworkTable} - * - * @deprecated to provide backwards compatability for new api - * - * @author Mitchell - * - */ -@Deprecated -public class NetworkTableKeyNotDefined extends TableKeyNotDefinedException { - - /** - * @param key the key that was not defined in the table - */ - public NetworkTableKeyNotDefined(String key) { - super(key); - } - -} diff --git a/src/main/java/edu/wpi/first/wpilibj/networktables/NetworkTablesJNI.java b/src/main/java/edu/wpi/first/wpilibj/networktables/NetworkTablesJNI.java index 6689b0f..c348541 100644 --- a/src/main/java/edu/wpi/first/wpilibj/networktables/NetworkTablesJNI.java +++ b/src/main/java/edu/wpi/first/wpilibj/networktables/NetworkTablesJNI.java @@ -1,7 +1,5 @@ package edu.wpi.first.wpilibj.networktables; -import edu.wpi.first.wpilibj.tables.*; - import java.io.File; import java.io.InputStream; import java.io.OutputStream; @@ -83,15 +81,6 @@ else if (System.getProperty("os.name").startsWith("Mac")) public static native void forcePutDoubleArray(String key, double[] value); public static native void forcePutStringArray(String key, String[] value); - public static native Object getValue(String key) throws TableKeyNotDefinedException; - public static native boolean getBoolean(String key) throws TableKeyNotDefinedException; - public static native double getDouble(String key) throws TableKeyNotDefinedException; - public static native String getString(String key) throws TableKeyNotDefinedException; - public static native byte[] getRaw(String key) throws TableKeyNotDefinedException; - public static native boolean[] getBooleanArray(String key) throws TableKeyNotDefinedException; - public static native double[] getDoubleArray(String key) throws TableKeyNotDefinedException; - public static native String[] getStringArray(String key) throws TableKeyNotDefinedException; - public static native Object getValue(String key, Object defaultValue); public static native boolean getBoolean(String key, boolean defaultValue); public static native double getDouble(String key, double defaultValue); @@ -135,7 +124,6 @@ public interface ConnectionListenerFunction { // public static native void createRpc(String key, byte[] def, IRpc rpc); // public static native void createRpc(String key, ByteBuffer def, int def_len, IRpc rpc); - public static native byte[] getRpc(String key) throws TableKeyNotDefinedException; public static native byte[] getRpc(String key, byte[] defaultValue); public static native int callRpc(String key, byte[] params); public static native int callRpc(String key, ByteBuffer params, int params_len); diff --git a/src/main/java/edu/wpi/first/wpilibj/tables/ITable.java b/src/main/java/edu/wpi/first/wpilibj/tables/ITable.java index 50418cf..eeb31e7 100644 --- a/src/main/java/edu/wpi/first/wpilibj/tables/ITable.java +++ b/src/main/java/edu/wpi/first/wpilibj/tables/ITable.java @@ -1,7 +1,6 @@ package edu.wpi.first.wpilibj.tables; import java.nio.ByteBuffer; -import java.util.NoSuchElementException; import java.util.Set; @@ -109,22 +108,6 @@ public interface ITable { */ public void delete(String key); - /** - * Gets the value associated with a key as an object. If the key does not - * exist, it will return the default value - * NOTE: If the value is a double, it will return a Double object, - * not a primitive. To get the primitive, use - * {@link #getDouble(String, double)}. - * @param key the key of the value to look up - * @return the value associated with the given key - * @throws TableKeyNotDefinedException if there is no value associated with - * the given key - * @deprecated This exception-raising method has been replaced by the - * default-taking method {@link #getValue(String, Object)}. - */ - @Deprecated - public Object getValue(String key) throws TableKeyNotDefinedException; - /** * Gets the value associated with a key as an object. * NOTE: If the value is a double, it will return a Double object, @@ -147,17 +130,6 @@ public interface ITable { public boolean putValue(String key, Object value) throws IllegalArgumentException; - /** - * Retrieve an array data type from the table. - * @param key the key to be assigned to - * @param externalValue the array data type to retreive into - * @throws TableKeyNotDefinedException if there is no value associated with - * the given key - * @deprecated Use get*Array functions instead. - */ - @Deprecated - public void retrieveValue(String key, Object externalValue) throws TableKeyNotDefinedException; - /** * Put a number in the table * @param key the key to be assigned to @@ -174,17 +146,6 @@ public boolean putValue(String key, Object value) */ public boolean setDefaultNumber(String key, double defaultValue); - /** - * Returns the number the key maps to. - * @param key the key to look up - * @return the value associated with the given key - * @throws TableKeyNotDefinedException if there is no value associated with - * the given key - * @deprecated This exception-raising method has been replaced by the - * default-taking method {@link #getNumber(String, double)}. - */ - @Deprecated - public double getNumber(String key) throws TableKeyNotDefinedException; /** * Returns the number the key maps to. If the key does not exist or is of * different type, it will return the default value. @@ -211,17 +172,6 @@ public boolean putValue(String key, Object value) */ public boolean setDefaultString(String key, String defaultValue); - /** - * Returns the string the key maps to. - * @param key the key to look up - * @return the value associated with the given key - * @throws TableKeyNotDefinedException if there is no value associated with - * the given key - * @deprecated This exception-raising method has been replaced by the - * default-taking method {@link #getString(String, String)}. - */ - @Deprecated - public String getString(String key) throws TableKeyNotDefinedException; /** * Returns the string the key maps to. If the key does not exist or is of * different type, it will return the default value. @@ -248,17 +198,6 @@ public boolean putValue(String key, Object value) */ public boolean setDefaultBoolean(String key, boolean defaultValue); - /** - * Returns the boolean the key maps to. - * @param key the key to look up - * @return the value associated with the given key - * @throws TableKeyNotDefinedException if there is no value associated with - * the given key - * @deprecated This exception-raising method has been replaced by the - * default-taking method {@link #getBoolean(String, boolean)}. - */ - @Deprecated - public boolean getBoolean(String key) throws TableKeyNotDefinedException; /** * Returns the boolean the key maps to. If the key does not exist or is of * different type, it will return the default value. @@ -301,17 +240,6 @@ public boolean putValue(String key, Object value) */ public boolean setDefaultBooleanArray(String key, Boolean[] defaultValue); - /** - * Returns the boolean array the key maps to. - * @param key the key to look up - * @return the value associated with the given key - * @throws TableKeyNotDefinedException if there is no value associated with - * the given key - * @deprecated This exception-raising method has been replaced by the - * default-taking method {@link #getBooleanArray(String, boolean[])}. - */ - @Deprecated - public boolean[] getBooleanArray(String key) throws TableKeyNotDefinedException; /** * Returns the boolean array the key maps to. If the key does not exist or is * of different type, it will return the default value. @@ -363,17 +291,6 @@ public boolean putValue(String key, Object value) */ public boolean setDefaultNumberArray(String key, Double[] defaultValue); - /** - * Returns the number array the key maps to. - * @param key the key to look up - * @return the value associated with the given key - * @throws TableKeyNotDefinedException if there is no value associated with - * the given key - * @deprecated This exception-raising method has been replaced by the - * default-taking method {@link #getNumberArray(String, double[])}. - */ - @Deprecated - public double[] getNumberArray(String key) throws TableKeyNotDefinedException; /** * Returns the number array the key maps to. If the key does not exist or is * of different type, it will return the default value. @@ -409,17 +326,6 @@ public boolean putValue(String key, Object value) */ public boolean setDefaultStringArray(String key, String[] defaultValue); - /** - * Returns the string array the key maps to. - * @param key the key to look up - * @return the value associated with the given key - * @throws TableKeyNotDefinedException if there is no value associated with - * the given key - * @deprecated This exception-raising method has been replaced by the - * default-taking method {@link #getStringArray(String, String[])}. - */ - @Deprecated - public String[] getStringArray(String key) throws TableKeyNotDefinedException; /** * Returns the string array the key maps to. If the key does not exist or is * of different type, it will return the default value. @@ -454,17 +360,7 @@ public boolean putValue(String key, Object value) * @return False if the table key already exists with a different type */ public boolean putRaw(String key, ByteBuffer value, int len); - /** - * Returns the raw value (byte array) the key maps to. - * @param key the key to look up - * @return the value associated with the given key - * @throws TableKeyNotDefinedException if there is no value associated with - * the given key - * @deprecated This exception-raising method has been replaced by the - * default-taking method {@link #getRaw(String, byte[])}. - */ - @Deprecated - public byte[] getRaw(String key) throws TableKeyNotDefinedException; + /** * Returns the raw value (byte array) the key maps to. If the key does not * exist or is of different type, it will return the default value. @@ -543,48 +439,6 @@ public void addSubTableListener(final ITableListener listener, * Deprecated Methods */ - /** - * Maps the specified key to the specified value in this table. - * The key can not be null. - * The value can be retrieved by calling the get method with a key that is - * equal to the original key. - * @param key the key - * @param value the value - * @return False if the table key already exists with a different type - * @throws IllegalArgumentException if key is null - * @deprecated Use {@link #putNumber(String, double)} instead. - */ - @Deprecated - public boolean putInt(String key, int value); - - /** - * Returns the value at the specified key. - * @param key the key - * @return the value - * @throws TableKeyNotDefinedException if there is no value mapped to by the - * key - * @throws IllegalArgumentException if the value mapped to by the key is not - * an int - * @throws IllegalArgumentException if the key is null - * @deprecated Use {@link #getNumber(String, double)} instead. - */ - @Deprecated - public int getInt(String key) throws TableKeyNotDefinedException; - - /** - * Returns the value at the specified key. - * @param key the key - * @param defaultValue the value returned if the key is undefined - * @return the value - * @throws IllegalArgumentException if the value mapped to by the key is not - * an int - * @throws IllegalArgumentException if the key is null - * @deprecated Use {@link #getNumber(String, double)} instead. - */ - @Deprecated - public int getInt(String key, int defaultValue) - throws TableKeyNotDefinedException; - /** * Maps the specified key to the specified value in this table. * The key can not be null. @@ -599,20 +453,6 @@ public int getInt(String key, int defaultValue) @Deprecated public boolean putDouble(String key, double value); - /** - * Returns the value at the specified key. - * @param key the key - * @return the value - * @throws TableKeyNotDefinedException if there is no - * value mapped to by the key - * @throws IllegalArgumentException if the value mapped to by the key is not a - * double - * @throws IllegalArgumentException if the key is null - * @deprecated Use {@link #getNumber(String, double)} instead. - */ - @Deprecated - public double getDouble(String key) throws TableKeyNotDefinedException; - /** * Returns the value at the specified key. * @param key the key diff --git a/src/main/java/edu/wpi/first/wpilibj/tables/TableKeyNotDefinedException.java b/src/main/java/edu/wpi/first/wpilibj/tables/TableKeyNotDefinedException.java deleted file mode 100644 index 4ca3a54..0000000 --- a/src/main/java/edu/wpi/first/wpilibj/tables/TableKeyNotDefinedException.java +++ /dev/null @@ -1,20 +0,0 @@ -package edu.wpi.first.wpilibj.tables; - -import java.util.NoSuchElementException; - -/** - * An exception throw when the lookup a a key-value fails in a {@link ITable} - * - * @author Mitchell - * - */ -public class TableKeyNotDefinedException extends NoSuchElementException { - - /** - * @param key the key that was not defined in the table - */ - public TableKeyNotDefinedException(String key) { - super("Unknown Table Key: "+key); - } - -} diff --git a/src/main/native/cpp/jni/NetworkTablesJNI.cpp b/src/main/native/cpp/jni/NetworkTablesJNI.cpp index 3ec7f65..ec5bf1f 100644 --- a/src/main/native/cpp/jni/NetworkTablesJNI.cpp +++ b/src/main/native/cpp/jni/NetworkTablesJNI.cpp @@ -28,7 +28,6 @@ static JClass booleanCls; static JClass doubleCls; static JClass connectionInfoCls; static JClass entryInfoCls; -static JException keyNotDefinedEx; static JException persistentEx; static JException illegalArgEx; static JException nullPointerEx; @@ -78,10 +77,6 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { entryInfoCls = JClass(env, "edu/wpi/first/wpilibj/networktables/EntryInfo"); if (!entryInfoCls) return JNI_ERR; - keyNotDefinedEx = JException( - env, "edu/wpi/first/wpilibj/networktables/NetworkTableKeyNotDefined"); - if (!keyNotDefinedEx) return JNI_ERR; - persistentEx = JException( env, "edu/wpi/first/wpilibj/networktables/PersistentException"); if (!persistentEx) return JNI_ERR; @@ -108,7 +103,6 @@ JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved) { doubleCls.free(env); connectionInfoCls.free(env); entryInfoCls.free(env); - keyNotDefinedEx.free(env); persistentEx.free(env); illegalArgEx.free(env); nullPointerEx.free(env); @@ -638,172 +632,12 @@ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_networktables_NetworkTablesJNI nt::SetEntryTypeValue(JStringRef{env, key}, v); } -/* - * Class: edu_wpi_first_wpilibj_networktables_NetworkTablesJNI - * Method: getValue - * Signature: (Ljava/lang/String;)Ljava/lang/Object; - */ -JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_networktables_NetworkTablesJNI_getValue__Ljava_lang_String_2 - (JNIEnv *env, jclass, jstring key) -{ - if (!key) { - nullPointerEx.Throw(env, "key cannot be null"); - return nullptr; - } - auto val = nt::GetEntryValue(JStringRef{env, key}); - if (!val) { - keyNotDefinedEx.Throw(env, key); - return nullptr; - } - return MakeJObject(env, *val); -} - -/* - * Class: edu_wpi_first_wpilibj_networktables_NetworkTablesJNI - * Method: getBoolean - * Signature: (Ljava/lang/String;)Z - */ -JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_networktables_NetworkTablesJNI_getBoolean__Ljava_lang_String_2 - (JNIEnv *env, jclass, jstring key) -{ - if (!key) { - nullPointerEx.Throw(env, "key cannot be null"); - return false; - } - auto val = nt::GetEntryValue(JStringRef{env, key}); - if (!val || !val->IsBoolean()) { - keyNotDefinedEx.Throw(env, key); - return false; - } - return val->GetBoolean(); -} - -/* - * Class: edu_wpi_first_wpilibj_networktables_NetworkTablesJNI - * Method: getDouble - * Signature: (Ljava/lang/String;)D - */ -JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_networktables_NetworkTablesJNI_getDouble__Ljava_lang_String_2 - (JNIEnv *env, jclass, jstring key) -{ - if (!key) { - nullPointerEx.Throw(env, "key cannot be null"); - return 0; - } - auto val = nt::GetEntryValue(JStringRef{env, key}); - if (!val || !val->IsDouble()) { - keyNotDefinedEx.Throw(env, key); - return 0; - } - return val->GetDouble(); -} - -/* - * Class: edu_wpi_first_wpilibj_networktables_NetworkTablesJNI - * Method: getString - * Signature: (Ljava/lang/String;)Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL Java_edu_wpi_first_wpilibj_networktables_NetworkTablesJNI_getString__Ljava_lang_String_2 - (JNIEnv *env, jclass, jstring key) -{ - if (!key) { - nullPointerEx.Throw(env, "key cannot be null"); - return nullptr; - } - auto val = nt::GetEntryValue(JStringRef{env, key}); - if (!val || !val->IsString()) { - keyNotDefinedEx.Throw(env, key); - return nullptr; - } - return MakeJString(env, val->GetString()); -} - -/* - * Class: edu_wpi_first_wpilibj_networktables_NetworkTablesJNI - * Method: getRaw - * Signature: (Ljava/lang/String;)[B - */ -JNIEXPORT jbyteArray JNICALL Java_edu_wpi_first_wpilibj_networktables_NetworkTablesJNI_getRaw__Ljava_lang_String_2 - (JNIEnv *env, jclass, jstring key) -{ - if (!key) { - nullPointerEx.Throw(env, "key cannot be null"); - return nullptr; - } - auto val = nt::GetEntryValue(JStringRef{env, key}); - if (!val || !val->IsRaw()) { - keyNotDefinedEx.Throw(env, key); - return nullptr; - } - return MakeJByteArray(env, val->GetRaw()); -} - -/* - * Class: edu_wpi_first_wpilibj_networktables_NetworkTablesJNI - * Method: getBooleanArray - * Signature: (Ljava/lang/String;)[Z - */ -JNIEXPORT jbooleanArray JNICALL Java_edu_wpi_first_wpilibj_networktables_NetworkTablesJNI_getBooleanArray__Ljava_lang_String_2 - (JNIEnv *env, jclass, jstring key) -{ - if (!key) { - nullPointerEx.Throw(env, "key cannot be null"); - return nullptr; - } - auto val = nt::GetEntryValue(JStringRef{env, key}); - if (!val || !val->IsBooleanArray()) { - keyNotDefinedEx.Throw(env, key); - return nullptr; - } - return MakeJBooleanArray(env, val->GetBooleanArray()); -} - -/* - * Class: edu_wpi_first_wpilibj_networktables_NetworkTablesJNI - * Method: getDoubleArray - * Signature: (Ljava/lang/String;)[D - */ -JNIEXPORT jdoubleArray JNICALL Java_edu_wpi_first_wpilibj_networktables_NetworkTablesJNI_getDoubleArray__Ljava_lang_String_2 - (JNIEnv *env, jclass, jstring key) -{ - if (!key) { - nullPointerEx.Throw(env, "key cannot be null"); - return nullptr; - } - auto val = nt::GetEntryValue(JStringRef{env, key}); - if (!val || !val->IsDoubleArray()) { - keyNotDefinedEx.Throw(env, key); - return nullptr; - } - return MakeJDoubleArray(env, val->GetDoubleArray()); -} - -/* - * Class: edu_wpi_first_wpilibj_networktables_NetworkTablesJNI - * Method: getStringArray - * Signature: (Ljava/lang/String;)[Ljava/lang/String; - */ -JNIEXPORT jobjectArray JNICALL Java_edu_wpi_first_wpilibj_networktables_NetworkTablesJNI_getStringArray__Ljava_lang_String_2 - (JNIEnv *env, jclass, jstring key) -{ - if (!key) { - nullPointerEx.Throw(env, "key cannot be null"); - return nullptr; - } - auto val = nt::GetEntryValue(JStringRef{env, key}); - if (!val || !val->IsStringArray()) { - keyNotDefinedEx.Throw(env, key); - return nullptr; - } - return MakeJStringArray(env, val->GetStringArray()); -} - /* * Class: edu_wpi_first_wpilibj_networktables_NetworkTablesJNI * Method: getValue * Signature: (Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; */ -JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_networktables_NetworkTablesJNI_getValue__Ljava_lang_String_2Ljava_lang_Object_2 +JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_networktables_NetworkTablesJNI_getValue (JNIEnv *env, jclass, jstring key, jobject defaultValue) { if (!key) { @@ -820,7 +654,7 @@ JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_networktables_NetworkTables * Method: getBoolean * Signature: (Ljava/lang/String;Z)Z */ -JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_networktables_NetworkTablesJNI_getBoolean__Ljava_lang_String_2Z +JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_networktables_NetworkTablesJNI_getBoolean (JNIEnv *env, jclass, jstring key, jboolean defaultValue) { if (!key) { @@ -837,7 +671,7 @@ JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_networktables_NetworkTable * Method: getDouble * Signature: (Ljava/lang/String;D)D */ -JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_networktables_NetworkTablesJNI_getDouble__Ljava_lang_String_2D +JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_networktables_NetworkTablesJNI_getDouble (JNIEnv *env, jclass, jstring key, jdouble defaultValue) { if (!key) { @@ -854,7 +688,7 @@ JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_networktables_NetworkTables * Method: getString * Signature: (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String; */ -JNIEXPORT jstring JNICALL Java_edu_wpi_first_wpilibj_networktables_NetworkTablesJNI_getString__Ljava_lang_String_2Ljava_lang_String_2 +JNIEXPORT jstring JNICALL Java_edu_wpi_first_wpilibj_networktables_NetworkTablesJNI_getString (JNIEnv *env, jclass, jstring key, jstring defaultValue) { if (!key) { @@ -871,7 +705,7 @@ JNIEXPORT jstring JNICALL Java_edu_wpi_first_wpilibj_networktables_NetworkTables * Method: getRaw * Signature: (Ljava/lang/String;[B)[B */ -JNIEXPORT jbyteArray JNICALL Java_edu_wpi_first_wpilibj_networktables_NetworkTablesJNI_getRaw__Ljava_lang_String_2_3B +JNIEXPORT jbyteArray JNICALL Java_edu_wpi_first_wpilibj_networktables_NetworkTablesJNI_getRaw (JNIEnv *env, jclass, jstring key, jbyteArray defaultValue) { if (!key) { @@ -888,7 +722,7 @@ JNIEXPORT jbyteArray JNICALL Java_edu_wpi_first_wpilibj_networktables_NetworkTab * Method: getBooleanArray * Signature: (Ljava/lang/String;[Z)[Z */ -JNIEXPORT jbooleanArray JNICALL Java_edu_wpi_first_wpilibj_networktables_NetworkTablesJNI_getBooleanArray__Ljava_lang_String_2_3Z +JNIEXPORT jbooleanArray JNICALL Java_edu_wpi_first_wpilibj_networktables_NetworkTablesJNI_getBooleanArray (JNIEnv *env, jclass, jstring key, jbooleanArray defaultValue) { if (!key) { @@ -905,7 +739,7 @@ JNIEXPORT jbooleanArray JNICALL Java_edu_wpi_first_wpilibj_networktables_Network * Method: getDoubleArray * Signature: (Ljava/lang/String;[D)[D */ -JNIEXPORT jdoubleArray JNICALL Java_edu_wpi_first_wpilibj_networktables_NetworkTablesJNI_getDoubleArray__Ljava_lang_String_2_3D +JNIEXPORT jdoubleArray JNICALL Java_edu_wpi_first_wpilibj_networktables_NetworkTablesJNI_getDoubleArray (JNIEnv *env, jclass, jstring key, jdoubleArray defaultValue) { if (!key) { @@ -922,7 +756,7 @@ JNIEXPORT jdoubleArray JNICALL Java_edu_wpi_first_wpilibj_networktables_NetworkT * Method: getStringArray * Signature: (Ljava/lang/String;[Ljava/lang/String;)[Ljava/lang/String; */ -JNIEXPORT jobjectArray JNICALL Java_edu_wpi_first_wpilibj_networktables_NetworkTablesJNI_getStringArray__Ljava_lang_String_2_3Ljava_lang_String_2 +JNIEXPORT jobjectArray JNICALL Java_edu_wpi_first_wpilibj_networktables_NetworkTablesJNI_getStringArray (JNIEnv *env, jclass, jstring key, jobjectArray defaultValue) { if (!key) { @@ -1294,32 +1128,12 @@ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_networktables_NetworkTablesJNI nt::RemoveConnectionListener(connListenerUid); } -/* - * Class: edu_wpi_first_wpilibj_networktables_NetworkTablesJNI - * Method: getRpc - * Signature: (Ljava/lang/String;)[B - */ -JNIEXPORT jbyteArray JNICALL Java_edu_wpi_first_wpilibj_networktables_NetworkTablesJNI_getRpc__Ljava_lang_String_2 - (JNIEnv *env, jclass, jstring key) -{ - if (!key) { - nullPointerEx.Throw(env, "key cannot be null"); - return nullptr; - } - auto val = nt::GetEntryValue(JStringRef{env, key}); - if (!val || !val->IsRpc()) { - keyNotDefinedEx.Throw(env, key); - return nullptr; - } - return MakeJByteArray(env, val->GetRpc()); -} - /* * Class: edu_wpi_first_wpilibj_networktables_NetworkTablesJNI * Method: getRpc * Signature: (Ljava/lang/String;[B)[B */ -JNIEXPORT jbyteArray JNICALL Java_edu_wpi_first_wpilibj_networktables_NetworkTablesJNI_getRpc__Ljava_lang_String_2_3B +JNIEXPORT jbyteArray JNICALL Java_edu_wpi_first_wpilibj_networktables_NetworkTablesJNI_getRpc (JNIEnv *env, jclass, jstring key, jbyteArray defaultValue) { if (!key) { diff --git a/src/main/native/cpp/networktables/NetworkTable.cpp b/src/main/native/cpp/networktables/NetworkTable.cpp index 4437de0..912143a 100644 --- a/src/main/native/cpp/networktables/NetworkTable.cpp +++ b/src/main/native/cpp/networktables/NetworkTable.cpp @@ -6,7 +6,6 @@ #include "llvm/SmallString.h" #include "llvm/StringMap.h" #include "tables/ITableListener.h" -#include "tables/TableKeyNotDefinedException.h" #include "ntcore.h" using llvm::StringRef; @@ -365,16 +364,6 @@ bool NetworkTable::SetDefaultNumber(StringRef key, double defaultValue) { return nt::SetDefaultEntryValue(path, nt::Value::MakeDouble(defaultValue)); } -double NetworkTable::GetNumber(StringRef key) const { - llvm::SmallString<128> path(m_path); - path += PATH_SEPARATOR_CHAR; - path += key; - auto value = nt::GetEntryValue(path); - if (!value || value->type() != NT_DOUBLE) - throw TableKeyNotDefinedException(path); - return value->GetDouble(); -} - double NetworkTable::GetNumber(StringRef key, double defaultValue) const { llvm::SmallString<128> path(m_path); path += PATH_SEPARATOR_CHAR; @@ -398,16 +387,6 @@ bool NetworkTable::SetDefaultString(StringRef key, StringRef defaultValue) { return nt::SetDefaultEntryValue(path, nt::Value::MakeString(defaultValue)); } -std::string NetworkTable::GetString(StringRef key) const { - llvm::SmallString<128> path(m_path); - path += PATH_SEPARATOR_CHAR; - path += key; - auto value = nt::GetEntryValue(path); - if (!value || value->type() != NT_STRING) - throw TableKeyNotDefinedException(path); - return value->GetString(); -} - std::string NetworkTable::GetString(StringRef key, StringRef defaultValue) const { llvm::SmallString<128> path(m_path); @@ -432,16 +411,6 @@ bool NetworkTable::SetDefaultBoolean(StringRef key, bool defaultValue) { return nt::SetDefaultEntryValue(path, nt::Value::MakeBoolean(defaultValue)); } -bool NetworkTable::GetBoolean(StringRef key) const { - llvm::SmallString<128> path(m_path); - path += PATH_SEPARATOR_CHAR; - path += key; - auto value = nt::GetEntryValue(path); - if (!value || value->type() != NT_BOOLEAN) - throw TableKeyNotDefinedException(path); - return value->GetBoolean(); -} - bool NetworkTable::GetBoolean(StringRef key, bool defaultValue) const { llvm::SmallString<128> path(m_path); path += PATH_SEPARATOR_CHAR; diff --git a/src/main/native/cpp/tables/TableKeyNotDefinedException.cpp b/src/main/native/cpp/tables/TableKeyNotDefinedException.cpp deleted file mode 100644 index 30bedd0..0000000 --- a/src/main/native/cpp/tables/TableKeyNotDefinedException.cpp +++ /dev/null @@ -1,19 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2015. 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. */ -/*----------------------------------------------------------------------------*/ - -#include "tables/TableKeyNotDefinedException.h" - -TableKeyNotDefinedException::TableKeyNotDefinedException(llvm::StringRef key) - : msg("Unknown Table Key: ") { - msg += key; -} - -const char* TableKeyNotDefinedException::what() const NT_NOEXCEPT { - return msg.c_str(); -} - -TableKeyNotDefinedException::~TableKeyNotDefinedException() NT_NOEXCEPT {} diff --git a/src/main/native/include/networktables/NetworkTable.h b/src/main/native/include/networktables/NetworkTable.h index 0b9ae61..0399669 100644 --- a/src/main/native/include/networktables/NetworkTable.h +++ b/src/main/native/include/networktables/NetworkTable.h @@ -286,21 +286,6 @@ class NetworkTable : public ITable { virtual bool SetDefaultNumber(llvm::StringRef key, double defaultValue) override; - /** - * Gets the number associated with the given name. - * - * @param key the key to look up - * @return the value associated with the given key - * @throws TableKeyNotDefinedException if there is no value associated with - * the given key - * @deprecated This exception-raising method has been replaced by the - * default-taking method. - */ - WPI_DEPRECATED( - "Raises an exception if key not found; " - "use GetNumber(StringRef key, double defaultValue) instead") - virtual double GetNumber(llvm::StringRef key) const override; - /** * Gets the number associated with the given name. * @@ -330,21 +315,6 @@ class NetworkTable : public ITable { virtual bool SetDefaultString(llvm::StringRef key, llvm::StringRef defaultValue) override; - /** - * Gets the string associated with the given name. - * - * @param key the key to look up - * @return the value associated with the given key - * @throws TableKeyNotDefinedException if there is no value associated with - * the given key - * @deprecated This exception-raising method has been replaced by the - * default-taking method. - */ - WPI_DEPRECATED( - "Raises an exception if key not found; " - "use GetString(StringRef key, StringRef defaultValue) instead") - virtual std::string GetString(llvm::StringRef key) const override; - /** * Gets the string associated with the given name. If the key does not * exist or is of different type, it will return the default value. @@ -375,21 +345,6 @@ class NetworkTable : public ITable { virtual bool SetDefaultBoolean(llvm::StringRef key, bool defaultValue) override; - /** - * Gets the boolean associated with the given name. - * - * @param key the key to look up - * @return the value associated with the given key - * @throws TableKeyNotDefinedException if there is no value associated with - * the given key - * @deprecated This exception-raising method has been replaced by the - * default-taking method. - */ - WPI_DEPRECATED( - "Raises an exception if key not found; " - "use GetBoolean(StringRef key, bool defaultValue) instead") - virtual bool GetBoolean(llvm::StringRef key) const override; - /** * Gets the boolean associated with the given name. If the key does not * exist or is of different type, it will return the default value. diff --git a/src/main/native/include/tables/ITable.h b/src/main/native/include/tables/ITable.h index 6cc0713..8b3fe43 100644 --- a/src/main/native/include/tables/ITable.h +++ b/src/main/native/include/tables/ITable.h @@ -159,21 +159,6 @@ class ITable { */ virtual bool SetDefaultNumber(llvm::StringRef key, double defaultValue) = 0; - /** - * Gets the number associated with the given name. - * - * @param key the key to look up - * @return the value associated with the given key - * @throws TableKeyNotDefinedException if there is no value associated with - * the given key - * @deprecated This exception-raising method has been replaced by the - * default-taking method. - */ - WPI_DEPRECATED( - "Raises an exception if key not found; " - "use GetNumber(StringRef key, double defaultValue) instead") - virtual double GetNumber(llvm::StringRef key) const = 0; - /** * Gets the number associated with the given name. * @@ -202,21 +187,6 @@ class ITable { virtual bool SetDefaultString(llvm::StringRef key, llvm::StringRef defaultValue) = 0; - /** - * Gets the string associated with the given name. - * - * @param key the key to look up - * @return the value associated with the given key - * @throws TableKeyNotDefinedException if there is no value associated with - * the given key - * @deprecated This exception-raising method has been replaced by the - * default-taking method. - */ - WPI_DEPRECATED( - "Raises an exception if key not found; " - "use GetString(StringRef key, StringRef defaultValue) instead") - virtual std::string GetString(llvm::StringRef key) const = 0; - /** * Gets the string associated with the given name. If the key does not * exist or is of different type, it will return the default value. @@ -249,21 +219,6 @@ class ITable { */ virtual bool SetDefaultBoolean(llvm::StringRef key, bool defaultValue) = 0; - /** - * Gets the boolean associated with the given name. - * - * @param key the key to look up - * @return the value associated with the given key - * @throws TableKeyNotDefinedException if there is no value associated with - * the given key - * @deprecated This exception-raising method has been replaced by the - * default-taking method. - */ - WPI_DEPRECATED( - "Raises an exception if key not found; " - "use GetBoolean(StringRef key, bool defaultValue) instead") - virtual bool GetBoolean(llvm::StringRef key) const = 0; - /** * Gets the boolean associated with the given name. If the key does not * exist or is of different type, it will return the default value. diff --git a/src/main/native/include/tables/TableKeyNotDefinedException.h b/src/main/native/include/tables/TableKeyNotDefinedException.h deleted file mode 100644 index d65bcf2..0000000 --- a/src/main/native/include/tables/TableKeyNotDefinedException.h +++ /dev/null @@ -1,36 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2015. 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. */ -/*----------------------------------------------------------------------------*/ - -#ifndef TABLEKEYNOTDEFINEDEXCEPTION_H_ -#define TABLEKEYNOTDEFINEDEXCEPTION_H_ - -#include -#include "llvm/StringRef.h" - -#if defined(_MSC_VER) -#define NT_NOEXCEPT throw() -#else -#define NT_NOEXCEPT noexcept -#endif - -/** - * An exception thrown when the lookup a a key-value fails in a {@link ITable} - */ -class TableKeyNotDefinedException : public std::exception { - public: - /** - * @param key the key that was not defined in the table - */ - TableKeyNotDefinedException(llvm::StringRef key); - ~TableKeyNotDefinedException() NT_NOEXCEPT; - const char* what() const NT_NOEXCEPT override; - - private: - std::string msg; -}; - -#endif // TABLEKEYNOTDEFINEDEXCEPTION_H_