mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
Add ITable/NetworkTable GetKeys and GetSubTables accessors.
This commit is contained in:
@@ -367,13 +367,47 @@ public class NetworkTable implements ITable, IRemote {
|
||||
}
|
||||
|
||||
public boolean containsSubTable(String key) {
|
||||
String subtablePrefix = path + key + PATH_SEPARATOR;
|
||||
//List keys = node.getEntryStore().keys();
|
||||
//for (int i = 0; i < keys.size(); ++i) {
|
||||
// if (((String)keys.get(i)).startsWith(subtablePrefix))
|
||||
// return true;
|
||||
//}
|
||||
return false;
|
||||
EntryInfo[] entries = NetworkTablesJNI.getEntries(path + PATH_SEPARATOR + key + PATH_SEPARATOR, 0);
|
||||
return entries.length != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param types bitmask of types; 0 is treated as a "don't care".
|
||||
* @return keys currently in the table
|
||||
*/
|
||||
public Set<String> getKeys(int types) {
|
||||
Set<String> keys = new HashSet<String>();
|
||||
int prefixLen = path.length() + 1;
|
||||
for (EntryInfo entry : NetworkTablesJNI.getEntries(path + PATH_SEPARATOR, types)) {
|
||||
String relativeKey = entry.name.substring(prefixLen);
|
||||
if (relativeKey.indexOf(PATH_SEPARATOR) != -1)
|
||||
continue;
|
||||
keys.add(relativeKey);
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return keys currently in the table
|
||||
*/
|
||||
public Set<String> getKeys() {
|
||||
return getKeys(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return subtables currently in the table
|
||||
*/
|
||||
public Set<String> getSubTables() {
|
||||
Set<String> keys = new HashSet<String>();
|
||||
int prefixLen = path.length() + 1;
|
||||
for (EntryInfo entry : NetworkTablesJNI.getEntries(path + PATH_SEPARATOR, 0)) {
|
||||
String relativeKey = entry.name.substring(prefixLen);
|
||||
int endSubTable = relativeKey.indexOf(PATH_SEPARATOR);
|
||||
if (endSubTable == -1)
|
||||
continue;
|
||||
keys.add(relativeKey.substring(0, endSubTable));
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -98,7 +98,7 @@ public class NetworkTablesJNI {
|
||||
public static native void deleteEntry(String key);
|
||||
public static native void deleteAllEntries();
|
||||
|
||||
// public static native EntryInfo[] getEntryInfo(String prefix, int types);
|
||||
public static native EntryInfo[] getEntries(String prefix, int types);
|
||||
|
||||
public static native void flush();
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package edu.wpi.first.wpilibj.tables;
|
||||
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
/**
|
||||
@@ -30,6 +31,22 @@ public interface ITable {
|
||||
*/
|
||||
public ITable getSubTable(String key);
|
||||
|
||||
/**
|
||||
* @param types bitmask of types; 0 is treated as a "don't care".
|
||||
* @return keys currently in the table
|
||||
*/
|
||||
public Set<String> getKeys(int types);
|
||||
|
||||
/**
|
||||
* @return keys currently in the table
|
||||
*/
|
||||
public Set<String> getKeys();
|
||||
|
||||
/**
|
||||
* @return subtables currently in the table
|
||||
*/
|
||||
public Set<String> getSubTables();
|
||||
|
||||
/**
|
||||
* Makes a key's value persistent through program restarts.
|
||||
* The key cannot be null.
|
||||
|
||||
Reference in New Issue
Block a user