Class NetworkTable

java.lang.Object
edu.wpi.first.networktables.NetworkTable

public final class NetworkTable
extends Object
A network table that knows its subtable path.
  • Field Details

  • Method Details

    • basenameKey

      public static String basenameKey​(String key)
      Gets the "base name" of a key. For example, "/foo/bar" becomes "bar". If the key has a trailing slash, returns an empty string.
      Parameters:
      key - key
      Returns:
      base name
    • normalizeKey

      public static String normalizeKey​(String key, boolean withLeadingSlash)
      Normalizes an network table key to contain no consecutive slashes and optionally start with a leading slash. For example:
      
       normalizeKey("/foo/bar", true)  == "/foo/bar"
       normalizeKey("foo/bar", true)   == "/foo/bar"
       normalizeKey("/foo/bar", false) == "foo/bar"
       normalizeKey("foo//bar", false) == "foo/bar"
       
      Parameters:
      key - the key to normalize
      withLeadingSlash - whether or not the normalized key should begin with a leading slash
      Returns:
      normalized key
    • normalizeKey

      public static String normalizeKey​(String key)
      Normalizes a network table key to start with exactly one leading slash ("/") and contain no consecutive slashes. For example, "//foo/bar/" becomes "/foo/bar/" and "///a/b/c" becomes "/a/b/c".

      This is equivalent to normalizeKey(key, true)

      Parameters:
      key - the key to normalize
      Returns:
      normalized key
    • getHierarchy

      public static List<String> getHierarchy​(String key)
      Gets a list of the names of all the super tables of a given key. For example, the key "/foo/bar/baz" has a hierarchy of "/", "/foo", "/foo/bar", and "/foo/bar/baz".
      Parameters:
      key - the key
      Returns:
      List of super tables
    • getInstance

      Gets the instance for the table.
      Returns:
      Instance
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getEntry

      Gets the entry for a sub key.
      Parameters:
      key - the key name
      Returns:
      Network table entry.
    • addEntryListener

      public int addEntryListener​(TableEntryListener listener, int flags)
      Listen to keys only within this table.
      Parameters:
      listener - listener to add
      flags - EntryListenerFlags bitmask
      Returns:
      Listener handle
    • addEntryListener

      public int addEntryListener​(String key, TableEntryListener listener, int flags)
      Listen to a single key.
      Parameters:
      key - the key name
      listener - listener to add
      flags - EntryListenerFlags bitmask
      Returns:
      Listener handle
    • removeEntryListener

      public void removeEntryListener​(int listener)
      Remove an entry listener.
      Parameters:
      listener - listener handle
    • addSubTableListener

      public int addSubTableListener​(TableListener listener, boolean localNotify)
      Listen for sub-table creation. This calls the listener once for each newly created sub-table. It immediately calls the listener for any existing sub-tables.
      Parameters:
      listener - listener to add
      localNotify - notify local changes as well as remote
      Returns:
      Listener handle
    • removeTableListener

      public void removeTableListener​(int listener)
      Remove a sub-table listener.
      Parameters:
      listener - listener handle
    • getSubTable

      public NetworkTable getSubTable​(String key)
      Returns the table at the specified key. If there is no table at the specified key, it will create a new table
      Parameters:
      key - the name of the table relative to this one
      Returns:
      a sub table relative to this one
    • containsKey

      public boolean containsKey​(String key)
      Checks the table and tells if it contains the specified key.
      Parameters:
      key - the key to search for
      Returns:
      true if the table as a value assigned to the given key
    • containsSubTable

      public boolean containsSubTable​(String key)
      Checks the table and tells if it contains the specified sub table.
      Parameters:
      key - the key to search for
      Returns:
      true if there is a subtable with the key which contains at least one key/subtable of its own
    • getKeys

      public Set<String> getKeys​(int types)
      Gets all keys in the table (not including sub-tables).
      Parameters:
      types - bitmask of types; 0 is treated as a "don't care".
      Returns:
      keys currently in the table
    • getKeys

      public Set<String> getKeys()
      Gets all keys in the table (not including sub-tables).
      Returns:
      keys currently in the table
    • getSubTables

      public Set<String> getSubTables()
      Gets the names of all subtables in the table.
      Returns:
      subtables currently in the table
    • delete

      public void delete​(String key)
      Deletes the specified key in this table. The key can not be null.
      Parameters:
      key - the key name
    • getPath

      public String getPath()
      Get the path of the NetworkTable.
      Returns:
      The path of the NetworkTable.
    • saveEntries

      public void saveEntries​(String filename) throws PersistentException
      Save table values to a file. The file format used is identical to that used for SavePersistent.
      Parameters:
      filename - filename
      Throws:
      PersistentException - if error saving file
    • loadEntries

      public String[] loadEntries​(String filename) throws PersistentException
      Load table values from a file. The file format used is identical to that used for SavePersistent / LoadPersistent.
      Parameters:
      filename - filename
      Returns:
      List of warnings (errors result in an exception instead)
      Throws:
      PersistentException - if error saving file
    • equals

      public boolean equals​(Object other)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object