Skip to content

Commit

Permalink
newer stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
srimanachanta committed Dec 2, 2023
1 parent 5f05124 commit e674a62
Show file tree
Hide file tree
Showing 58 changed files with 258 additions and 420 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import edu.wpi.first.math.geometry.Pose3d;
import edu.wpi.first.math.geometry.Rotation3d;
import edu.wpi.first.math.util.Units;
import java.io.IOException;
import java.util.Optional;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
Expand All @@ -28,7 +27,7 @@ void testLoad(AprilTagFields field) {
}

@Test
void test2022RapidReact() throws IOException {
void test2022RapidReact() {
AprilTagFieldLayout layout = AprilTagFields.k2022RapidReact.loadAprilTagLayoutField();

// Blue Hangar Truss - Hub
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public static boolean readConfig() {
// parse file
JsonElement top;
try {
top = new JsonParser().parse(Files.newBufferedReader(Paths.get(configFile)));
top = JsonParser.parseReader(Files.newBufferedReader(Paths.get(configFile)));
} catch (IOException ex) {
System.err.println("could not open '" + configFile + "': " + ex);
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void update(VideoEvent event) {
}

@Override
public void close() throws Exception {
public void close() {
if (m_booleanValueEntry != null) {
m_booleanValueEntry.close();
}
Expand Down
9 changes: 3 additions & 6 deletions hal/src/main/java/edu/wpi/first/hal/DMAJNISample.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ public int getAnalogInputAveraged(int analogInputHandle) {
}

// + 2 Hack, but needed to not have to call into JNI
int value = readValue(data.m_valueType + 2, data.m_index);
return value;
return readValue(data.m_valueType + 2, data.m_index);
}

public void getAnalogAccumulator(int analogInputHandle, AccumulatorResult result) {
Expand All @@ -144,14 +143,12 @@ public void getAnalogAccumulator(int analogInputHandle, AccumulatorResult result
if (data.m_index == 0) {
int val0 = readValue(kEnable_Accumulator0, 0);
int val1 = readValue(kEnable_Accumulator0, 1);
int val2 = readValue(kEnable_Accumulator0, 2);
result.count = val2;
result.count = readValue(kEnable_Accumulator0, 2);
result.value = ((long) val1 << 32) | val0;
} else if (data.m_index == 1) {
int val0 = readValue(kEnable_Accumulator1, 0);
int val1 = readValue(kEnable_Accumulator1, 1);
int val2 = readValue(kEnable_Accumulator1, 2);
result.count = val2;
result.count = readValue(kEnable_Accumulator1, 2);
result.value = ((long) val1 << 32) | val0;
} else {
throw new RuntimeException("Resource not found in DMA capture");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1009,5 +1009,5 @@ public int hashCode() {
}

private final Topic m_topic;
protected int m_handle;
private final int m_handle;
}
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ private void startThread() {
} catch (Throwable throwable) {
System.err.println(
"Unhandled exception during listener callback: "
+ throwable.toString());
+ throwable);
throwable.printStackTrace();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ public String[] getStringArray() {
* @return The entry value
*/
public static NetworkTableValue makeBoolean(boolean value) {
return new NetworkTableValue(NetworkTableType.kBoolean, Boolean.valueOf(value));
return new NetworkTableValue(NetworkTableType.kBoolean, value);
}

/**
Expand All @@ -347,7 +347,7 @@ public static NetworkTableValue makeBoolean(boolean value) {
* @return The entry value
*/
public static NetworkTableValue makeBoolean(boolean value, long time) {
return new NetworkTableValue(NetworkTableType.kBoolean, Boolean.valueOf(value), time);
return new NetworkTableValue(NetworkTableType.kBoolean, value, time);
}

/**
Expand All @@ -357,7 +357,7 @@ public static NetworkTableValue makeBoolean(boolean value, long time) {
* @return The entry value
*/
public static NetworkTableValue makeInteger(long value) {
return new NetworkTableValue(NetworkTableType.kInteger, Long.valueOf(value));
return new NetworkTableValue(NetworkTableType.kInteger, value);
}

/**
Expand All @@ -368,7 +368,7 @@ public static NetworkTableValue makeInteger(long value) {
* @return The entry value
*/
public static NetworkTableValue makeInteger(long value, long time) {
return new NetworkTableValue(NetworkTableType.kInteger, Long.valueOf(value), time);
return new NetworkTableValue(NetworkTableType.kInteger, value, time);
}

/**
Expand All @@ -378,7 +378,7 @@ public static NetworkTableValue makeInteger(long value, long time) {
* @return The entry value
*/
public static NetworkTableValue makeFloat(float value) {
return new NetworkTableValue(NetworkTableType.kFloat, Float.valueOf(value));
return new NetworkTableValue(NetworkTableType.kFloat, value);
}

/**
Expand All @@ -389,7 +389,7 @@ public static NetworkTableValue makeFloat(float value) {
* @return The entry value
*/
public static NetworkTableValue makeFloat(float value, long time) {
return new NetworkTableValue(NetworkTableType.kFloat, Float.valueOf(value), time);
return new NetworkTableValue(NetworkTableType.kFloat, value, time);
}

/**
Expand All @@ -399,7 +399,7 @@ public static NetworkTableValue makeFloat(float value, long time) {
* @return The entry value
*/
public static NetworkTableValue makeDouble(double value) {
return new NetworkTableValue(NetworkTableType.kDouble, Double.valueOf(value));
return new NetworkTableValue(NetworkTableType.kDouble, value);
}

/**
Expand All @@ -410,7 +410,7 @@ public static NetworkTableValue makeDouble(double value) {
* @return The entry value
*/
public static NetworkTableValue makeDouble(double value, long time) {
return new NetworkTableValue(NetworkTableType.kDouble, Double.valueOf(value), time);
return new NetworkTableValue(NetworkTableType.kDouble, value, time);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,14 @@ private T fromRaw(byte[] raw, T defaultValue) {

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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private ProtobufTopic(NetworkTableInstance inst, int handle, Protobuf<T, ?> prot
* @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);
}

/**
Expand All @@ -47,7 +47,7 @@ public static <T> ProtobufTopic<T> wrap(Topic topic, Protobuf<T, ?> proto) {
*/
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);
}

/**
Expand All @@ -63,7 +63,7 @@ public static <T> ProtobufTopic<T> wrap(
* @return subscriber
*/
public ProtobufSubscriber<T> subscribe(T defaultValue, PubSubOption... options) {
return new ProtobufEntryImpl<T>(
return new ProtobufEntryImpl<>(
this,
ProtobufBuffer.create(m_proto),
NetworkTablesJNI.subscribe(
Expand All @@ -87,7 +87,7 @@ public ProtobufSubscriber<T> subscribe(T defaultValue, PubSubOption... options)
*/
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(
Expand All @@ -113,7 +113,7 @@ public ProtobufPublisher<T> publish(PubSubOption... options) {
*/
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(
Expand Down Expand Up @@ -144,7 +144,7 @@ public ProtobufPublisher<T> publishEx(String properties, PubSubOption... options
* @return entry
*/
public ProtobufEntry<T> getEntry(T defaultValue, PubSubOption... options) {
return new ProtobufEntryImpl<T>(
return new ProtobufEntryImpl<>(
this,
ProtobufBuffer.create(m_proto),
NetworkTablesJNI.getEntry(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,14 @@ private T[] fromRaw(byte[] raw, T[] defaultValue) {
@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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private StructArrayTopic(NetworkTableInstance inst, int handle, Struct<T> struct
* @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);
}

/**
Expand All @@ -47,7 +47,7 @@ public static <T> StructArrayTopic<T> wrap(Topic topic, Struct<T> struct) {
*/
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);
}

/**
Expand All @@ -63,7 +63,7 @@ public static <T> StructArrayTopic<T> wrap(
* @return subscriber
*/
public StructArraySubscriber<T> subscribe(T[] defaultValue, PubSubOption... options) {
return new StructArrayEntryImpl<T>(
return new StructArrayEntryImpl<>(
this,
StructBuffer.create(m_struct),
NetworkTablesJNI.subscribe(
Expand All @@ -87,7 +87,7 @@ public StructArraySubscriber<T> subscribe(T[] defaultValue, PubSubOption... opti
*/
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(
Expand All @@ -113,7 +113,7 @@ public StructArrayPublisher<T> publish(PubSubOption... options) {
*/
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(
Expand Down Expand Up @@ -144,7 +144,7 @@ public StructArrayPublisher<T> publishEx(String properties, PubSubOption... opti
* @return entry
*/
public StructArrayEntry<T> getEntry(T[] defaultValue, PubSubOption... options) {
return new StructArrayEntryImpl<T>(
return new StructArrayEntryImpl<>(
this,
StructBuffer.create(m_struct),
NetworkTablesJNI.getEntry(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,14 @@ private T fromRaw(byte[] raw, T defaultValue) {
@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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private StructTopic(NetworkTableInstance inst, int handle, Struct<T> struct) {
* @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);
}

/**
Expand All @@ -46,7 +46,7 @@ public static <T> StructTopic<T> wrap(Topic topic, Struct<T> struct) {
* @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);
}

/**
Expand All @@ -62,7 +62,7 @@ public static <T> StructTopic<T> wrap(NetworkTableInstance inst, int handle, Str
* @return subscriber
*/
public StructSubscriber<T> subscribe(T defaultValue, PubSubOption... options) {
return new StructEntryImpl<T>(
return new StructEntryImpl<>(
this,
StructBuffer.create(m_struct),
NetworkTablesJNI.subscribe(
Expand All @@ -86,7 +86,7 @@ public StructSubscriber<T> subscribe(T defaultValue, PubSubOption... options) {
*/
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(
Expand All @@ -112,7 +112,7 @@ public StructPublisher<T> publish(PubSubOption... options) {
*/
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(
Expand Down Expand Up @@ -143,7 +143,7 @@ public StructPublisher<T> publishEx(String properties, PubSubOption... options)
* @return entry
*/
public StructEntry<T> getEntry(T defaultValue, PubSubOption... options) {
return new StructEntryImpl<T>(
return new StructEntryImpl<>(
this,
StructBuffer.create(m_struct),
NetworkTablesJNI.getEntry(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ void parallelRaceOnlyCallsEndOnceTest() {
scheduler.run();
command2Holder.setFinished(true);
// at this point the sequential group should be done
assertDoesNotThrow(() -> scheduler.run());
assertDoesNotThrow(scheduler::run);
assertFalse(scheduler.isScheduled(group2));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ void cancelFromEndLoopWhileInRunLoop() {
scheduler.schedule(cCancelsD);
scheduler.schedule(dCancelsAll);

assertDoesNotThrow(() -> scheduler.run());
assertDoesNotThrow(scheduler::run);
assertEquals(4, counter.get());
assertFalse(scheduler.isScheduled(aCancelsB));
assertFalse(scheduler.isScheduled(bCancelsC));
Expand Down
Loading

0 comments on commit e674a62

Please sign in to comment.