001/*----------------------------------------------------------------------------*/ 002/* Copyright (c) FIRST 2017-2018. All Rights Reserved. */ 003/* Open Source Software - may be modified and shared by FRC teams. The code */ 004/* must be accompanied by the FIRST BSD license file in the root directory of */ 005/* the project. */ 006/*----------------------------------------------------------------------------*/ 007 008package edu.wpi.first.wpilibj.tables; 009 010import java.nio.ByteBuffer; 011import java.util.Set; 012 013 014/** 015 * A table whose values can be read and written to 016 * @deprecated Use {@link edu.wpi.first.networktables.NetworkTable}. 017 */ 018@Deprecated 019public interface ITable { 020 021 /** 022 * Checks the table and tells if it contains the specified key 023 * 024 * @param key the key to search for 025 * @return true if the table as a value assigned to the given key 026 */ 027 public boolean containsKey(String key); 028 029 /** 030 * @param key the key to search for 031 * @return true if there is a subtable with the key which contains at least 032 * one key/subtable of its own 033 */ 034 public boolean containsSubTable(String key); 035 036 /** 037 * Returns the table at the specified key. If there is no table at the 038 * specified key, it will create a new table 039 * 040 * @param key the name of the table relative to this one 041 * @return a sub table relative to this one 042 */ 043 public ITable getSubTable(String key); 044 045 /** 046 * Gets all keys in the table (not including sub-tables). 047 * @param types bitmask of types; 0 is treated as a "don't care". 048 * @return keys currently in the table 049 */ 050 public Set<String> getKeys(int types); 051 052 /** 053 * Gets all keys in the table (not including sub-tables). 054 * @return keys currently in the table 055 */ 056 public Set<String> getKeys(); 057 058 /** 059 * Gets the names of all subtables in the table. 060 * @return subtables currently in the table 061 */ 062 public Set<String> getSubTables(); 063 064 /** 065 * Makes a key's value persistent through program restarts. 066 * The key cannot be null. 067 * 068 * @param key the key name 069 */ 070 public void setPersistent(String key); 071 072 /** 073 * Stop making a key's value persistent through program restarts. 074 * The key cannot be null. 075 * 076 * @param key the key name 077 */ 078 public void clearPersistent(String key); 079 080 /** 081 * Returns whether the value is persistent through program restarts. 082 * The key cannot be null. 083 * 084 * @param key the key name 085 * @return True if the value is persistent. 086 */ 087 public boolean isPersistent(String key); 088 089 /** 090 * Sets flags on the specified key in this table. The key can 091 * not be null. 092 * 093 * @param key the key name 094 * @param flags the flags to set (bitmask) 095 */ 096 public void setFlags(String key, int flags); 097 098 /** 099 * Clears flags on the specified key in this table. The key can 100 * not be null. 101 * 102 * @param key the key name 103 * @param flags the flags to clear (bitmask) 104 */ 105 public void clearFlags(String key, int flags); 106 107 /** 108 * Returns the flags for the specified key. 109 * 110 * @param key the key name 111 * @return the flags, or 0 if the key is not defined 112 */ 113 public int getFlags(String key); 114 115 /** 116 * Deletes the specified key in this table. The key can 117 * not be null. 118 * 119 * @param key the key name 120 */ 121 public void delete(String key); 122 123 /** 124 * Gets the value associated with a key as an object. 125 * NOTE: If the value is a double, it will return a Double object, 126 * not a primitive. To get the primitive, use 127 * {@link #getDouble(String, double)}. 128 * @param key the key of the value to look up 129 * @param defaultValue the default value if the key is null 130 * @return the value associated with the given key 131 */ 132 public Object getValue(String key, Object defaultValue); 133 134 /** 135 * Put a value in the table 136 * @param key the key to be assigned to 137 * @param value the value that will be assigned 138 * @return False if the table key already exists with a different type 139 * @throws IllegalArgumentException when the value is not supported by the 140 * table 141 */ 142 public boolean putValue(String key, Object value) 143 throws IllegalArgumentException; 144 145 /** 146 * Put a number in the table 147 * @param key the key to be assigned to 148 * @param value the value that will be assigned 149 * @return False if the table key already exists with a different type 150 */ 151 public boolean putNumber(String key, double value); 152 153 /** 154 * Gets the current value in the table, setting it if it does not exist. 155 * @param key the key 156 * @param defaultValue the default value to set if key doens't exist. 157 * @return False if the table key exists with a different type 158 */ 159 public boolean setDefaultNumber(String key, double defaultValue); 160 161 /** 162 * Returns the number the key maps to. If the key does not exist or is of 163 * different type, it will return the default value. 164 * @param key the key to look up 165 * @param defaultValue the value to be returned if no value is found 166 * @return the value associated with the given key or the given default value 167 * if there is no value associated with the key 168 */ 169 public double getNumber(String key, double defaultValue); 170 171 /** 172 * Put a string in the table 173 * @param key the key to be assigned to 174 * @param value the value that will be assigned 175 * @return False if the table key already exists with a different type 176 */ 177 public boolean putString(String key, String value); 178 179 /** 180 * Gets the current value in the table, setting it if it does not exist. 181 * @param key the key 182 * @param defaultValue the default value to set if key doens't exist. 183 * @return False if the table key exists with a different type 184 */ 185 public boolean setDefaultString(String key, String defaultValue); 186 187 /** 188 * Returns the string the key maps to. If the key does not exist or is of 189 * different type, it will return the default value. 190 * @param key the key to look up 191 * @param defaultValue the value to be returned if no value is found 192 * @return the value associated with the given key or the given default value 193 * if there is no value associated with the key 194 */ 195 public String getString(String key, String defaultValue); 196 197 /** 198 * Put a boolean in the table 199 * @param key the key to be assigned to 200 * @param value the value that will be assigned 201 * @return False if the table key already exists with a different type 202 */ 203 public boolean putBoolean(String key, boolean value); 204 205 /** 206 * Gets the current value in the table, setting it if it does not exist. 207 * @param key the key 208 * @param defaultValue the default value to set if key doens't exist. 209 * @return False if the table key exists with a different type 210 */ 211 public boolean setDefaultBoolean(String key, boolean defaultValue); 212 213 /** 214 * Returns the boolean the key maps to. If the key does not exist or is of 215 * different type, it will return the default value. 216 * @param key the key to look up 217 * @param defaultValue the value to be returned if no value is found 218 * @return the value associated with the given key or the given default value 219 * if there is no value associated with the key 220 */ 221 public boolean getBoolean(String key, boolean defaultValue); 222 223 /** 224 * Put a boolean array in the table 225 * @param key the key to be assigned to 226 * @param value the value that will be assigned 227 * @return False if the table key already exists with a different type 228 */ 229 public boolean putBooleanArray(String key, boolean[] value); 230 231 /** 232 * Gets the current value in the table, setting it if it does not exist. 233 * @param key the key 234 * @param defaultValue the default value to set if key doens't exist. 235 * @return False if the table key exists with a different type 236 */ 237 public boolean setDefaultBooleanArray(String key, boolean[] defaultValue); 238 239 /** 240 * Put a boolean array in the table 241 * @param key the key to be assigned to 242 * @param value the value that will be assigned 243 * @return False if the table key already exists with a different type 244 */ 245 public boolean putBooleanArray(String key, Boolean[] value); 246 247 /** 248 * Gets the current value in the table, setting it if it does not exist. 249 * @param key the key 250 * @param defaultValue the default value to set if key doens't exist. 251 * @return False if the table key exists with a different type 252 */ 253 public boolean setDefaultBooleanArray(String key, Boolean[] defaultValue); 254 255 /** 256 * Returns the boolean array the key maps to. If the key does not exist or is 257 * of different type, it will return the default value. 258 * @param key the key to look up 259 * @param defaultValue the value to be returned if no value is found 260 * @return the value associated with the given key or the given default value 261 * if there is no value associated with the key 262 */ 263 public boolean[] getBooleanArray(String key, boolean[] defaultValue); 264 /** 265 * Returns the boolean array the key maps to. If the key does not exist or is 266 * of different type, it will return the default value. 267 * @param key the key to look up 268 * @param defaultValue the value to be returned if no value is found 269 * @return the value associated with the given key or the given default value 270 * if there is no value associated with the key 271 */ 272 public Boolean[] getBooleanArray(String key, Boolean[] defaultValue); 273 274 /** 275 * Put a number array in the table 276 * @param key the key to be assigned to 277 * @param value the value that will be assigned 278 * @return False if the table key already exists with a different type 279 */ 280 public boolean putNumberArray(String key, double[] value); 281 282 /** 283 * Gets the current value in the table, setting it if it does not exist. 284 * @param key the key 285 * @param defaultValue the default value to set if key doens't exist. 286 * @return False if the table key exists with a different type 287 */ 288 public boolean setDefaultNumberArray(String key, double[] defaultValue); 289 290 /** 291 * Put a number array in the table 292 * @param key the key to be assigned to 293 * @param value the value that will be assigned 294 * @return False if the table key already exists with a different type 295 */ 296 public boolean putNumberArray(String key, Double[] value); 297 298 /** 299 * Gets the current value in the table, setting it if it does not exist. 300 * @param key the key 301 * @param defaultValue the default value to set if key doens't exist. 302 * @return False if the table key exists with a different type 303 */ 304 public boolean setDefaultNumberArray(String key, Double[] defaultValue); 305 306 /** 307 * Returns the number array the key maps to. If the key does not exist or is 308 * of different type, it will return the default value. 309 * @param key the key to look up 310 * @param defaultValue the value to be returned if no value is found 311 * @return the value associated with the given key or the given default value 312 * if there is no value associated with the key 313 */ 314 public double[] getNumberArray(String key, double[] defaultValue); 315 /** 316 * Returns the number array the key maps to. If the key does not exist or is 317 * of different type, it will return the default value. 318 * @param key the key to look up 319 * @param defaultValue the value to be returned if no value is found 320 * @return the value associated with the given key or the given default value 321 * if there is no value associated with the key 322 */ 323 public Double[] getNumberArray(String key, Double[] defaultValue); 324 325 /** 326 * Put a string array in the table 327 * @param key the key to be assigned to 328 * @param value the value that will be assigned 329 * @return False if the table key already exists with a different type 330 */ 331 public boolean putStringArray(String key, String[] value); 332 333 /** 334 * Gets the current value in the table, setting it if it does not exist. 335 * @param key the key 336 * @param defaultValue the default value to set if key doens't exist. 337 * @return False if the table key exists with a different type 338 */ 339 public boolean setDefaultStringArray(String key, String[] defaultValue); 340 341 /** 342 * Returns the string array the key maps to. If the key does not exist or is 343 * of different type, it will return the default value. 344 * @param key the key to look up 345 * @param defaultValue the value to be returned if no value is found 346 * @return the value associated with the given key or the given default value 347 * if there is no value associated with the key 348 */ 349 public String[] getStringArray(String key, String[] defaultValue); 350 351 /** 352 * Put a raw value (byte array) in the table 353 * @param key the key to be assigned to 354 * @param value the value that will be assigned 355 * @return False if the table key already exists with a different type 356 */ 357 public boolean putRaw(String key, byte[] value); 358 359 /** 360 * Gets the current value in the table, setting it if it does not exist. 361 * @param key the key 362 * @param defaultValue the default value to set if key doens't exist. 363 * @return False if the table key exists with a different type 364 */ 365 public boolean setDefaultRaw(String key, byte[] defaultValue); 366 367 /** 368 * Put a raw value (bytes from a byte buffer) in the table 369 * @param key the key to be assigned to 370 * @param value the value that will be assigned 371 * @param len the length of the value 372 * @return False if the table key already exists with a different type 373 */ 374 public boolean putRaw(String key, ByteBuffer value, int len); 375 376 /** 377 * Returns the raw value (byte array) the key maps to. If the key does not 378 * exist or is of different type, it will return the default value. 379 * @param key the key to look up 380 * @param defaultValue the value to be returned if no value is found 381 * @return the value associated with the given key or the given default value 382 * if there is no value associated with the key 383 */ 384 public byte[] getRaw(String key, byte[] defaultValue); 385 386 /** Notifier flag values. */ 387 public static final int NOTIFY_IMMEDIATE = 0x01; 388 public static final int NOTIFY_LOCAL = 0x02; 389 public static final int NOTIFY_NEW = 0x04; 390 public static final int NOTIFY_DELETE = 0x08; 391 public static final int NOTIFY_UPDATE = 0x10; 392 public static final int NOTIFY_FLAGS = 0x20; 393 394 /** 395 * Add a listener for changes to the table 396 * @param listener the listener to add 397 */ 398 public void addTableListener(ITableListener listener); 399 /** 400 * Add a listener for changes to the table 401 * @param listener the listener to add 402 * @param immediateNotify if true then this listener will be notified of all 403 * current entries (marked as new) 404 */ 405 public void addTableListener(ITableListener listener, 406 boolean immediateNotify); 407 /** 408 * Add a listener for changes to the table 409 * @param listener the listener to add 410 * @param flags bitmask specifying desired notifications 411 */ 412 public void addTableListenerEx(ITableListener listener, int flags); 413 414 /** 415 * Add a listener for changes to a specific key the table 416 * @param key the key to listen for 417 * @param listener the listener to add 418 * @param immediateNotify if true then this listener will be notified of all 419 * current entries (marked as new) 420 */ 421 public void addTableListener(String key, ITableListener listener, 422 boolean immediateNotify); 423 /** 424 * Add a listener for changes to a specific key the table 425 * @param key the key to listen for 426 * @param listener the listener to add 427 * @param flags bitmask specifying desired notifications 428 */ 429 public void addTableListenerEx(String key, ITableListener listener, 430 int flags); 431 /** 432 * This will immediately notify the listener of all current sub tables 433 * @param listener the listener to notify 434 */ 435 public void addSubTableListener(final ITableListener listener); 436 /** 437 * This will immediately notify the listener of all current sub tables 438 * @param listener the listener to notify 439 * @param localNotify if true then this listener will be notified of all 440 * local changes in addition to all remote changes 441 */ 442 public void addSubTableListener(final ITableListener listener, 443 boolean localNotify); 444 /** 445 * Remove a listener from receiving table events 446 * @param listener the listener to be removed 447 */ 448 public void removeTableListener(ITableListener listener); 449 450 /* 451 * Deprecated Methods 452 */ 453 454 /** 455 * Maps the specified key to the specified value in this table. 456 * The key can not be null. 457 * The value can be retrieved by calling the get method with a key that is 458 * equal to the original key. 459 * @param key the key 460 * @param value the value 461 * @return False if the table key already exists with a different type 462 * @throws IllegalArgumentException if key is null 463 * @deprecated Use {@link #putNumber(String, double)} instead. 464 */ 465 @Deprecated 466 public boolean putDouble(String key, double value); 467 468 /** 469 * Returns the value at the specified key. 470 * @param key the key 471 * @param defaultValue the value returned if the key is undefined 472 * @return the value 473 * @throws IllegalArgumentException if the value mapped to by the key is not a 474 * double 475 * @throws IllegalArgumentException if the key is null 476 * @deprecated Use {@link #getNumber(String, double)} instead. 477 */ 478 @Deprecated 479 public double getDouble(String key, double defaultValue); 480 481 /** 482 * Gets the full path of this table. Does not include the trailing "/". 483 * @return The path to this table (e.g. "", "/foo"). 484 */ 485 public String getPath(); 486 487}