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
    • getTopic

      public Topic getTopic(String name)
      Get (generic) topic.
      Parameters:
      name - topic name
      Returns:
      Topic
    • getBooleanTopic

      Get boolean topic.
      Parameters:
      name - topic name
      Returns:
      BooleanTopic
    • getIntegerTopic

      Get long topic.
      Parameters:
      name - topic name
      Returns:
      IntegerTopic
    • getFloatTopic

      Get float topic.
      Parameters:
      name - topic name
      Returns:
      FloatTopic
    • getDoubleTopic

      Get double topic.
      Parameters:
      name - topic name
      Returns:
      DoubleTopic
    • getStringTopic

      Get String topic.
      Parameters:
      name - topic name
      Returns:
      StringTopic
    • getRawTopic

      public RawTopic getRawTopic(String name)
      Get raw topic.
      Parameters:
      name - topic name
      Returns:
      RawTopic
    • getBooleanArrayTopic

      Get boolean[] topic.
      Parameters:
      name - topic name
      Returns:
      BooleanArrayTopic
    • getIntegerArrayTopic

      Get long[] topic.
      Parameters:
      name - topic name
      Returns:
      IntegerArrayTopic
    • getFloatArrayTopic

      Get float[] topic.
      Parameters:
      name - topic name
      Returns:
      FloatArrayTopic
    • getDoubleArrayTopic

      Get double[] topic.
      Parameters:
      name - topic name
      Returns:
      DoubleArrayTopic
    • getStringArrayTopic

      Get String[] topic.
      Parameters:
      name - topic name
      Returns:
      StringArrayTopic
    • getProtobufTopic

      public <T, MessageType extends us.hebi.quickbuf.ProtoMessage<?>> ProtobufTopic<T> getProtobufTopic(String name, Protobuf<T,MessageType> proto)
      Get protobuf-encoded value topic.
      Type Parameters:
      T - value class (inferred from proto)
      MessageType - protobuf message type (inferred from proto)
      Parameters:
      name - topic name
      proto - protobuf serialization implementation
      Returns:
      ProtobufTopic
    • getStructTopic

      public <T> StructTopic<T> getStructTopic(String name, Struct<T> struct)
      Get struct-encoded value topic.
      Type Parameters:
      T - value class (inferred from struct)
      Parameters:
      name - topic name
      struct - struct serialization implementation
      Returns:
      StructTopic
    • getStructArrayTopic

      public <T> StructArrayTopic<T> getStructArrayTopic(String name, Struct<T> struct)
      Get struct-encoded value array topic.
      Type Parameters:
      T - value class (inferred from struct)
      Parameters:
      name - topic name
      struct - struct serialization implementation
      Returns:
      StructTopic
    • getEntry

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

      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
    • getTopicInfo

      public List<TopicInfo> getTopicInfo(int types)
      Gets topic information for all keys in the table (not including sub-tables).
      Parameters:
      types - bitmask of types (NetworkTableType values); 0 is treated as a "don't care".
      Returns:
      topic information for keys currently in the table
    • getTopicInfo

      Gets topic information for all keys in the table (not including sub-tables).
      Returns:
      topic information for keys currently in the table
    • getTopics

      public List<Topic> getTopics(int types)
      Gets all topics in the table (not including sub-tables).
      Parameters:
      types - bitmask of types (NetworkTableType values); 0 is treated as a "don't care".
      Returns:
      topic for keys currently in the table
    • getTopics

      public List<Topic> getTopics()
      Gets all topics in the table (not including sub-tables).
      Returns:
      topic for keys currently in the table
    • 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
    • putValue

      public boolean putValue(String key, NetworkTableValue value)
      Put a value in the table.
      Parameters:
      key - the key to be assigned to
      value - the value that will be assigned
      Returns:
      False if the table key already exists with a different type
    • setDefaultValue

      public boolean setDefaultValue(String key, NetworkTableValue defaultValue)
      Gets the current value in the table, setting it if it does not exist.
      Parameters:
      key - the key
      defaultValue - the default value to set if key doesn't exist.
      Returns:
      False if the table key exists with a different type
    • getValue

      Gets the value associated with a key as an object.
      Parameters:
      key - the key of the value to look up
      Returns:
      the value associated with the given key, or nullptr if the key does not exist
    • getPath

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

      Listen to topics only within this table.
      Parameters:
      eventKinds - set of event kinds to listen to
      listener - listener to add
      Returns:
      Listener handle
    • addListener

      Listen to a single key.
      Parameters:
      key - the key name
      eventKinds - set of event kinds to listen to
      listener - listener to add
      Returns:
      Listener handle
    • addSubTableListener

      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
      Returns:
      Listener handle
    • removeListener

      public void removeListener(int listener)
      Remove a listener.
      Parameters:
      listener - listener handle
    • equals

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

      public int hashCode()
      Overrides:
      hashCode in class Object