[build] Apply spotless for java formatting (#1768)

Update checkstyle config to be compatible with spotless.

Co-authored-by: Austin Shalit <austinshalit@gmail.com>
This commit is contained in:
Peter Johnson
2020-12-29 22:45:16 -08:00
committed by GitHub
parent e563a0b7db
commit a751fa22d2
883 changed files with 16526 additions and 17751 deletions

View File

@@ -8,15 +8,12 @@ import edu.wpi.first.networktables.NetworkTablesJNI;
import edu.wpi.first.wpiutil.RuntimeDetector;
public final class DevMain {
/**
* Main method.
*/
/** Main method. */
public static void main(String[] args) {
System.out.println("Hello World!");
System.out.println(RuntimeDetector.getPlatformPath());
NetworkTablesJNI.flush(NetworkTablesJNI.getDefaultInstance());
}
private DevMain() {
}
private DevMain() {}
}

View File

@@ -4,45 +4,39 @@
package edu.wpi.first.networktables;
/**
* NetworkTables Connection information.
*/
/** NetworkTables Connection information. */
public final class ConnectionInfo {
/**
* The remote identifier (as set on the remote node by
* {@link NetworkTableInstance#setNetworkIdentity(String)}).
* The remote identifier (as set on the remote node by {@link
* NetworkTableInstance#setNetworkIdentity(String)}).
*/
@SuppressWarnings("MemberName")
public final String remote_id;
/**
* The IP address of the remote node.
*/
/** The IP address of the remote node. */
@SuppressWarnings("MemberName")
public final String remote_ip;
/**
* The port number of the remote node.
*/
/** The port number of the remote node. */
@SuppressWarnings("MemberName")
public final int remote_port;
/**
* The last time any update was received from the remote node (same scale as
* returned by {@link NetworkTablesJNI#now()}).
* The last time any update was received from the remote node (same scale as returned by {@link
* NetworkTablesJNI#now()}).
*/
@SuppressWarnings("MemberName")
public final long last_update;
/**
* The protocol version being used for this connection. This is in protocol
* layer format, so 0x0200 = 2.0, 0x0300 = 3.0).
* The protocol version being used for this connection. This is in protocol layer format, so
* 0x0200 = 2.0, 0x0300 = 3.0).
*/
@SuppressWarnings("MemberName")
public final int protocol_version;
/** Constructor.
* This should generally only be used internally to NetworkTables.
/**
* Constructor. This should generally only be used internally to NetworkTables.
*
* @param remoteId Remote identifier
* @param remoteIp Remote IP address
@@ -50,8 +44,8 @@ public final class ConnectionInfo {
* @param lastUpdate Last time an update was received
* @param protocolVersion The protocol version used for the connection
*/
public ConnectionInfo(String remoteId, String remoteIp, int remotePort, long lastUpdate,
int protocolVersion) {
public ConnectionInfo(
String remoteId, String remoteIp, int remotePort, long lastUpdate, int protocolVersion) {
remote_id = remoteId;
remote_ip = remoteIp;
remote_port = remotePort;

View File

@@ -4,38 +4,30 @@
package edu.wpi.first.networktables;
/**
* NetworkTables Connection notification.
*/
/** NetworkTables Connection notification. */
public final class ConnectionNotification {
/**
* Listener that was triggered.
*/
/** Listener that was triggered. */
@SuppressWarnings("MemberName")
public final int listener;
/**
* True if event is due to connection being established.
*/
/** True if event is due to connection being established. */
@SuppressWarnings("MemberName")
public final boolean connected;
/**
* Connection information.
*/
/** Connection information. */
@SuppressWarnings("MemberName")
public final ConnectionInfo conn;
/** Constructor.
* This should generally only be used internally to NetworkTables.
/**
* Constructor. This should generally only be used internally to NetworkTables.
*
* @param inst Instance
* @param listener Listener that was triggered
* @param connected Connected if true
* @param conn Connection information
*/
public ConnectionNotification(NetworkTableInstance inst, int listener, boolean connected,
ConnectionInfo conn) {
public ConnectionNotification(
NetworkTableInstance inst, int listener, boolean connected, ConnectionInfo conn) {
this.m_inst = inst;
this.listener = listener;
this.connected = connected;

View File

@@ -4,9 +4,7 @@
package edu.wpi.first.networktables;
/**
* NetworkTables Entry information.
*/
/** NetworkTables Entry information. */
public final class EntryInfo {
/** Entry handle. */
@SuppressWarnings("MemberName")
@@ -28,8 +26,8 @@ public final class EntryInfo {
@SuppressWarnings("MemberName")
public final long last_change;
/** Constructor.
* This should generally only be used internally to NetworkTables.
/**
* Constructor. This should generally only be used internally to NetworkTables.
*
* @param inst Instance
* @param entry Entry handle
@@ -38,8 +36,8 @@ public final class EntryInfo {
* @param flags Flags
* @param lastChange Timestamp of last change
*/
public EntryInfo(NetworkTableInstance inst, int entry, String name, int type, int flags,
long lastChange) {
public EntryInfo(
NetworkTableInstance inst, int entry, String name, int type, int flags, long lastChange) {
this.m_inst = inst;
this.entry = entry;
this.name = name;

View File

@@ -7,33 +7,32 @@ package edu.wpi.first.networktables;
/**
* Flag values for use with entry listeners.
*
* <p>The flags are a bitmask and must be OR'ed together to indicate the
* combination of events desired to be received.
* <p>The flags are a bitmask and must be OR'ed together to indicate the combination of events
* desired to be received.
*
* <p>The constants kNew, kDelete, kUpdate, and kFlags represent different events
* that can occur to entries.
* <p>The constants kNew, kDelete, kUpdate, and kFlags represent different events that can occur to
* entries.
*
* <p>By default, notifications are only generated for remote changes occurring
* after the listener is created. The constants kImmediate and kLocal are
* modifiers that cause notifications to be generated at other times.
* <p>By default, notifications are only generated for remote changes occurring after the listener
* is created. The constants kImmediate and kLocal are modifiers that cause notifications to be
* generated at other times.
*/
public interface EntryListenerFlags {
/**
* Initial listener addition.
*
* <p>Set this flag to receive immediate notification of entries matching the
* flag criteria (generally only useful when combined with kNew).
* <p>Set this flag to receive immediate notification of entries matching the flag criteria
* (generally only useful when combined with kNew).
*/
int kImmediate = 0x01;
/**
* Changed locally.
*
* <p>Set this flag to receive notification of both local changes and changes
* coming from remote nodes. By default, notifications are only generated
* for remote changes. Must be combined with some combination of kNew,
* kDelete, kUpdate, and kFlags to receive notifications of those respective
* events.
* <p>Set this flag to receive notification of both local changes and changes coming from remote
* nodes. By default, notifications are only generated for remote changes. Must be combined with
* some combination of kNew, kDelete, kUpdate, and kFlags to receive notifications of those
* respective events.
*/
int kLocal = 0x02;
@@ -54,16 +53,14 @@ public interface EntryListenerFlags {
/**
* Entry's value changed.
*
* <p>Set this flag to receive a notification when an entry's value (or type)
* changes.
* <p>Set this flag to receive a notification when an entry's value (or type) changes.
*/
int kUpdate = 0x10;
/**
* Entry's flags changed.
*
* <p>Set this flag to receive a notification when an entry's flags value
* changes.
* <p>Set this flag to receive a notification when an entry's flags value changes.
*/
int kFlags = 0x20;
}

View File

@@ -4,43 +4,32 @@
package edu.wpi.first.networktables;
/**
* NetworkTables Entry notification.
*/
/** NetworkTables Entry notification. */
public final class EntryNotification {
/**
* Listener that was triggered.
*/
/** Listener that was triggered. */
@SuppressWarnings("MemberName")
public final int listener;
/**
* Entry handle.
*/
/** Entry handle. */
@SuppressWarnings("MemberName")
public final int entry;
/**
* Entry name.
*/
/** Entry name. */
@SuppressWarnings("MemberName")
public final String name;
/**
* The new value.
*/
/** The new value. */
@SuppressWarnings("MemberName")
public final NetworkTableValue value;
/**
* Update flags. For example, {@link EntryListenerFlags#kNew} if the key did
* not previously exist.
* Update flags. For example, {@link EntryListenerFlags#kNew} if the key did not previously exist.
*/
@SuppressWarnings("MemberName")
public final int flags;
/** Constructor.
* This should generally only be used internally to NetworkTables.
/**
* Constructor. This should generally only be used internally to NetworkTables.
*
* @param inst Instance
* @param listener Listener that was triggered
@@ -49,8 +38,13 @@ public final class EntryNotification {
* @param value The new value
* @param flags Update flags
*/
public EntryNotification(NetworkTableInstance inst, int listener, int entry, String name,
NetworkTableValue value, int flags) {
public EntryNotification(
NetworkTableInstance inst,
int listener,
int entry,
String name,
NetworkTableValue value,
int flags) {
this.m_inst = inst;
this.listener = listener;
this.entry = entry;

View File

@@ -4,14 +4,11 @@
package edu.wpi.first.networktables;
/**
* NetworkTables log message.
*/
/** NetworkTables log message. */
public final class LogMessage {
/**
* Logging levels.
*/
/** Logging levels. */
public static final int kCritical = 50;
public static final int kError = 40;
public static final int kWarning = 30;
public static final int kInfo = 20;
@@ -21,38 +18,28 @@ public final class LogMessage {
public static final int kDebug3 = 7;
public static final int kDebug4 = 6;
/**
* The logger that generated the message.
*/
/** The logger that generated the message. */
@SuppressWarnings("MemberName")
public final int logger;
/**
* Log level of the message.
*/
/** Log level of the message. */
@SuppressWarnings("MemberName")
public final int level;
/**
* The filename of the source file that generated the message.
*/
/** The filename of the source file that generated the message. */
@SuppressWarnings("MemberName")
public final String filename;
/**
* The line number in the source file that generated the message.
*/
/** The line number in the source file that generated the message. */
@SuppressWarnings("MemberName")
public final int line;
/**
* The message.
*/
/** The message. */
@SuppressWarnings("MemberName")
public final String message;
/** Constructor.
* This should generally only be used internally to NetworkTables.
/**
* Constructor. This should generally only be used internally to NetworkTables.
*
* @param inst Instance
* @param logger Logger
@@ -61,8 +48,8 @@ public final class LogMessage {
* @param line Line number
* @param message Message
*/
public LogMessage(NetworkTableInstance inst, int logger, int level, String filename, int line,
String message) {
public LogMessage(
NetworkTableInstance inst, int logger, int level, String filename, int line, String message) {
this.m_inst = inst;
this.logger = logger;
this.level = level;

View File

@@ -13,13 +13,9 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.function.Consumer;
/**
* A network table that knows its subtable path.
*/
/** A network table that knows its subtable path. */
public final class NetworkTable {
/**
* The path separator for sub-tables and keys.
*/
/** The path separator for sub-tables and keys. */
public static final char PATH_SEPARATOR = '/';
private final String m_path;
@@ -27,8 +23,8 @@ public final class NetworkTable {
private final NetworkTableInstance m_inst;
/**
* Gets the "base name" of a key. For example, "/foo/bar" becomes "bar".
* If the key has a trailing slash, returns an empty string.
* Gets the "base name" of a key. For example, "/foo/bar" becomes "bar". If the key has a trailing
* slash, returns an empty string.
*
* @param key key
* @return base name
@@ -42,8 +38,8 @@ public final class NetworkTable {
}
/**
* Normalizes an network table key to contain no consecutive slashes and
* optionally start with a leading slash. For example:
* Normalizes an network table key to contain no consecutive slashes and optionally start with a
* leading slash. For example:
*
* <pre><code>
* normalizeKey("/foo/bar", true) == "/foo/bar"
@@ -52,9 +48,8 @@ public final class NetworkTable {
* normalizeKey("foo//bar", false) == "foo/bar"
* </code></pre>
*
* @param key the key to normalize
* @param withLeadingSlash whether or not the normalized key should begin
* with a leading slash
* @param key the key to normalize
* @param withLeadingSlash whether or not the normalized key should begin with a leading slash
* @return normalized key
*/
public static String normalizeKey(String key, boolean withLeadingSlash) {
@@ -74,10 +69,9 @@ public final class NetworkTable {
}
/**
* Normalizes a network table key to start with exactly one leading slash
* ("/") and contain no consecutive slashes. For example,
* {@code "//foo/bar/"} becomes {@code "/foo/bar/"} and
* {@code "///a/b/c"} becomes {@code "/a/b/c"}.
* Normalizes a network table key to start with exactly one leading slash ("/") and contain no
* consecutive slashes. For example, {@code "//foo/bar/"} becomes {@code "/foo/bar/"} and {@code
* "///a/b/c"} becomes {@code "/a/b/c"}.
*
* <p>This is equivalent to {@code normalizeKey(key, true)}
*
@@ -89,9 +83,8 @@ public final class NetworkTable {
}
/**
* 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".
* 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".
*
* @param key the key
* @return List of super tables
@@ -115,9 +108,7 @@ public final class NetworkTable {
return hierarchy;
}
/**
* Constructor. Use NetworkTableInstance.getTable() or getSubTable() instead.
*/
/** Constructor. Use NetworkTableInstance.getTable() or getSubTable() instead. */
NetworkTable(NetworkTableInstance inst, String path) {
m_path = path;
m_pathWithSep = path + PATH_SEPARATOR;
@@ -158,52 +149,54 @@ public final class NetworkTable {
/**
* Listen to keys only within this table.
*
* @param listener listener to add
* @param flags {@link EntryListenerFlags} bitmask
* @param listener listener to add
* @param flags {@link EntryListenerFlags} bitmask
* @return Listener handle
*/
public int addEntryListener(TableEntryListener listener, int flags) {
final int prefixLen = m_path.length() + 1;
return m_inst.addEntryListener(m_pathWithSep, event -> {
String relativeKey = event.name.substring(prefixLen);
if (relativeKey.indexOf(PATH_SEPARATOR) != -1) {
// part of a sub table
return;
}
listener.valueChanged(this, relativeKey, event.getEntry(), event.value, event.flags);
}, flags);
return m_inst.addEntryListener(
m_pathWithSep,
event -> {
String relativeKey = event.name.substring(prefixLen);
if (relativeKey.indexOf(PATH_SEPARATOR) != -1) {
// part of a sub table
return;
}
listener.valueChanged(this, relativeKey, event.getEntry(), event.value, event.flags);
},
flags);
}
/**
* Listen to a single key.
*
* @param key the key name
* @param listener listener to add
* @param flags {@link EntryListenerFlags} bitmask
* @param key the key name
* @param listener listener to add
* @param flags {@link EntryListenerFlags} bitmask
* @return Listener handle
*/
public int addEntryListener(String key, TableEntryListener listener, int flags) {
final NetworkTableEntry entry = getEntry(key);
return m_inst.addEntryListener(entry,
event -> listener.valueChanged(this, key, entry, event.value, event.flags), flags);
return m_inst.addEntryListener(
entry, event -> listener.valueChanged(this, key, entry, event.value, event.flags), flags);
}
/**
* Remove an entry listener.
*
* @param listener listener handle
* @param listener listener handle
*/
public void removeEntryListener(int listener) {
m_inst.removeEntryListener(listener);
}
/**
* Listen for sub-table creation.
* This calls the listener once for each newly created sub-table.
* 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.
*
* @param listener listener to add
* @param localNotify notify local changes as well as remote
* @param listener listener to add
* @param localNotify notify local changes as well as remote
* @return Listener handle
*/
public int addSubTableListener(TableListener listener, boolean localNotify) {
@@ -215,38 +208,41 @@ public final class NetworkTable {
final int prefixLen = m_path.length() + 1;
final NetworkTable parent = this;
return m_inst.addEntryListener(m_pathWithSep, new Consumer<>() {
final Set<String> m_notifiedTables = new HashSet<>();
return m_inst.addEntryListener(
m_pathWithSep,
new Consumer<>() {
final Set<String> m_notifiedTables = new HashSet<>();
@Override
public void accept(EntryNotification event) {
String relativeKey = event.name.substring(prefixLen);
int endSubTable = relativeKey.indexOf(PATH_SEPARATOR);
if (endSubTable == -1) {
return;
}
String subTableKey = relativeKey.substring(0, endSubTable);
if (m_notifiedTables.contains(subTableKey)) {
return;
}
m_notifiedTables.add(subTableKey);
listener.tableCreated(parent, subTableKey, parent.getSubTable(subTableKey));
}
}, flags);
@Override
public void accept(EntryNotification event) {
String relativeKey = event.name.substring(prefixLen);
int endSubTable = relativeKey.indexOf(PATH_SEPARATOR);
if (endSubTable == -1) {
return;
}
String subTableKey = relativeKey.substring(0, endSubTable);
if (m_notifiedTables.contains(subTableKey)) {
return;
}
m_notifiedTables.add(subTableKey);
listener.tableCreated(parent, subTableKey, parent.getSubTable(subTableKey));
}
},
flags);
}
/**
* Remove a sub-table listener.
*
* @param listener listener handle
* @param listener listener handle
*/
public void removeTableListener(int listener) {
m_inst.removeEntryListener(listener);
}
/**
* Returns the table at the specified key. If there is no table at the
* specified key, it will create a new table
* Returns the table at the specified key. If there is no table at the specified key, it will
* create a new table
*
* @param key the name of the table relative to this one
* @return a sub table relative to this one
@@ -273,8 +269,8 @@ public final class NetworkTable {
* its own
*/
public boolean containsSubTable(String key) {
int[] handles = NetworkTablesJNI.getEntries(m_inst.getHandle(),
m_pathWithSep + key + PATH_SEPARATOR, 0);
int[] handles =
NetworkTablesJNI.getEntries(m_inst.getHandle(), m_pathWithSep + key + PATH_SEPARATOR, 0);
return handles.length != 0;
}
@@ -330,8 +326,7 @@ public final class NetworkTable {
}
/**
* Deletes the specified key in this table. The key can
* not be null.
* Deletes the specified key in this table. The key can not be null.
*
* @param key the key name
*/
@@ -371,18 +366,15 @@ public final class NetworkTable {
return getEntry(key).getValue();
}
/**
* Get the path of the NetworkTable.
*/
/** Get the path of the NetworkTable. */
public String getPath() {
return m_path;
}
/**
* Save table values to a file. The file format used is identical to
* that used for SavePersistent.
* Save table values to a file. The file format used is identical to that used for SavePersistent.
*
* @param filename filename
* @param filename filename
* @throws PersistentException if error saving file
*/
public void saveEntries(String filename) throws PersistentException {
@@ -390,10 +382,10 @@ public final class NetworkTable {
}
/**
* Load table values from a file. The file format used is identical to
* that used for SavePersistent / LoadPersistent.
* Load table values from a file. The file format used is identical to that used for
* SavePersistent / LoadPersistent.
*
* @param filename filename
* @param filename filename
* @return List of warnings (errors result in an exception instead)
* @throws PersistentException if error saving file
*/

View File

@@ -7,13 +7,9 @@ package edu.wpi.first.networktables;
import java.nio.ByteBuffer;
import java.util.function.Consumer;
/**
* NetworkTables Entry.
*/
/** NetworkTables Entry. */
public final class NetworkTableEntry {
/**
* Flag values (as returned by {@link #getFlags()}).
*/
/** Flag values (as returned by {@link #getFlags()}). */
public static final int kPersistent = 0x01;
/**
@@ -109,8 +105,7 @@ public final class NetworkTableEntry {
}
/**
* Gets the entry's value.
* Returns a value with type NetworkTableType.kUnassigned if the value
* Gets the entry's value. Returns a value with type NetworkTableType.kUnassigned if the value
* does not exist.
*
* @return the entry's value
@@ -120,8 +115,8 @@ public final class NetworkTableEntry {
}
/**
* Gets the entry's value as a boolean. If the entry does not exist or is of
* different type, it will return the default value.
* Gets the entry's value as a boolean. If the entry does not exist or is of different type, it
* will return the default value.
*
* @param defaultValue the value to be returned if no value is found
* @return the entry's value or the given default value
@@ -131,8 +126,8 @@ public final class NetworkTableEntry {
}
/**
* Gets the entry's value as a double. If the entry does not exist or is of
* different type, it will return the default value.
* Gets the entry's value as a double. If the entry does not exist or is of different type, it
* will return the default value.
*
* @param defaultValue the value to be returned if no value is found
* @return the entry's value or the given default value
@@ -142,8 +137,8 @@ public final class NetworkTableEntry {
}
/**
* Gets the entry's value as a double. If the entry does not exist or is of
* different type, it will return the default value.
* Gets the entry's value as a double. If the entry does not exist or is of different type, it
* will return the default value.
*
* @param defaultValue the value to be returned if no value is found
* @return the entry's value or the given default value
@@ -153,8 +148,8 @@ public final class NetworkTableEntry {
}
/**
* Gets the entry's value as a string. If the entry does not exist or is of
* different type, it will return the default value.
* Gets the entry's value as a string. If the entry does not exist or is of different type, it
* will return the default value.
*
* @param defaultValue the value to be returned if no value is found
* @return the entry's value or the given default value
@@ -164,8 +159,8 @@ public final class NetworkTableEntry {
}
/**
* Gets the entry's value as a raw value (byte array). If the entry does not
* exist or is of different type, it will return the default value.
* Gets the entry's value as a raw value (byte array). If the entry does not exist or is of
* different type, it will return the default value.
*
* @param defaultValue the value to be returned if no value is found
* @return the entry's value or the given default value
@@ -175,8 +170,8 @@ public final class NetworkTableEntry {
}
/**
* Gets the entry's value as a boolean array. If the entry does not exist
* or is of different type, it will return the default value.
* Gets the entry's value as a boolean array. If the entry does not exist or is of different type,
* it will return the default value.
*
* @param defaultValue the value to be returned if no value is found
* @return the entry's value or the given default value
@@ -186,20 +181,20 @@ public final class NetworkTableEntry {
}
/**
* Gets the entry's value as a boolean array. If the entry does not exist
* or is of different type, it will return the default value.
* Gets the entry's value as a boolean array. If the entry does not exist or is of different type,
* it will return the default value.
*
* @param defaultValue the value to be returned if no value is found
* @return the entry's value or the given default value
*/
public Boolean[] getBooleanArray(Boolean[] defaultValue) {
return NetworkTableValue.fromNative(NetworkTablesJNI.getBooleanArray(m_handle,
NetworkTableValue.toNative(defaultValue)));
return NetworkTableValue.fromNative(
NetworkTablesJNI.getBooleanArray(m_handle, NetworkTableValue.toNative(defaultValue)));
}
/**
* Gets the entry's value as a double array. If the entry does not exist
* or is of different type, it will return the default value.
* Gets the entry's value as a double array. If the entry does not exist or is of different type,
* it will return the default value.
*
* @param defaultValue the value to be returned if no value is found
* @return the entry's value or the given default value
@@ -209,32 +204,32 @@ public final class NetworkTableEntry {
}
/**
* Gets the entry's value as a double array. If the entry does not exist
* or is of different type, it will return the default value.
* Gets the entry's value as a double array. If the entry does not exist or is of different type,
* it will return the default value.
*
* @param defaultValue the value to be returned if no value is found
* @return the entry's value or the given default value
*/
public Double[] getDoubleArray(Double[] defaultValue) {
return NetworkTableValue.fromNative(NetworkTablesJNI.getDoubleArray(m_handle,
NetworkTableValue.toNative(defaultValue)));
return NetworkTableValue.fromNative(
NetworkTablesJNI.getDoubleArray(m_handle, NetworkTableValue.toNative(defaultValue)));
}
/**
* Gets the entry's value as a double array. If the entry does not exist
* or is of different type, it will return the default value.
* Gets the entry's value as a double array. If the entry does not exist or is of different type,
* it will return the default value.
*
* @param defaultValue the value to be returned if no value is found
* @return the entry's value or the given default value
*/
public Number[] getNumberArray(Number[] defaultValue) {
return NetworkTableValue.fromNative(NetworkTablesJNI.getDoubleArray(m_handle,
NetworkTableValue.toNative(defaultValue)));
return NetworkTableValue.fromNative(
NetworkTablesJNI.getDoubleArray(m_handle, NetworkTableValue.toNative(defaultValue)));
}
/**
* Gets the entry's value as a string array. If the entry does not exist
* or is of different type, it will return the default value.
* Gets the entry's value as a string array. If the entry does not exist or is of different type,
* it will return the default value.
*
* @param defaultValue the value to be returned if no value is found
* @return the entry's value or the given default value
@@ -276,11 +271,10 @@ public final class NetworkTableEntry {
Object otherValue = ((NetworkTableValue) defaultValue).getValue();
switch (((NetworkTableValue) defaultValue).getType()) {
case kBoolean:
return NetworkTablesJNI.setDefaultBoolean(m_handle, time,
(Boolean) otherValue);
return NetworkTablesJNI.setDefaultBoolean(m_handle, time, (Boolean) otherValue);
case kDouble:
return NetworkTablesJNI.setDefaultDouble(m_handle, time,
((Number) otherValue).doubleValue());
return NetworkTablesJNI.setDefaultDouble(
m_handle, time, ((Number) otherValue).doubleValue());
case kString:
return NetworkTablesJNI.setDefaultString(m_handle, time, (String) otherValue);
case kRaw:
@@ -302,21 +296,21 @@ public final class NetworkTableEntry {
return setDefaultNumber((Number) defaultValue);
} else if (defaultValue instanceof String) {
return setDefaultString((String) defaultValue);
} else if (defaultValue instanceof byte[]) {
} else if (defaultValue instanceof byte[]) {
return setDefaultRaw((byte[]) defaultValue);
} else if (defaultValue instanceof boolean[]) {
} else if (defaultValue instanceof boolean[]) {
return setDefaultBooleanArray((boolean[]) defaultValue);
} else if (defaultValue instanceof double[]) {
} else if (defaultValue instanceof double[]) {
return setDefaultDoubleArray((double[]) defaultValue);
} else if (defaultValue instanceof Boolean[]) {
} else if (defaultValue instanceof Boolean[]) {
return setDefaultBooleanArray((Boolean[]) defaultValue);
} else if (defaultValue instanceof Number[]) {
} else if (defaultValue instanceof Number[]) {
return setDefaultNumberArray((Number[]) defaultValue);
} else if (defaultValue instanceof String[]) {
} else if (defaultValue instanceof String[]) {
return setDefaultStringArray((String[]) defaultValue);
} else {
throw new IllegalArgumentException("Value of type " + defaultValue.getClass().getName()
+ " cannot be put into a table");
throw new IllegalArgumentException(
"Value of type " + defaultValue.getClass().getName() + " cannot be put into a table");
}
}
@@ -387,8 +381,8 @@ public final class NetworkTableEntry {
* @return False if the entry exists with a different type
*/
public boolean setDefaultBooleanArray(Boolean[] defaultValue) {
return NetworkTablesJNI.setDefaultBooleanArray(m_handle,
0, NetworkTableValue.toNative(defaultValue));
return NetworkTablesJNI.setDefaultBooleanArray(
m_handle, 0, NetworkTableValue.toNative(defaultValue));
}
/**
@@ -408,8 +402,8 @@ public final class NetworkTableEntry {
* @return False if the entry exists with a different type
*/
public boolean setDefaultNumberArray(Number[] defaultValue) {
return NetworkTablesJNI.setDefaultDoubleArray(m_handle,
0, NetworkTableValue.toNative(defaultValue));
return NetworkTablesJNI.setDefaultDoubleArray(
m_handle, 0, NetworkTableValue.toNative(defaultValue));
}
/**
@@ -435,11 +429,10 @@ public final class NetworkTableEntry {
Object otherValue = ((NetworkTableValue) value).getValue();
switch (((NetworkTableValue) value).getType()) {
case kBoolean:
return NetworkTablesJNI.setBoolean(m_handle, time, (Boolean) otherValue,
false);
return NetworkTablesJNI.setBoolean(m_handle, time, (Boolean) otherValue, false);
case kDouble:
return NetworkTablesJNI.setDouble(m_handle, time, ((Number) otherValue).doubleValue(),
false);
return NetworkTablesJNI.setDouble(
m_handle, time, ((Number) otherValue).doubleValue(), false);
case kString:
return NetworkTablesJNI.setString(m_handle, time, (String) otherValue, false);
case kRaw:
@@ -474,8 +467,8 @@ public final class NetworkTableEntry {
} else if (value instanceof String[]) {
return setStringArray((String[]) value);
} else {
throw new IllegalArgumentException("Value of type " + value.getClass().getName()
+ " cannot be put into a table");
throw new IllegalArgumentException(
"Value of type " + value.getClass().getName() + " cannot be put into a table");
}
}
@@ -597,8 +590,8 @@ public final class NetworkTableEntry {
}
/**
* Sets the entry's value. If the value is of different type, the type is
* changed to match the new value.
* Sets the entry's value. If the value is of different type, the type is changed to match the new
* value.
*
* @param value the value to set
* @throws IllegalArgumentException if the value is not a known type
@@ -653,14 +646,14 @@ public final class NetworkTableEntry {
} else if (value instanceof String[]) {
forceSetStringArray((String[]) value);
} else {
throw new IllegalArgumentException("Value of type " + value.getClass().getName()
+ " cannot be put into a table");
throw new IllegalArgumentException(
"Value of type " + value.getClass().getName() + " cannot be put into a table");
}
}
/**
* Sets the entry's value. If the value is of different type, the type is
* changed to match the new value.
* Sets the entry's value. If the value is of different type, the type is changed to match the new
* value.
*
* @param value the value to set
*/
@@ -669,8 +662,8 @@ public final class NetworkTableEntry {
}
/**
* Sets the entry's value. If the value is of different type, the type is
* changed to match the new value.
* Sets the entry's value. If the value is of different type, the type is changed to match the new
* value.
*
* @param value the value to set
*/
@@ -679,8 +672,8 @@ public final class NetworkTableEntry {
}
/**
* Sets the entry's value. If the value is of different type, the type is
* changed to match the new value.
* Sets the entry's value. If the value is of different type, the type is changed to match the new
* value.
*
* @param value the value to set
*/
@@ -689,8 +682,8 @@ public final class NetworkTableEntry {
}
/**
* Sets the entry's value. If the value is of different type, the type is
* changed to match the new value.
* Sets the entry's value. If the value is of different type, the type is changed to match the new
* value.
*
* @param value the value to set
*/
@@ -699,8 +692,8 @@ public final class NetworkTableEntry {
}
/**
* Sets the entry's value. If the value is of different type, the type is
* changed to match the new value.
* Sets the entry's value. If the value is of different type, the type is changed to match the new
* value.
*
* @param value the value to set
*/
@@ -709,8 +702,8 @@ public final class NetworkTableEntry {
}
/**
* Sets the entry's value. If the value is of different type, the type is
* changed to match the new value.
* Sets the entry's value. If the value is of different type, the type is changed to match the new
* value.
*
* @param value the value to set
*/
@@ -719,8 +712,8 @@ public final class NetworkTableEntry {
}
/**
* Sets the entry's value. If the value is of different type, the type is
* changed to match the new value.
* Sets the entry's value. If the value is of different type, the type is changed to match the new
* value.
*
* @param value the value to set
*/
@@ -729,8 +722,8 @@ public final class NetworkTableEntry {
}
/**
* Sets the entry's value. If the value is of different type, the type is
* changed to match the new value.
* Sets the entry's value. If the value is of different type, the type is changed to match the new
* value.
*
* @param value the value to set
*/
@@ -739,8 +732,8 @@ public final class NetworkTableEntry {
}
/**
* Sets the entry's value. If the value is of different type, the type is
* changed to match the new value.
* Sets the entry's value. If the value is of different type, the type is changed to match the new
* value.
*
* @param value the value to set
*/
@@ -749,8 +742,8 @@ public final class NetworkTableEntry {
}
/**
* Sets the entry's value. If the value is of different type, the type is
* changed to match the new value.
* Sets the entry's value. If the value is of different type, the type is changed to match the new
* value.
*
* @param value the value to set
*/
@@ -776,16 +769,12 @@ public final class NetworkTableEntry {
NetworkTablesJNI.setEntryFlags(m_handle, getFlags() & ~flags);
}
/**
* Make value persistent through program restarts.
*/
/** Make value persistent through program restarts. */
public void setPersistent() {
setFlags(kPersistent);
}
/**
* Stop making value persistent through program restarts.
*/
/** Stop making value persistent through program restarts. */
public void clearPersistent() {
clearFlags(kPersistent);
}
@@ -799,31 +788,28 @@ public final class NetworkTableEntry {
return (getFlags() & kPersistent) != 0;
}
/**
* Deletes the entry.
*/
/** Deletes the entry. */
public void delete() {
NetworkTablesJNI.deleteEntry(m_handle);
}
/**
* Create a callback-based RPC entry point. Only valid to use on the server.
* The callback function will be called when the RPC is called.
* This function creates RPC version 0 definitions (raw data in and out).
* Create a callback-based RPC entry point. Only valid to use on the server. The callback function
* will be called when the RPC is called. This function creates RPC version 0 definitions (raw
* data in and out).
*
* @param callback callback function
* @param callback callback function
*/
public void createRpc(Consumer<RpcAnswer> callback) {
m_inst.createRpc(this, callback);
}
/**
* Call a RPC function. May be used on either the client or server.
* This function is non-blocking. Either {@link RpcCall#getResult()} or
* {@link RpcCall#cancelResult()} must be called on the return value to either
* get or ignore the result of the call.
* Call a RPC function. May be used on either the client or server. This function is non-blocking.
* Either {@link RpcCall#getResult()} or {@link RpcCall#cancelResult()} must be called on the
* return value to either get or ignore the result of the call.
*
* @param params parameter
* @param params parameter
* @return RPC call object.
*/
public RpcCall callRpc(byte[] params) {

View File

@@ -4,9 +4,7 @@
package edu.wpi.first.networktables;
/**
* Network table data types.
*/
/** Network table data types. */
public enum NetworkTableType {
kUnassigned(0),
kBoolean(0x01),
@@ -36,15 +34,24 @@ public enum NetworkTableType {
*/
public static NetworkTableType getFromInt(int value) {
switch (value) {
case 0x01: return kBoolean;
case 0x02: return kDouble;
case 0x04: return kString;
case 0x08: return kRaw;
case 0x10: return kBooleanArray;
case 0x20: return kDoubleArray;
case 0x40: return kStringArray;
case 0x80: return kRpc;
default: return kUnassigned;
case 0x01:
return kBoolean;
case 0x02:
return kDouble;
case 0x04:
return kString;
case 0x08:
return kRaw;
case 0x10:
return kBooleanArray;
case 0x20:
return kDoubleArray;
case 0x40:
return kStringArray;
case 0x80:
return kRpc;
default:
return kUnassigned;
}
}
}

View File

@@ -6,9 +6,7 @@ package edu.wpi.first.networktables;
import java.util.Objects;
/**
* A network table entry value.
*/
/** A network table entry value. */
public final class NetworkTableValue {
NetworkTableValue(NetworkTableType type, Object value, long time) {
m_type = type;

View File

@@ -4,12 +4,11 @@
package edu.wpi.first.networktables;
import edu.wpi.first.wpiutil.RuntimeLoader;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.concurrent.atomic.AtomicBoolean;
import edu.wpi.first.wpiutil.RuntimeLoader;
public final class NetworkTablesJNI {
static boolean libraryLoaded = false;
static RuntimeLoader<NetworkTablesJNI> loader = null;
@@ -29,7 +28,9 @@ public final class NetworkTablesJNI {
static {
if (Helper.getExtractOnStaticLoad()) {
try {
loader = new RuntimeLoader<>("ntcorejni", RuntimeLoader.getDefaultExtractionRoot(), NetworkTablesJNI.class);
loader =
new RuntimeLoader<>(
"ntcorejni", RuntimeLoader.getDefaultExtractionRoot(), NetworkTablesJNI.class);
loader.loadLibrary();
} catch (IOException ex) {
ex.printStackTrace();
@@ -39,58 +40,86 @@ public final class NetworkTablesJNI {
}
}
/**
* Force load the library.
*/
/** Force load the library. */
public static synchronized void forceLoad() throws IOException {
if (libraryLoaded) {
return;
}
loader = new RuntimeLoader<>("ntcorejni", RuntimeLoader.getDefaultExtractionRoot(), NetworkTablesJNI.class);
loader =
new RuntimeLoader<>(
"ntcorejni", RuntimeLoader.getDefaultExtractionRoot(), NetworkTablesJNI.class);
loader.loadLibrary();
libraryLoaded = true;
}
public static native int getDefaultInstance();
public static native int createInstance();
public static native void destroyInstance(int inst);
public static native int getInstanceFromHandle(int handle);
public static native int getEntry(int inst, String key);
public static native int[] getEntries(int inst, String prefix, int types);
public static native String getEntryName(int entry);
public static native long getEntryLastChange(int entry);
public static native int getType(int entry);
public static native boolean setBoolean(int entry, long time, boolean value, boolean force);
public static native boolean setDouble(int entry, long time, double value, boolean force);
public static native boolean setString(int entry, long time, String value, boolean force);
public static native boolean setRaw(int entry, long time, byte[] value, boolean force);
public static native boolean setRaw(int entry, long time, ByteBuffer value, int len, boolean force);
public static native boolean setBooleanArray(int entry, long time, boolean[] value, boolean force);
public static native boolean setRaw(
int entry, long time, ByteBuffer value, int len, boolean force);
public static native boolean setBooleanArray(
int entry, long time, boolean[] value, boolean force);
public static native boolean setDoubleArray(int entry, long time, double[] value, boolean force);
public static native boolean setStringArray(int entry, long time, String[] value, boolean force);
public static native NetworkTableValue getValue(int entry);
public static native boolean getBoolean(int entry, boolean defaultValue);
public static native double getDouble(int entry, double defaultValue);
public static native String getString(int entry, String defaultValue);
public static native byte[] getRaw(int entry, byte[] defaultValue);
public static native boolean[] getBooleanArray(int entry, boolean[] defaultValue);
public static native double[] getDoubleArray(int entry, double[] defaultValue);
public static native String[] getStringArray(int entry, String[] defaultValue);
public static native boolean setDefaultBoolean(int entry, long time, boolean defaultValue);
public static native boolean setDefaultDouble(int entry, long time, double defaultValue);
public static native boolean setDefaultString(int entry, long time, String defaultValue);
public static native boolean setDefaultRaw(int entry, long time, byte[] defaultValue);
public static native boolean setDefaultBooleanArray(int entry, long time, boolean[] defaultValue);
public static native boolean setDefaultDoubleArray(int entry, long time, double[] defaultValue);
public static native boolean setDefaultStringArray(int entry, long time, String[] defaultValue);
public static native void setEntryFlags(int entry, int flags);
public static native int getEntryFlags(int entry);
public static native void deleteEntry(int entry);
@@ -98,58 +127,109 @@ public final class NetworkTablesJNI {
public static native void deleteAllEntries(int inst);
public static native EntryInfo getEntryInfoHandle(NetworkTableInstance inst, int entry);
public static native EntryInfo[] getEntryInfo(NetworkTableInstance instObject, int inst, String prefix, int types);
public static native EntryInfo[] getEntryInfo(
NetworkTableInstance instObject, int inst, String prefix, int types);
public static native int createEntryListenerPoller(int inst);
public static native void destroyEntryListenerPoller(int poller);
public static native int addPolledEntryListener(int poller, String prefix, int flags);
public static native int addPolledEntryListener(int poller, int entry, int flags);
public static native EntryNotification[] pollEntryListener(NetworkTableInstance inst, int poller) throws InterruptedException;
public static native EntryNotification[] pollEntryListenerTimeout(NetworkTableInstance inst, int poller, double timeout) throws InterruptedException;
public static native EntryNotification[] pollEntryListener(NetworkTableInstance inst, int poller)
throws InterruptedException;
public static native EntryNotification[] pollEntryListenerTimeout(
NetworkTableInstance inst, int poller, double timeout) throws InterruptedException;
public static native void cancelPollEntryListener(int poller);
public static native void removeEntryListener(int entryListener);
public static native boolean waitForEntryListenerQueue(int inst, double timeout);
public static native int createConnectionListenerPoller(int inst);
public static native void destroyConnectionListenerPoller(int poller);
public static native int addPolledConnectionListener(int poller, boolean immediateNotify);
public static native ConnectionNotification[] pollConnectionListener(NetworkTableInstance inst, int poller) throws InterruptedException;
public static native ConnectionNotification[] pollConnectionListenerTimeout(NetworkTableInstance inst, int poller, double timeout) throws InterruptedException;
public static native ConnectionNotification[] pollConnectionListener(
NetworkTableInstance inst, int poller) throws InterruptedException;
public static native ConnectionNotification[] pollConnectionListenerTimeout(
NetworkTableInstance inst, int poller, double timeout) throws InterruptedException;
public static native void cancelPollConnectionListener(int poller);
public static native void removeConnectionListener(int connListener);
public static native boolean waitForConnectionListenerQueue(int inst, double timeout);
public static native int createRpcCallPoller(int inst);
public static native void destroyRpcCallPoller(int poller);
public static native void createPolledRpc(int entry, byte[] def, int poller);
public static native RpcAnswer[] pollRpc(NetworkTableInstance inst, int poller) throws InterruptedException;
public static native RpcAnswer[] pollRpcTimeout(NetworkTableInstance inst, int poller, double timeout) throws InterruptedException;
public static native RpcAnswer[] pollRpc(NetworkTableInstance inst, int poller)
throws InterruptedException;
public static native RpcAnswer[] pollRpcTimeout(
NetworkTableInstance inst, int poller, double timeout) throws InterruptedException;
public static native void cancelPollRpc(int poller);
public static native boolean waitForRpcCallQueue(int inst, double timeout);
public static native boolean postRpcResponse(int entry, int call, byte[] result);
public static native int callRpc(int entry, byte[] params);
public static native byte[] getRpcResult(int entry, int call);
public static native byte[] getRpcResult(int entry, int call, double timeout);
public static native void cancelRpcResult(int entry, int call);
public static native byte[] getRpc(int entry, byte[] defaultValue);
public static native void setNetworkIdentity(int inst, String name);
public static native int getNetworkMode(int inst);
public static native void startLocal(int inst);
public static native void stopLocal(int inst);
public static native void startServer(int inst, String persistFilename, String listenAddress, int port);
public static native void startServer(
int inst, String persistFilename, String listenAddress, int port);
public static native void stopServer(int inst);
public static native void startClient(int inst);
public static native void startClient(int inst, String serverName, int port);
public static native void startClient(int inst, String[] serverNames, int[] ports);
public static native void startClientTeam(int inst, int team, int port);
public static native void stopClient(int inst);
public static native void setServer(int inst, String serverName, int port);
public static native void setServer(int inst, String[] serverNames, int[] ports);
public static native void setServerTeam(int inst, int team, int port);
public static native void startDSClient(int inst, int port);
public static native void stopDSClient(int inst);
public static native void setUpdateRate(int inst, double interval);
public static native void flush(int inst);
@@ -159,19 +239,33 @@ public final class NetworkTablesJNI {
public static native boolean isConnected(int inst);
public static native void savePersistent(int inst, String filename) throws PersistentException;
public static native String[] loadPersistent(int inst, String filename) throws PersistentException; // returns warnings
public static native void saveEntries(int inst, String filename, String prefix) throws PersistentException;
public static native String[] loadEntries(int inst, String filename, String prefix) throws PersistentException; // returns warnings
public static native String[] loadPersistent(int inst, String filename)
throws PersistentException; // returns warnings
public static native void saveEntries(int inst, String filename, String prefix)
throws PersistentException;
public static native String[] loadEntries(int inst, String filename, String prefix)
throws PersistentException; // returns warnings
public static native long now();
public static native int createLoggerPoller(int inst);
public static native void destroyLoggerPoller(int poller);
public static native int addPolledLogger(int poller, int minLevel, int maxLevel);
public static native LogMessage[] pollLogger(NetworkTableInstance inst, int poller) throws InterruptedException;
public static native LogMessage[] pollLoggerTimeout(NetworkTableInstance inst, int poller, double timeout) throws InterruptedException;
public static native LogMessage[] pollLogger(NetworkTableInstance inst, int poller)
throws InterruptedException;
public static native LogMessage[] pollLoggerTimeout(
NetworkTableInstance inst, int poller, double timeout) throws InterruptedException;
public static native void cancelPollLogger(int poller);
public static native void removeLogger(int logger);
public static native boolean waitForLoggerQueue(int inst, double timeout);
}

View File

@@ -6,9 +6,7 @@ package edu.wpi.first.networktables;
import java.io.IOException;
/**
* An exception thrown when persistent load/save fails in a {@link NetworkTable}.
*/
/** An exception thrown when persistent load/save fails in a {@link NetworkTable}. */
public final class PersistentException extends IOException {
public static final long serialVersionUID = 0;

View File

@@ -4,9 +4,7 @@
package edu.wpi.first.networktables;
/**
* NetworkTables Remote Procedure Call (Server Side).
*/
/** NetworkTables Remote Procedure Call (Server Side). */
public final class RpcAnswer {
/** Entry handle. */
@SuppressWarnings("MemberName")
@@ -28,8 +26,8 @@ public final class RpcAnswer {
@SuppressWarnings("MemberName")
public final ConnectionInfo conn;
/** Constructor.
* This should generally only be used internally to NetworkTables.
/**
* Constructor. This should generally only be used internally to NetworkTables.
*
* @param inst Instance
* @param entry Entry handle
@@ -38,8 +36,13 @@ public final class RpcAnswer {
* @param params Call raw parameters
* @param conn Connection info
*/
public RpcAnswer(NetworkTableInstance inst, int entry, int call, String name, byte[] params,
ConnectionInfo conn) {
public RpcAnswer(
NetworkTableInstance inst,
int entry,
int call,
String name,
byte[] params,
ConnectionInfo conn) {
this.m_inst = inst;
this.entry = entry;
this.call = call;
@@ -73,8 +76,8 @@ public final class RpcAnswer {
/**
* Post RPC response (return value) for a polled RPC.
*
* @param result result raw data that will be provided to remote caller
* @return true if the response was posted, otherwise false
* @param result result raw data that will be provided to remote caller
* @return true if the response was posted, otherwise false
*/
public boolean postResponse(byte[] result) {
boolean ret = NetworkTablesJNI.postRpcResponse(entry, call, result);

View File

@@ -4,12 +4,10 @@
package edu.wpi.first.networktables;
/**
* NetworkTables Remote Procedure Call.
*/
/** NetworkTables Remote Procedure Call. */
public final class RpcCall implements AutoCloseable {
/** Constructor.
* This should generally only be used internally to NetworkTables.
/**
* Constructor. This should generally only be used internally to NetworkTables.
*
* @param entry Entry
* @param call Call handle
@@ -19,9 +17,7 @@ public final class RpcCall implements AutoCloseable {
m_call = call;
}
/**
* Cancels the result if no other action taken.
*/
/** Cancels the result if no other action taken. */
@Override
public synchronized void close() {
if (m_call != 0) {
@@ -57,8 +53,7 @@ public final class RpcCall implements AutoCloseable {
}
/**
* Get the result (return value). This function blocks until
* the result is received.
* Get the result (return value). This function blocks until the result is received.
*
* @return Received result (output)
*/
@@ -71,10 +66,10 @@ public final class RpcCall implements AutoCloseable {
}
/**
* Get the result (return value). This function blocks until
* the result is received or it times out.
* Get the result (return value). This function blocks until the result is received or it times
* out.
*
* @param timeout timeout, in seconds
* @param timeout timeout, in seconds
* @return Received result (output)
*/
public byte[] getResult(double timeout) {
@@ -85,9 +80,7 @@ public final class RpcCall implements AutoCloseable {
return result;
}
/**
* Ignore the result. This function is non-blocking.
*/
/** Ignore the result. This function is non-blocking. */
public void cancelResult() {
NetworkTablesJNI.cancelRpcResult(m_entry.getHandle(), m_call);
}

View File

@@ -4,9 +4,7 @@
package edu.wpi.first.networktables;
/**
* A listener that listens to changes in values in a {@link NetworkTable}.
*/
/** A listener that listens to changes in values in a {@link NetworkTable}. */
@FunctionalInterface
public interface TableEntryListener extends EntryListenerFlags {
/**
@@ -16,9 +14,9 @@ public interface TableEntryListener extends EntryListenerFlags {
* @param key the key associated with the value that changed
* @param entry the entry associated with the value that changed
* @param value the new value
* @param flags update flags; for example, EntryListenerFlags.kNew if the key
* did not previously exist in the table
* @param flags update flags; for example, EntryListenerFlags.kNew if the key did not previously
* exist in the table
*/
void valueChanged(NetworkTable table, String key, NetworkTableEntry entry,
NetworkTableValue value, int flags);
void valueChanged(
NetworkTable table, String key, NetworkTableEntry entry, NetworkTableValue value, int flags);
}

View File

@@ -4,9 +4,7 @@
package edu.wpi.first.networktables;
/**
* A listener that listens to new tables in a {@link NetworkTable}.
*/
/** A listener that listens to new tables in a {@link NetworkTable}. */
@FunctionalInterface
public interface TableListener {
/**

View File

@@ -4,9 +4,9 @@
package edu.wpi.first.wpilibj.tables;
/**
* Represents an object that has a remote connection.
*
* @deprecated Use {@link edu.wpi.first.networktables.NetworkTableInstance}.
*/
@Deprecated
@@ -16,7 +16,8 @@ public interface IRemote {
* Register an object to listen for connection and disconnection events
*
* @param listener the listener to be register
* @param immediateNotify if the listener object should be notified of the current connection state
* @param immediateNotify if the listener object should be notified of the current connection
* state
*/
public void addConnectionListener(IRemoteConnectionListener listener, boolean immediateNotify);
@@ -29,13 +30,15 @@ public interface IRemote {
/**
* Get the current state of the objects connection
*
* @return the current connection state
*/
public boolean isConnected();
public boolean isConnected();
/**
* If the object is acting as a server
*
* @return if the object is a server
*/
public boolean isServer();
public boolean isServer();
}

View File

@@ -8,6 +8,7 @@ import edu.wpi.first.networktables.ConnectionInfo;
/**
* A listener that listens for connection changes in a {@link IRemote} object.
*
* @deprecated Use Consumer&lt;{@link edu.wpi.first.networktables.ConnectionNotification}&gt;.
*/
@Deprecated
@@ -15,30 +16,34 @@ import edu.wpi.first.networktables.ConnectionInfo;
public interface IRemoteConnectionListener {
/**
* Called when an IRemote is connected
*
* @param remote the object that connected
*/
public void connected(IRemote remote);
/**
* Called when an IRemote is disconnected
*
* @param remote the object that disconnected
*/
public void disconnected(IRemote remote);
/**
* Extended version of connected called when an IRemote is connected.
* Contains the connection info of the connected remote
* Extended version of connected called when an IRemote is connected. Contains the connection info
* of the connected remote
*
* @param remote the object that connected
* @param info the connection info for the connected remote
*/
default public void connectedEx(IRemote remote, ConnectionInfo info) {
public default void connectedEx(IRemote remote, ConnectionInfo info) {
connected(remote);
}
/**
* Extended version of connected called when an IRemote is disconnected.
* Contains the connection info of the disconnected remote
* Extended version of connected called when an IRemote is disconnected. Contains the connection
* info of the disconnected remote
*
* @param remote the object that disconnected
* @param info the connection info for the disconnected remote
*/
default public void disconnectedEx(IRemote remote, ConnectionInfo info) {
public default void disconnectedEx(IRemote remote, ConnectionInfo info) {
disconnected(remote);
}
}

View File

@@ -7,9 +7,9 @@ package edu.wpi.first.wpilibj.tables;
import java.nio.ByteBuffer;
import java.util.Set;
/**
* A table whose values can be read and written to.
*
* @deprecated Use {@link edu.wpi.first.networktables.NetworkTable}.
*/
@Deprecated
@@ -26,14 +26,14 @@ public interface ITable {
/**
* @param key the key to search for
* @return true if there is a subtable with the key which contains at least
* one key/subtable of its own
* @return true if there is a subtable with the key which contains at least one key/subtable of
* its own
*/
public boolean containsSubTable(String key);
/**
* Returns the table at the specified key. If there is no table at the
* specified key, it will create a new table
* Returns the table at the specified key. If there is no table at the specified key, it will
* create a new table
*
* @param key the name of the table relative to this one
* @return a sub table relative to this one
@@ -42,6 +42,7 @@ public interface ITable {
/**
* Gets all keys in the table (not including sub-tables).
*
* @param types bitmask of types; 0 is treated as a "don't care".
* @return keys currently in the table
*/
@@ -49,35 +50,34 @@ public interface ITable {
/**
* Gets all keys in the table (not including sub-tables).
*
* @return keys currently in the table
*/
public Set<String> getKeys();
/**
* Gets the names of all subtables in the table.
*
* @return subtables currently in the table
*/
public Set<String> getSubTables();
/**
* Makes a key's value persistent through program restarts.
* The key cannot be null.
* Makes a key's value persistent through program restarts. The key cannot be null.
*
* @param key the key name
*/
public void setPersistent(String key);
/**
* Stop making a key's value persistent through program restarts.
* The key cannot be null.
* Stop making a key's value persistent through program restarts. The key cannot be null.
*
* @param key the key name
*/
public void clearPersistent(String key);
/**
* Returns whether the value is persistent through program restarts.
* The key cannot be null.
* Returns whether the value is persistent through program restarts. The key cannot be null.
*
* @param key the key name
* @return True if the value is persistent.
@@ -85,8 +85,7 @@ public interface ITable {
public boolean isPersistent(String key);
/**
* Sets flags on the specified key in this table. The key can
* not be null.
* Sets flags on the specified key in this table. The key can not be null.
*
* @param key the key name
* @param flags the flags to set (bitmask)
@@ -94,8 +93,7 @@ public interface ITable {
public void setFlags(String key, int flags);
/**
* Clears flags on the specified key in this table. The key can
* not be null.
* Clears flags on the specified key in this table. The key can not be null.
*
* @param key the key name
* @param flags the flags to clear (bitmask)
@@ -111,18 +109,17 @@ public interface ITable {
public int getFlags(String key);
/**
* Deletes the specified key in this table. The key can
* not be null.
* Deletes the specified key in this table. The key can not be null.
*
* @param key the key name
*/
public void delete(String key);
/**
* Gets the value associated with a key as an object.
* NOTE: If the value is a double, it will return a Double object,
* not a primitive. To get the primitive, use
* {@link #getDouble(String, double)}.
* Gets the value associated with a key as an object. NOTE: If the value is a double, it will
* return a Double object, not a primitive. To get the primitive, use {@link #getDouble(String,
* double)}.
*
* @param key the key of the value to look up
* @param defaultValue the default value if the key is null
* @return the value associated with the given key
@@ -131,17 +128,17 @@ public interface ITable {
/**
* Put a value in the table
*
* @param key the key to be assigned to
* @param value the value that will be assigned
* @return False if the table key already exists with a different type
* @throws IllegalArgumentException when the value is not supported by the
* table
* @throws IllegalArgumentException when the value is not supported by the table
*/
public boolean putValue(String key, Object value)
throws IllegalArgumentException;
public boolean putValue(String key, Object value) throws IllegalArgumentException;
/**
* Put a number in the table
*
* @param key the key to be assigned to
* @param value the value that will be assigned
* @return False if the table key already exists with a different type
@@ -150,6 +147,7 @@ public interface ITable {
/**
* Gets the current value in the table, setting it if it does not exist.
*
* @param key the key
* @param defaultValue the default value to set if key doens't exist.
* @return False if the table key exists with a different type
@@ -157,17 +155,19 @@ public interface ITable {
public boolean setDefaultNumber(String key, double defaultValue);
/**
* Returns the number the key maps to. If the key does not exist or is of
* different type, it will return the default value.
* Returns the number the key maps to. If the key does not exist or is of different type, it will
* return the default value.
*
* @param key the key to look up
* @param defaultValue the value to be returned if no value is found
* @return the value associated with the given key or the given default value
* if there is no value associated with the key
* @return the value associated with the given key or the given default value if there is no value
* associated with the key
*/
public double getNumber(String key, double defaultValue);
/**
* Put a string in the table
*
* @param key the key to be assigned to
* @param value the value that will be assigned
* @return False if the table key already exists with a different type
@@ -176,6 +176,7 @@ public interface ITable {
/**
* Gets the current value in the table, setting it if it does not exist.
*
* @param key the key
* @param defaultValue the default value to set if key doens't exist.
* @return False if the table key exists with a different type
@@ -183,17 +184,19 @@ public interface ITable {
public boolean setDefaultString(String key, String defaultValue);
/**
* Returns the string the key maps to. If the key does not exist or is of
* different type, it will return the default value.
* Returns the string the key maps to. If the key does not exist or is of different type, it will
* return the default value.
*
* @param key the key to look up
* @param defaultValue the value to be returned if no value is found
* @return the value associated with the given key or the given default value
* if there is no value associated with the key
* @return the value associated with the given key or the given default value if there is no value
* associated with the key
*/
public String getString(String key, String defaultValue);
/**
* Put a boolean in the table
*
* @param key the key to be assigned to
* @param value the value that will be assigned
* @return False if the table key already exists with a different type
@@ -202,6 +205,7 @@ public interface ITable {
/**
* Gets the current value in the table, setting it if it does not exist.
*
* @param key the key
* @param defaultValue the default value to set if key doens't exist.
* @return False if the table key exists with a different type
@@ -209,17 +213,19 @@ public interface ITable {
public boolean setDefaultBoolean(String key, boolean defaultValue);
/**
* Returns the boolean the key maps to. If the key does not exist or is of
* different type, it will return the default value.
* Returns the boolean the key maps to. If the key does not exist or is of different type, it will
* return the default value.
*
* @param key the key to look up
* @param defaultValue the value to be returned if no value is found
* @return the value associated with the given key or the given default value
* if there is no value associated with the key
* @return the value associated with the given key or the given default value if there is no value
* associated with the key
*/
public boolean getBoolean(String key, boolean defaultValue);
/**
* Put a boolean array in the table
*
* @param key the key to be assigned to
* @param value the value that will be assigned
* @return False if the table key already exists with a different type
@@ -228,6 +234,7 @@ public interface ITable {
/**
* Gets the current value in the table, setting it if it does not exist.
*
* @param key the key
* @param defaultValue the default value to set if key doens't exist.
* @return False if the table key exists with a different type
@@ -236,6 +243,7 @@ public interface ITable {
/**
* Put a boolean array in the table
*
* @param key the key to be assigned to
* @param value the value that will be assigned
* @return False if the table key already exists with a different type
@@ -244,6 +252,7 @@ public interface ITable {
/**
* Gets the current value in the table, setting it if it does not exist.
*
* @param key the key
* @param defaultValue the default value to set if key doens't exist.
* @return False if the table key exists with a different type
@@ -251,26 +260,29 @@ public interface ITable {
public boolean setDefaultBooleanArray(String key, Boolean[] defaultValue);
/**
* Returns the boolean array the key maps to. If the key does not exist or is
* of different type, it will return the default value.
* Returns the boolean array the key maps to. If the key does not exist or is of different type,
* it will return the default value.
*
* @param key the key to look up
* @param defaultValue the value to be returned if no value is found
* @return the value associated with the given key or the given default value
* if there is no value associated with the key
* @return the value associated with the given key or the given default value if there is no value
* associated with the key
*/
public boolean[] getBooleanArray(String key, boolean[] defaultValue);
/**
* Returns the boolean array the key maps to. If the key does not exist or is
* of different type, it will return the default value.
* Returns the boolean array the key maps to. If the key does not exist or is of different type,
* it will return the default value.
*
* @param key the key to look up
* @param defaultValue the value to be returned if no value is found
* @return the value associated with the given key or the given default value
* if there is no value associated with the key
* @return the value associated with the given key or the given default value if there is no value
* associated with the key
*/
public Boolean[] getBooleanArray(String key, Boolean[] defaultValue);
/**
* Put a number array in the table
*
* @param key the key to be assigned to
* @param value the value that will be assigned
* @return False if the table key already exists with a different type
@@ -279,6 +291,7 @@ public interface ITable {
/**
* Gets the current value in the table, setting it if it does not exist.
*
* @param key the key
* @param defaultValue the default value to set if key doens't exist.
* @return False if the table key exists with a different type
@@ -287,6 +300,7 @@ public interface ITable {
/**
* Put a number array in the table
*
* @param key the key to be assigned to
* @param value the value that will be assigned
* @return False if the table key already exists with a different type
@@ -295,6 +309,7 @@ public interface ITable {
/**
* Gets the current value in the table, setting it if it does not exist.
*
* @param key the key
* @param defaultValue the default value to set if key doens't exist.
* @return False if the table key exists with a different type
@@ -302,26 +317,29 @@ public interface ITable {
public boolean setDefaultNumberArray(String key, Double[] defaultValue);
/**
* Returns the number array the key maps to. If the key does not exist or is
* of different type, it will return the default value.
* Returns the number array the key maps to. If the key does not exist or is of different type, it
* will return the default value.
*
* @param key the key to look up
* @param defaultValue the value to be returned if no value is found
* @return the value associated with the given key or the given default value
* if there is no value associated with the key
* @return the value associated with the given key or the given default value if there is no value
* associated with the key
*/
public double[] getNumberArray(String key, double[] defaultValue);
/**
* Returns the number array the key maps to. If the key does not exist or is
* of different type, it will return the default value.
* Returns the number array the key maps to. If the key does not exist or is of different type, it
* will return the default value.
*
* @param key the key to look up
* @param defaultValue the value to be returned if no value is found
* @return the value associated with the given key or the given default value
* if there is no value associated with the key
* @return the value associated with the given key or the given default value if there is no value
* associated with the key
*/
public Double[] getNumberArray(String key, Double[] defaultValue);
/**
* Put a string array in the table
*
* @param key the key to be assigned to
* @param value the value that will be assigned
* @return False if the table key already exists with a different type
@@ -330,6 +348,7 @@ public interface ITable {
/**
* Gets the current value in the table, setting it if it does not exist.
*
* @param key the key
* @param defaultValue the default value to set if key doens't exist.
* @return False if the table key exists with a different type
@@ -337,17 +356,19 @@ public interface ITable {
public boolean setDefaultStringArray(String key, String[] defaultValue);
/**
* Returns the string array the key maps to. If the key does not exist or is
* of different type, it will return the default value.
* Returns the string array the key maps to. If the key does not exist or is of different type, it
* will return the default value.
*
* @param key the key to look up
* @param defaultValue the value to be returned if no value is found
* @return the value associated with the given key or the given default value
* if there is no value associated with the key
* @return the value associated with the given key or the given default value if there is no value
* associated with the key
*/
public String[] getStringArray(String key, String[] defaultValue);
/**
* Put a raw value (byte array) in the table
*
* @param key the key to be assigned to
* @param value the value that will be assigned
* @return False if the table key already exists with a different type
@@ -356,6 +377,7 @@ public interface ITable {
/**
* Gets the current value in the table, setting it if it does not exist.
*
* @param key the key
* @param defaultValue the default value to set if key doens't exist.
* @return False if the table key exists with a different type
@@ -364,6 +386,7 @@ public interface ITable {
/**
* Put a raw value (bytes from a byte buffer) in the table
*
* @param key the key to be assigned to
* @param value the value that will be assigned
* @param len the length of the value
@@ -372,17 +395,19 @@ public interface ITable {
public boolean putRaw(String key, ByteBuffer value, int len);
/**
* Returns the raw value (byte array) the key maps to. If the key does not
* exist or is of different type, it will return the default value.
* Returns the raw value (byte array) the key maps to. If the key does not exist or is of
* different type, it will return the default value.
*
* @param key the key to look up
* @param defaultValue the value to be returned if no value is found
* @return the value associated with the given key or the given default value
* if there is no value associated with the key
* @return the value associated with the given key or the given default value if there is no value
* associated with the key
*/
public byte[] getRaw(String key, byte[] defaultValue);
/** Notifier flag values. */
public static final int NOTIFY_IMMEDIATE = 0x01;
public static final int NOTIFY_LOCAL = 0x02;
public static final int NOTIFY_NEW = 0x04;
public static final int NOTIFY_DELETE = 0x08;
@@ -391,19 +416,21 @@ public interface ITable {
/**
* Add a listener for changes to the table
*
* @param listener the listener to add
*/
public void addTableListener(ITableListener listener);
/**
* Add a listener for changes to the table
*
* @param listener the listener to add
* @param immediateNotify if true then this listener will be notified of all
* current entries (marked as new)
* @param immediateNotify if true then this listener will be notified of all current entries
* (marked as new)
*/
public void addTableListener(ITableListener listener,
boolean immediateNotify);
public void addTableListener(ITableListener listener, boolean immediateNotify);
/**
* Add a listener for changes to the table
*
* @param listener the listener to add
* @param flags bitmask specifying desired notifications
*/
@@ -411,36 +438,38 @@ public interface ITable {
/**
* Add a listener for changes to a specific key the table
*
* @param key the key to listen for
* @param listener the listener to add
* @param immediateNotify if true then this listener will be notified of all
* current entries (marked as new)
* @param immediateNotify if true then this listener will be notified of all current entries
* (marked as new)
*/
public void addTableListener(String key, ITableListener listener,
boolean immediateNotify);
public void addTableListener(String key, ITableListener listener, boolean immediateNotify);
/**
* Add a listener for changes to a specific key the table
*
* @param key the key to listen for
* @param listener the listener to add
* @param flags bitmask specifying desired notifications
*/
public void addTableListenerEx(String key, ITableListener listener,
int flags);
public void addTableListenerEx(String key, ITableListener listener, int flags);
/**
* This will immediately notify the listener of all current sub tables
*
* @param listener the listener to notify
*/
public void addSubTableListener(final ITableListener listener);
/**
* This will immediately notify the listener of all current sub tables
*
* @param listener the listener to notify
* @param localNotify if true then this listener will be notified of all
* local changes in addition to all remote changes
* @param localNotify if true then this listener will be notified of all local changes in addition
* to all remote changes
*/
public void addSubTableListener(final ITableListener listener,
boolean localNotify);
public void addSubTableListener(final ITableListener listener, boolean localNotify);
/**
* Remove a listener from receiving table events
*
* @param listener the listener to be removed
*/
public void removeTableListener(ITableListener listener);
@@ -450,10 +479,9 @@ public interface ITable {
*/
/**
* Maps the specified key to the specified value in this table.
* The key can not be null.
* The value can be retrieved by calling the get method with a key that is
* equal to the original key.
* Maps the specified key to the specified value in this table. The key can not be null. The value
* can be retrieved by calling the get method with a key that is equal to the original key.
*
* @param key the key
* @param value the value
* @return False if the table key already exists with a different type
@@ -465,11 +493,11 @@ public interface ITable {
/**
* Returns the value at the specified key.
*
* @param key the key
* @param defaultValue the value returned if the key is undefined
* @return the value
* @throws IllegalArgumentException if the value mapped to by the key is not a
* double
* @throws IllegalArgumentException if the value mapped to by the key is not a double
* @throws IllegalArgumentException if the key is null
* @deprecated Use {@link #getNumber(String, double)} instead.
*/
@@ -477,9 +505,9 @@ public interface ITable {
public double getDouble(String key, double defaultValue);
/**
* Gets the full path of this table. Does not include the trailing "/".
* Gets the full path of this table. Does not include the trailing "/".
*
* @return The path to this table (e.g. "", "/foo").
*/
public String getPath();
}

View File

@@ -6,36 +6,38 @@ package edu.wpi.first.wpilibj.tables;
/**
* A listener that listens to changes in values in a {@link ITable}.
* @deprecated Use Consumer&lt;{@link edu.wpi.first.networktables.EntryNotification}&gt;,
* {@link edu.wpi.first.networktables.TableEntryListener}, or
* {@link edu.wpi.first.networktables.TableListener} as appropriate.
*
* @deprecated Use Consumer&lt;{@link edu.wpi.first.networktables.EntryNotification}&gt;, {@link
* edu.wpi.first.networktables.TableEntryListener}, or {@link
* edu.wpi.first.networktables.TableListener} as appropriate.
*/
@FunctionalInterface
@Deprecated
@SuppressWarnings("checkstyle:all")
public interface ITableListener {
/**
* Called when a key-value pair is changed in a {@link ITable}
* @param source the table the key-value pair exists in
* @param key the key associated with the value that changed
* @param value the new value
* @param isNew true if the key did not previously exist in the table, otherwise it is false
*/
public void valueChanged(ITable source, String key, Object value, boolean isNew);
/**
* Called when a key-value pair is changed in a {@link ITable}
*
* @param source the table the key-value pair exists in
* @param key the key associated with the value that changed
* @param value the new value
* @param isNew true if the key did not previously exist in the table, otherwise it is false
*/
public void valueChanged(ITable source, String key, Object value, boolean isNew);
/**
* Extended version of valueChanged. Called when a key-value pair is
* changed in a {@link ITable}. The default implementation simply calls
* valueChanged(). If this is overridden, valueChanged() will not be
* called.
* @param source the table the key-value pair exists in
* @param key the key associated with the value that changed
* @param value the new value
* @param flags update flags; for example, NOTIFY_NEW if the key did not
* previously exist in the table
*/
default public void valueChangedEx(ITable source, String key, Object value, int flags) {
// NOTIFY_NEW = 0x04
valueChanged(source, key, value, (flags & 0x04) != 0);
}
/**
* Extended version of valueChanged. Called when a key-value pair is changed in a {@link ITable}.
* The default implementation simply calls valueChanged(). If this is overridden, valueChanged()
* will not be called.
*
* @param source the table the key-value pair exists in
* @param key the key associated with the value that changed
* @param value the new value
* @param flags update flags; for example, NOTIFY_NEW if the key did not previously exist in the
* table
*/
public default void valueChangedEx(ITable source, String key, Object value, int flags) {
// NOTIFY_NEW = 0x04
valueChanged(source, key, value, (flags & 0x04) != 0);
}
}

View File

@@ -4,17 +4,6 @@
package edu.wpi.first.networktables;
import java.util.ArrayList;
import java.util.List;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.OS;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -22,6 +11,16 @@ import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import java.util.ArrayList;
import java.util.List;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.OS;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
class ConnectionListenerTest {
private NetworkTableInstance m_serverInst;
private NetworkTableInstance m_clientInst;
@@ -41,9 +40,7 @@ class ConnectionListenerTest {
m_serverInst.close();
}
/**
* Connect to the server.
*/
/** Connect to the server. */
@SuppressWarnings("PMD.AvoidUsingHardCodedIP")
private void connect() {
m_serverInst.startServer("connectionlistenertest.ini", "127.0.0.1", 10000);
@@ -108,13 +105,12 @@ class ConnectionListenerTest {
assertEquals(1, events.length);
assertEquals(handle, events[0].listener);
assertFalse(events[0].connected);
}
@ParameterizedTest
@DisabledOnOs(OS.WINDOWS)
@SuppressWarnings("PMD.AvoidUsingHardCodedIP")
@ValueSource(strings = { "127.0.0.1", "127.0.0.1 ", " 127.0.0.1 " })
@ValueSource(strings = {"127.0.0.1", "127.0.0.1 ", " 127.0.0.1 "})
void testThreaded(String address) {
m_serverInst.startServer("connectionlistenertest.ini", address, 10000);
List<ConnectionNotification> events = new ArrayList<>();

View File

@@ -4,18 +4,17 @@
package edu.wpi.first.networktables;
import java.util.ArrayList;
import java.util.List;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import java.util.ArrayList;
import java.util.List;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
class EntryListenerTest {
private NetworkTableInstance m_serverInst;
private NetworkTableInstance m_clientInst;
@@ -53,15 +52,12 @@ class EntryListenerTest {
}
}
/**
* Test prefix with a new remote.
*/
/** Test prefix with a new remote. */
@Test
void testPrefixNewRemote() {
connect();
List<EntryNotification> events = new ArrayList<>();
final int handle = m_serverInst.addEntryListener("/foo", events::add,
EntryListenerFlags.kNew);
final int handle = m_serverInst.addEntryListener("/foo", events::add, EntryListenerFlags.kNew);
// Trigger an event
m_clientInst.getEntry("/foo/bar").setDouble(1.0);
@@ -76,13 +72,13 @@ class EntryListenerTest {
assertTrue(m_serverInst.waitForEntryListenerQueue(1.0));
// Check the event
assertAll("Event",
assertAll(
"Event",
() -> assertEquals(1, events.size()),
() -> assertEquals(handle, events.get(0).listener),
() -> assertEquals(m_serverInst.getEntry("/foo/bar"), events.get(0).getEntry()),
() -> assertEquals("/foo/bar", events.get(0).name),
() -> assertEquals(NetworkTableValue.makeDouble(1.0), events.get(0).value),
() -> assertEquals(EntryListenerFlags.kNew, events.get(0).flags)
);
() -> assertEquals(EntryListenerFlags.kNew, events.get(0).flags));
}
}

View File

@@ -4,16 +4,15 @@
package edu.wpi.first.networktables;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.fail;
import java.util.ArrayList;
import java.util.List;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.fail;
class LoggerTest {
private NetworkTableInstance m_clientInst;

View File

@@ -4,24 +4,22 @@
package edu.wpi.first.networktables;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Stream;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import static org.junit.jupiter.api.Assertions.assertEquals;
class NetworkTableTest {
private static Stream<Arguments> basenameKeyArguments() {
return Stream.of(
Arguments.of("simple", "simple"),
Arguments.of("simple", "one/two/many/simple"),
Arguments.of("simple", "//////an/////awful/key////simple")
);
Arguments.of("simple", "//////an/////awful/key////simple"));
}
@ParameterizedTest
@@ -35,8 +33,7 @@ class NetworkTableTest {
Arguments.of("/", "///"),
Arguments.of("/no/normal/req", "/no/normal/req"),
Arguments.of("/no/leading/slash", "no/leading/slash"),
Arguments.of("/what/an/awful/key/", "//////what////an/awful/////key///")
);
Arguments.of("/what/an/awful/key/", "//////what////an/awful/////key///"));
}
@ParameterizedTest
@@ -51,8 +48,7 @@ class NetworkTableTest {
Arguments.of("a", "///a"),
Arguments.of("leading/slash", "/leading/slash"),
Arguments.of("no/leading/slash", "no/leading/slash"),
Arguments.of("what/an/awful/key/", "//////what////an/awful/////key///")
);
Arguments.of("what/an/awful/key/", "//////what////an/awful/////key///"));
}
@ParameterizedTest
@@ -66,8 +62,7 @@ class NetworkTableTest {
Arguments.of(Collections.singletonList("/"), ""),
Arguments.of(Collections.singletonList("/"), "/"),
Arguments.of(Arrays.asList("/", "/foo", "/foo/bar", "/foo/bar/baz"), "/foo/bar/baz"),
Arguments.of(Arrays.asList("/", "/foo", "/foo/bar", "/foo/bar/"), "/foo/bar/")
);
Arguments.of(Arrays.asList("/", "/foo", "/foo/bar", "/foo/bar/"), "/foo/bar/"));
}
@ParameterizedTest