Package edu.wpi.first.networktables
Class NetworkTable
java.lang.Object
edu.wpi.first.networktables.NetworkTable
public final class NetworkTable extends Object
A network table that knows its subtable path.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
NetworkTable.SubTableListener
A listener that listens to new tables in aNetworkTable
.static interface
NetworkTable.TableEventListener
A listener that listens to events on topics in aNetworkTable
. -
Field Summary
Fields Modifier and Type Field Description static char
PATH_SEPARATOR
The path separator for sub-tables and keys. -
Method Summary
Modifier and Type Method Description int
addListener(String key, EnumSet<NetworkTableEvent.Kind> eventKinds, NetworkTable.TableEventListener listener)
Listen to a single key.int
addListener(EnumSet<NetworkTableEvent.Kind> eventKinds, NetworkTable.TableEventListener listener)
Listen to topics only within this table.int
addSubTableListener(NetworkTable.SubTableListener listener)
Listen for sub-table creation.static String
basenameKey(String key)
Gets the "base name" of a key.boolean
containsKey(String key)
Checks the table and tells if it contains the specified key.boolean
containsSubTable(String key)
Checks the table and tells if it contains the specified sub table.boolean
equals(Object other)
BooleanArrayTopic
getBooleanArrayTopic(String name)
Get boolean[] topic.BooleanTopic
getBooleanTopic(String name)
Get boolean topic.DoubleArrayTopic
getDoubleArrayTopic(String name)
Get double[] topic.DoubleTopic
getDoubleTopic(String name)
Get double topic.NetworkTableEntry
getEntry(String key)
Gets the entry for a sub key.FloatArrayTopic
getFloatArrayTopic(String name)
Get float[] topic.FloatTopic
getFloatTopic(String name)
Get float topic.static List<String>
getHierarchy(String key)
Gets a list of the names of all the super tables of a given key.NetworkTableInstance
getInstance()
Gets the instance for the table.IntegerArrayTopic
getIntegerArrayTopic(String name)
Get long[] topic.IntegerTopic
getIntegerTopic(String name)
Get long topic.Set<String>
getKeys()
Gets all keys in the table (not including sub-tables).Set<String>
getKeys(int types)
Gets all keys in the table (not including sub-tables).String
getPath()
Get the path of the NetworkTable.<T, MessageType extends us.hebi.quickbuf.ProtoMessage<?>>
ProtobufTopic<T>getProtobufTopic(String name, Protobuf<T,MessageType> proto)
Get protobuf-encoded value topic.RawTopic
getRawTopic(String name)
Get raw topic.StringArrayTopic
getStringArrayTopic(String name)
Get String[] topic.StringTopic
getStringTopic(String name)
Get String topic.<T> StructArrayTopic<T>
getStructArrayTopic(String name, Struct<T> struct)
Get struct-encoded value array topic.<T> StructTopic<T>
getStructTopic(String name, Struct<T> struct)
Get struct-encoded value topic.NetworkTable
getSubTable(String key)
Returns the table at the specified key.Set<String>
getSubTables()
Gets the names of all subtables in the table.Topic
getTopic(String name)
Get (generic) topic.List<TopicInfo>
getTopicInfo()
Gets topic information for all keys in the table (not including sub-tables).List<TopicInfo>
getTopicInfo(int types)
Gets topic information for all keys in the table (not including sub-tables).List<Topic>
getTopics()
Gets all topics in the table (not including sub-tables).List<Topic>
getTopics(int types)
Gets all topics in the table (not including sub-tables).NetworkTableValue
getValue(String key)
Gets the value associated with a key as an object.int
hashCode()
static String
normalizeKey(String key)
Normalizes a network table key to start with exactly one leading slash ("/") and contain no consecutive slashes.static String
normalizeKey(String key, boolean withLeadingSlash)
Normalizes an network table key to contain no consecutive slashes and optionally start with a leading slash.boolean
putValue(String key, NetworkTableValue value)
Put a value in the table.void
removeListener(int listener)
Remove a listener.boolean
setDefaultValue(String key, NetworkTableValue defaultValue)
Gets the current value in the table, setting it if it does not exist.String
toString()
-
Field Details
-
PATH_SEPARATOR
The path separator for sub-tables and keys.- See Also:
- Constant Field Values
-
-
Method Details
-
basenameKey
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
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 normalizewithLeadingSlash
- whether or not the normalized key should begin with a leading slash- Returns:
- normalized key
-
normalizeKey
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
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
-
getTopic
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
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 nameproto
- protobuf serialization implementation- Returns:
- ProtobufTopic
-
getStructTopic
Get struct-encoded value topic.- Type Parameters:
T
- value class (inferred from struct)- Parameters:
name
- topic namestruct
- struct serialization implementation- Returns:
- StructTopic
-
getStructArrayTopic
Get struct-encoded value array topic.- Type Parameters:
T
- value class (inferred from struct)- Parameters:
name
- topic namestruct
- 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
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
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
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
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
Gets all topics in the table (not including sub-tables).- Returns:
- topic for keys currently in the table
-
getKeys
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
Gets all keys in the table (not including sub-tables).- Returns:
- keys currently in the table
-
getSubTables
Gets the names of all subtables in the table.- Returns:
- subtables currently in the table
-
putValue
Put a value in the table.- Parameters:
key
- the key to be assigned tovalue
- the value that will be assigned- Returns:
- False if the table key already exists with a different type
-
setDefaultValue
Gets the current value in the table, setting it if it does not exist.- Parameters:
key
- the keydefaultValue
- 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
Get the path of the NetworkTable.- Returns:
- The path of the NetworkTable.
-
addListener
public int addListener(EnumSet<NetworkTableEvent.Kind> eventKinds, NetworkTable.TableEventListener listener)Listen to topics only within this table.- Parameters:
eventKinds
- set of event kinds to listen tolistener
- listener to add- Returns:
- Listener handle
-
addListener
public int addListener(String key, EnumSet<NetworkTableEvent.Kind> eventKinds, NetworkTable.TableEventListener listener)Listen to a single key.- Parameters:
key
- the key nameeventKinds
- set of event kinds to listen tolistener
- 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
Remove a listener.- Parameters:
listener
- listener handle
-
equals
-
hashCode
-