mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-28 02:11:43 +00:00
Clean up Java style (#5990)
Also make equivalent changes in C++ where applicable. Co-authored-by: Sriman Achanta <68172138+srimanachanta@users.noreply.github.com>
This commit is contained in:
@@ -574,7 +574,7 @@ public final class NetworkTable {
|
||||
return m_inst.addListener(
|
||||
new String[] {m_pathWithSep},
|
||||
EnumSet.of(NetworkTableEvent.Kind.kPublish, NetworkTableEvent.Kind.kImmediate),
|
||||
new Consumer<NetworkTableEvent>() {
|
||||
new Consumer<>() {
|
||||
final Set<String> m_notifiedTables = new HashSet<>();
|
||||
|
||||
@Override
|
||||
|
||||
@@ -190,14 +190,14 @@ final class ProtobufEntryImpl<T> extends EntryBase implements ProtobufEntry<T> {
|
||||
|
||||
private TimestampedObject<T> fromRaw(TimestampedRaw raw, T defaultValue) {
|
||||
if (raw.value.length == 0) {
|
||||
return new TimestampedObject<T>(0, 0, defaultValue);
|
||||
return new TimestampedObject<>(0, 0, defaultValue);
|
||||
}
|
||||
try {
|
||||
synchronized (m_buf) {
|
||||
return new TimestampedObject<T>(raw.timestamp, raw.serverTime, m_buf.read(raw.value));
|
||||
return new TimestampedObject<>(raw.timestamp, raw.serverTime, m_buf.read(raw.value));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
return new TimestampedObject<T>(0, 0, defaultValue);
|
||||
return new TimestampedObject<>(0, 0, defaultValue);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ public final class ProtobufTopic<T> extends Topic {
|
||||
* @return ProtobufTopic for value class
|
||||
*/
|
||||
public static <T> ProtobufTopic<T> wrap(Topic topic, Protobuf<T, ?> proto) {
|
||||
return new ProtobufTopic<T>(topic, proto);
|
||||
return new ProtobufTopic<>(topic, proto);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -47,7 +47,7 @@ public final class ProtobufTopic<T> extends Topic {
|
||||
*/
|
||||
public static <T> ProtobufTopic<T> wrap(
|
||||
NetworkTableInstance inst, int handle, Protobuf<T, ?> proto) {
|
||||
return new ProtobufTopic<T>(inst, handle, proto);
|
||||
return new ProtobufTopic<>(inst, handle, proto);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,7 +63,7 @@ public final class ProtobufTopic<T> extends Topic {
|
||||
* @return subscriber
|
||||
*/
|
||||
public ProtobufSubscriber<T> subscribe(T defaultValue, PubSubOption... options) {
|
||||
return new ProtobufEntryImpl<T>(
|
||||
return new ProtobufEntryImpl<>(
|
||||
this,
|
||||
ProtobufBuffer.create(m_proto),
|
||||
NetworkTablesJNI.subscribe(
|
||||
@@ -87,7 +87,7 @@ public final class ProtobufTopic<T> extends Topic {
|
||||
*/
|
||||
public ProtobufPublisher<T> publish(PubSubOption... options) {
|
||||
m_inst.addSchema(m_proto);
|
||||
return new ProtobufEntryImpl<T>(
|
||||
return new ProtobufEntryImpl<>(
|
||||
this,
|
||||
ProtobufBuffer.create(m_proto),
|
||||
NetworkTablesJNI.publish(
|
||||
@@ -113,7 +113,7 @@ public final class ProtobufTopic<T> extends Topic {
|
||||
*/
|
||||
public ProtobufPublisher<T> publishEx(String properties, PubSubOption... options) {
|
||||
m_inst.addSchema(m_proto);
|
||||
return new ProtobufEntryImpl<T>(
|
||||
return new ProtobufEntryImpl<>(
|
||||
this,
|
||||
ProtobufBuffer.create(m_proto),
|
||||
NetworkTablesJNI.publishEx(
|
||||
@@ -144,7 +144,7 @@ public final class ProtobufTopic<T> extends Topic {
|
||||
* @return entry
|
||||
*/
|
||||
public ProtobufEntry<T> getEntry(T defaultValue, PubSubOption... options) {
|
||||
return new ProtobufEntryImpl<T>(
|
||||
return new ProtobufEntryImpl<>(
|
||||
this,
|
||||
ProtobufBuffer.create(m_proto),
|
||||
NetworkTablesJNI.getEntry(
|
||||
|
||||
@@ -177,15 +177,14 @@ final class StructArrayEntryImpl<T> extends EntryBase implements StructArrayEntr
|
||||
@SuppressWarnings("PMD.AvoidCatchingGenericException")
|
||||
private TimestampedObject<T[]> fromRaw(TimestampedRaw raw, T[] defaultValue) {
|
||||
if (raw.value.length == 0) {
|
||||
return new TimestampedObject<T[]>(0, 0, defaultValue);
|
||||
return new TimestampedObject<>(0, 0, defaultValue);
|
||||
}
|
||||
try {
|
||||
synchronized (m_buf) {
|
||||
return new TimestampedObject<T[]>(
|
||||
raw.timestamp, raw.serverTime, m_buf.readArray(raw.value));
|
||||
return new TimestampedObject<>(raw.timestamp, raw.serverTime, m_buf.readArray(raw.value));
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
return new TimestampedObject<T[]>(0, 0, defaultValue);
|
||||
return new TimestampedObject<>(0, 0, defaultValue);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ public final class StructArrayTopic<T> extends Topic {
|
||||
* @return StructArrayTopic for value class
|
||||
*/
|
||||
public static <T> StructArrayTopic<T> wrap(Topic topic, Struct<T> struct) {
|
||||
return new StructArrayTopic<T>(topic, struct);
|
||||
return new StructArrayTopic<>(topic, struct);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -47,7 +47,7 @@ public final class StructArrayTopic<T> extends Topic {
|
||||
*/
|
||||
public static <T> StructArrayTopic<T> wrap(
|
||||
NetworkTableInstance inst, int handle, Struct<T> struct) {
|
||||
return new StructArrayTopic<T>(inst, handle, struct);
|
||||
return new StructArrayTopic<>(inst, handle, struct);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,7 +63,7 @@ public final class StructArrayTopic<T> extends Topic {
|
||||
* @return subscriber
|
||||
*/
|
||||
public StructArraySubscriber<T> subscribe(T[] defaultValue, PubSubOption... options) {
|
||||
return new StructArrayEntryImpl<T>(
|
||||
return new StructArrayEntryImpl<>(
|
||||
this,
|
||||
StructBuffer.create(m_struct),
|
||||
NetworkTablesJNI.subscribe(
|
||||
@@ -87,7 +87,7 @@ public final class StructArrayTopic<T> extends Topic {
|
||||
*/
|
||||
public StructArrayPublisher<T> publish(PubSubOption... options) {
|
||||
m_inst.addSchema(m_struct);
|
||||
return new StructArrayEntryImpl<T>(
|
||||
return new StructArrayEntryImpl<>(
|
||||
this,
|
||||
StructBuffer.create(m_struct),
|
||||
NetworkTablesJNI.publish(
|
||||
@@ -113,7 +113,7 @@ public final class StructArrayTopic<T> extends Topic {
|
||||
*/
|
||||
public StructArrayPublisher<T> publishEx(String properties, PubSubOption... options) {
|
||||
m_inst.addSchema(m_struct);
|
||||
return new StructArrayEntryImpl<T>(
|
||||
return new StructArrayEntryImpl<>(
|
||||
this,
|
||||
StructBuffer.create(m_struct),
|
||||
NetworkTablesJNI.publishEx(
|
||||
@@ -144,7 +144,7 @@ public final class StructArrayTopic<T> extends Topic {
|
||||
* @return entry
|
||||
*/
|
||||
public StructArrayEntry<T> getEntry(T[] defaultValue, PubSubOption... options) {
|
||||
return new StructArrayEntryImpl<T>(
|
||||
return new StructArrayEntryImpl<>(
|
||||
this,
|
||||
StructBuffer.create(m_struct),
|
||||
NetworkTablesJNI.getEntry(
|
||||
|
||||
@@ -188,14 +188,14 @@ final class StructEntryImpl<T> extends EntryBase implements StructEntry<T> {
|
||||
@SuppressWarnings("PMD.AvoidCatchingGenericException")
|
||||
private TimestampedObject<T> fromRaw(TimestampedRaw raw, T defaultValue) {
|
||||
if (raw.value.length == 0) {
|
||||
return new TimestampedObject<T>(0, 0, defaultValue);
|
||||
return new TimestampedObject<>(0, 0, defaultValue);
|
||||
}
|
||||
try {
|
||||
synchronized (m_buf) {
|
||||
return new TimestampedObject<T>(raw.timestamp, raw.serverTime, m_buf.read(raw.value));
|
||||
return new TimestampedObject<>(raw.timestamp, raw.serverTime, m_buf.read(raw.value));
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
return new TimestampedObject<T>(0, 0, defaultValue);
|
||||
return new TimestampedObject<>(0, 0, defaultValue);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ public final class StructTopic<T> extends Topic {
|
||||
* @return StructTopic for value class
|
||||
*/
|
||||
public static <T> StructTopic<T> wrap(Topic topic, Struct<T> struct) {
|
||||
return new StructTopic<T>(topic, struct);
|
||||
return new StructTopic<>(topic, struct);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,7 +46,7 @@ public final class StructTopic<T> extends Topic {
|
||||
* @return StructTopic for value class
|
||||
*/
|
||||
public static <T> StructTopic<T> wrap(NetworkTableInstance inst, int handle, Struct<T> struct) {
|
||||
return new StructTopic<T>(inst, handle, struct);
|
||||
return new StructTopic<>(inst, handle, struct);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,7 +62,7 @@ public final class StructTopic<T> extends Topic {
|
||||
* @return subscriber
|
||||
*/
|
||||
public StructSubscriber<T> subscribe(T defaultValue, PubSubOption... options) {
|
||||
return new StructEntryImpl<T>(
|
||||
return new StructEntryImpl<>(
|
||||
this,
|
||||
StructBuffer.create(m_struct),
|
||||
NetworkTablesJNI.subscribe(
|
||||
@@ -86,7 +86,7 @@ public final class StructTopic<T> extends Topic {
|
||||
*/
|
||||
public StructPublisher<T> publish(PubSubOption... options) {
|
||||
m_inst.addSchema(m_struct);
|
||||
return new StructEntryImpl<T>(
|
||||
return new StructEntryImpl<>(
|
||||
this,
|
||||
StructBuffer.create(m_struct),
|
||||
NetworkTablesJNI.publish(
|
||||
@@ -112,7 +112,7 @@ public final class StructTopic<T> extends Topic {
|
||||
*/
|
||||
public StructPublisher<T> publishEx(String properties, PubSubOption... options) {
|
||||
m_inst.addSchema(m_struct);
|
||||
return new StructEntryImpl<T>(
|
||||
return new StructEntryImpl<>(
|
||||
this,
|
||||
StructBuffer.create(m_struct),
|
||||
NetworkTablesJNI.publishEx(
|
||||
@@ -143,7 +143,7 @@ public final class StructTopic<T> extends Topic {
|
||||
* @return entry
|
||||
*/
|
||||
public StructEntry<T> getEntry(T defaultValue, PubSubOption... options) {
|
||||
return new StructEntryImpl<T>(
|
||||
return new StructEntryImpl<>(
|
||||
this,
|
||||
StructBuffer.create(m_struct),
|
||||
NetworkTablesJNI.getEntry(
|
||||
|
||||
@@ -6,7 +6,6 @@ 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;
|
||||
@@ -61,8 +60,8 @@ class NetworkTableTest {
|
||||
return Stream.of(
|
||||
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(List.of("/", "/foo", "/foo/bar", "/foo/bar/baz"), "/foo/bar/baz"),
|
||||
Arguments.of(List.of("/", "/foo", "/foo/bar", "/foo/bar/"), "/foo/bar/"));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
|
||||
@@ -4,11 +4,10 @@
|
||||
|
||||
package edu.wpi.first.networktables;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Arrays;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -31,9 +30,9 @@ class RawTest {
|
||||
void testGenericByteArray() {
|
||||
GenericEntry entry = m_inst.getTopic("test").getGenericEntry("raw");
|
||||
entry.setRaw(new byte[] {5}, 10);
|
||||
assertTrue(Arrays.equals(entry.getRaw(new byte[] {}), new byte[] {5}));
|
||||
assertArrayEquals(entry.getRaw(new byte[] {}), new byte[] {5});
|
||||
entry.setRaw(new byte[] {5, 6, 7}, 1, 2, 15);
|
||||
assertTrue(Arrays.equals(entry.getRaw(new byte[] {}), new byte[] {6, 7}));
|
||||
assertArrayEquals(entry.getRaw(new byte[] {}), new byte[] {6, 7});
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> entry.setRaw(new byte[] {5}, -1, 2, 20));
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> entry.setRaw(new byte[] {5}, 1, -2, 20));
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> entry.setRaw(new byte[] {5}, 1, 1, 20));
|
||||
@@ -43,9 +42,9 @@ class RawTest {
|
||||
void testRawByteArray() {
|
||||
RawEntry entry = m_inst.getRawTopic("test").getEntry("raw", new byte[] {});
|
||||
entry.set(new byte[] {5}, 10);
|
||||
assertTrue(Arrays.equals(entry.get(new byte[] {}), new byte[] {5}));
|
||||
assertArrayEquals(entry.get(new byte[] {}), new byte[] {5});
|
||||
entry.set(new byte[] {5, 6, 7}, 1, 2, 15);
|
||||
assertTrue(Arrays.equals(entry.get(new byte[] {}), new byte[] {6, 7}));
|
||||
assertArrayEquals(entry.get(new byte[] {}), new byte[] {6, 7});
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> entry.set(new byte[] {5}, -1, 1, 20));
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> entry.set(new byte[] {5}, 1, -1, 20));
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> entry.set(new byte[] {5}, 1, 1, 20));
|
||||
@@ -55,15 +54,15 @@ class RawTest {
|
||||
void testGenericByteBuffer() {
|
||||
GenericEntry entry = m_inst.getTopic("test").getGenericEntry("raw");
|
||||
entry.setRaw(ByteBuffer.wrap(new byte[] {5}), 10);
|
||||
assertTrue(Arrays.equals(entry.getRaw(new byte[] {}), new byte[] {5}));
|
||||
assertArrayEquals(entry.getRaw(new byte[] {}), new byte[] {5});
|
||||
entry.setRaw(ByteBuffer.wrap(new byte[] {5, 6, 7}).position(1), 15);
|
||||
assertTrue(Arrays.equals(entry.getRaw(new byte[] {}), new byte[] {6, 7}));
|
||||
assertArrayEquals(entry.getRaw(new byte[] {}), new byte[] {6, 7});
|
||||
entry.setRaw(ByteBuffer.wrap(new byte[] {5, 6, 7}).position(1).limit(2), 16);
|
||||
assertTrue(Arrays.equals(entry.getRaw(new byte[] {}), new byte[] {6}));
|
||||
assertArrayEquals(entry.getRaw(new byte[] {}), new byte[] {6});
|
||||
entry.setRaw(ByteBuffer.wrap(new byte[] {8, 9, 0}), 1, 2, 20);
|
||||
assertTrue(Arrays.equals(entry.getRaw(new byte[] {}), new byte[] {9, 0}));
|
||||
assertArrayEquals(entry.getRaw(new byte[] {}), new byte[] {9, 0});
|
||||
entry.setRaw(ByteBuffer.wrap(new byte[] {1, 2, 3}).position(2), 0, 2, 25);
|
||||
assertTrue(Arrays.equals(entry.getRaw(new byte[] {}), new byte[] {1, 2}));
|
||||
assertArrayEquals(entry.getRaw(new byte[] {}), new byte[] {1, 2});
|
||||
assertThrows(
|
||||
IndexOutOfBoundsException.class,
|
||||
() -> entry.setRaw(ByteBuffer.wrap(new byte[] {5}), -1, 1, 30));
|
||||
@@ -79,15 +78,15 @@ class RawTest {
|
||||
void testRawByteBuffer() {
|
||||
RawEntry entry = m_inst.getRawTopic("test").getEntry("raw", new byte[] {});
|
||||
entry.set(ByteBuffer.wrap(new byte[] {5}), 10);
|
||||
assertTrue(Arrays.equals(entry.get(new byte[] {}), new byte[] {5}));
|
||||
assertArrayEquals(entry.get(new byte[] {}), new byte[] {5});
|
||||
entry.set(ByteBuffer.wrap(new byte[] {5, 6, 7}).position(1), 15);
|
||||
assertTrue(Arrays.equals(entry.get(new byte[] {}), new byte[] {6, 7}));
|
||||
assertArrayEquals(entry.get(new byte[] {}), new byte[] {6, 7});
|
||||
entry.set(ByteBuffer.wrap(new byte[] {5, 6, 7}).position(1).limit(2), 16);
|
||||
assertTrue(Arrays.equals(entry.get(new byte[] {}), new byte[] {6}));
|
||||
assertArrayEquals(entry.get(new byte[] {}), new byte[] {6});
|
||||
entry.set(ByteBuffer.wrap(new byte[] {8, 9, 0}), 1, 2, 20);
|
||||
assertTrue(Arrays.equals(entry.get(new byte[] {}), new byte[] {9, 0}));
|
||||
assertArrayEquals(entry.get(new byte[] {}), new byte[] {9, 0});
|
||||
entry.set(ByteBuffer.wrap(new byte[] {1, 2, 3}).position(2), 0, 2, 25);
|
||||
assertTrue(Arrays.equals(entry.get(new byte[] {}), new byte[] {1, 2}));
|
||||
assertArrayEquals(entry.get(new byte[] {}), new byte[] {1, 2});
|
||||
assertThrows(
|
||||
IndexOutOfBoundsException.class,
|
||||
() -> entry.set(ByteBuffer.wrap(new byte[] {5}), -1, 1, 30));
|
||||
@@ -105,13 +104,13 @@ class RawTest {
|
||||
ByteBuffer bb = ByteBuffer.allocateDirect(3);
|
||||
bb.put(new byte[] {5, 6, 7});
|
||||
entry.setRaw(bb.position(1), 15);
|
||||
assertTrue(Arrays.equals(entry.getRaw(new byte[] {}), new byte[] {6, 7}));
|
||||
assertArrayEquals(entry.getRaw(new byte[] {}), new byte[] {6, 7});
|
||||
entry.setRaw(bb.limit(2), 16);
|
||||
assertTrue(Arrays.equals(entry.getRaw(new byte[] {}), new byte[] {6}));
|
||||
assertArrayEquals(entry.getRaw(new byte[] {}), new byte[] {6});
|
||||
bb.clear();
|
||||
bb.put(new byte[] {8, 9, 0});
|
||||
entry.setRaw(bb, 1, 2, 20);
|
||||
assertTrue(Arrays.equals(entry.getRaw(new byte[] {}), new byte[] {9, 0}));
|
||||
assertArrayEquals(entry.getRaw(new byte[] {}), new byte[] {9, 0});
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> entry.setRaw(bb, -1, 1, 25));
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> entry.setRaw(bb, 1, -1, 25));
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> entry.setRaw(bb, 2, 2, 25));
|
||||
@@ -123,13 +122,13 @@ class RawTest {
|
||||
ByteBuffer bb = ByteBuffer.allocateDirect(3);
|
||||
bb.put(new byte[] {5, 6, 7});
|
||||
entry.set(bb.position(1), 15);
|
||||
assertTrue(Arrays.equals(entry.get(new byte[] {}), new byte[] {6, 7}));
|
||||
assertArrayEquals(entry.get(new byte[] {}), new byte[] {6, 7});
|
||||
entry.set(bb.limit(2), 16);
|
||||
assertTrue(Arrays.equals(entry.get(new byte[] {}), new byte[] {6}));
|
||||
assertArrayEquals(entry.get(new byte[] {}), new byte[] {6});
|
||||
bb.clear();
|
||||
bb.put(new byte[] {8, 9, 0});
|
||||
entry.set(bb, 1, 2, 20);
|
||||
assertTrue(Arrays.equals(entry.get(new byte[] {}), new byte[] {9, 0}));
|
||||
assertArrayEquals(entry.get(new byte[] {}), new byte[] {9, 0});
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> entry.set(bb, -1, 1, 25));
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> entry.set(bb, 1, -1, 25));
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> entry.set(bb, 2, 2, 25));
|
||||
|
||||
Reference in New Issue
Block a user