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.
-
-
Field Summary
Fields Modifier and Type Field Description static char
PATH_SEPARATOR
The path separator for sub-tables and keys.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
addEntryListener(TableEntryListener listener, int flags)
Listen to keys only within this table.int
addEntryListener(String key, TableEntryListener listener, int flags)
Listen to a single key.int
addSubTableListener(TableListener listener, boolean localNotify)
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.void
delete(String key)
Deletes the specified key in this table.boolean
equals(Object other)
NetworkTableEntry
getEntry(String key)
Gets the entry for a sub key.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.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.NetworkTable
getSubTable(String key)
Returns the table at the specified key.Set<String>
getSubTables()
Gets the names of all subtables in the table.int
hashCode()
String[]
loadEntries(String filename)
Load table values from a file.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.void
removeEntryListener(int listener)
Remove an entry listener.void
removeTableListener(int listener)
Remove a sub-table listener.void
saveEntries(String filename)
Save table values to a file.String
toString()
-
-
-
Field Detail
-
PATH_SEPARATOR
public static final char PATH_SEPARATOR
The path separator for sub-tables and keys.- See Also:
- Constant Field Values
-
-
Method Detail
-
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 normalizewithLeadingSlash
- 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
public NetworkTableInstance getInstance()
Gets the instance for the table.- Returns:
- Instance
-
getEntry
public NetworkTableEntry getEntry(String key)
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 addflags
-EntryListenerFlags
bitmask- Returns:
- Listener handle
-
addEntryListener
public int addEntryListener(String key, TableEntryListener listener, int flags)
Listen to a single key.- Parameters:
key
- the key namelistener
- listener to addflags
-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 addlocalNotify
- 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
-
-