mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[wpilib] Add AlertSim function to get only active alerts (#8732)
This commit is contained in:
@@ -71,7 +71,7 @@ public final class AlertSim {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets detailed information about each alert.
|
||||
* Gets detailed information about each alert (including inactive ones).
|
||||
*
|
||||
* @return Alerts
|
||||
*/
|
||||
@@ -84,6 +84,18 @@ public final class AlertSim {
|
||||
return infos;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets detailed information about all active alerts.
|
||||
*
|
||||
* @return Alerts
|
||||
*/
|
||||
public static AlertInfo[] getActive() {
|
||||
AlertInfo[] alertInfos = getAll();
|
||||
return java.util.Arrays.stream(alertInfos)
|
||||
.filter(info -> info.activeStartTime != 0)
|
||||
.toArray(AlertInfo[]::new);
|
||||
}
|
||||
|
||||
/** Resets all alert simulation data. */
|
||||
public static void resetData() {
|
||||
AlertDataJNI.resetData();
|
||||
|
||||
@@ -157,4 +157,29 @@ class AlertSimTest {
|
||||
assertTrue(isAlertActive("AFTER", Level.LOW));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void getActive() {
|
||||
try (var a = makeAlert("A", Level.HIGH);
|
||||
var b = makeAlert("B", Level.HIGH);
|
||||
var c = makeAlert("C", Level.HIGH)) {
|
||||
a.set(true);
|
||||
b.set(true);
|
||||
c.set(false);
|
||||
|
||||
var active = AlertSim.getActive();
|
||||
var all = AlertSim.getAll();
|
||||
assertEquals(2, active.length);
|
||||
assertEquals(3, all.length);
|
||||
assertTrue(Arrays.stream(active).anyMatch(x -> "A".equals(x.text)));
|
||||
assertTrue(Arrays.stream(active).anyMatch(x -> "B".equals(x.text)));
|
||||
|
||||
a.set(false);
|
||||
active = AlertSim.getActive();
|
||||
all = AlertSim.getAll();
|
||||
assertEquals(1, active.length);
|
||||
assertEquals(3, all.length);
|
||||
assertEquals(active[0].text, "B");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user