Skip to content

Commit 2eb0506

Browse files
authored
Pipeline.indexOf(Step) returns -1 if not present (#782)
Instead of throwing an exception. Threading stuff kills it. Fixes #781
1 parent 9bb8ac0 commit 2eb0506

File tree

3 files changed

+3
-16
lines changed

3 files changed

+3
-16
lines changed

core/src/main/java/edu/wpi/grip/core/Pipeline.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import java.util.Collections;
3131
import java.util.HashSet;
3232
import java.util.List;
33-
import java.util.NoSuchElementException;
3433
import java.util.Set;
3534
import java.util.concurrent.locks.Lock;
3635
import java.util.concurrent.locks.ReadWriteLock;
@@ -382,13 +381,7 @@ public synchronized void moveStep(Step step, int delta) {
382381
@Override
383382
public int indexOf(Step step) {
384383
checkNotNull(step, "step");
385-
return readStepsSafely(steps -> {
386-
int index = steps.indexOf(step);
387-
if (index == -1) {
388-
throw new NoSuchElementException("Step " + step + " is not in the pipeline");
389-
}
390-
return index;
391-
});
384+
return readStepsSafely(steps -> steps.indexOf(step));
392385
}
393386

394387
@Subscribe

core/src/test/java/edu/wpi/grip/core/PipelineTest.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,10 @@
2626
import java.net.URISyntaxException;
2727
import java.util.Arrays;
2828
import java.util.Collections;
29-
import java.util.NoSuchElementException;
3029

3130
import static org.junit.Assert.assertEquals;
3231
import static org.junit.Assert.assertFalse;
3332
import static org.junit.Assert.assertTrue;
34-
import static org.junit.Assert.fail;
3533

3634
public class PipelineTest {
3735

@@ -393,12 +391,7 @@ public void testIndexOf() {
393391
pipeline.addStep(step);
394392
assertEquals("Index of step was not zero", 0, pipeline.indexOf(step));
395393
pipeline.removeStep(step);
396-
try {
397-
pipeline.indexOf(step);
398-
fail("NoSuchElementException should have been thrown");
399-
} catch (NoSuchElementException expected) {
400-
// This should happen
401-
}
394+
assertEquals("Index was not -1", -1, pipeline.indexOf(step));
402395
}
403396

404397
@Test

ui/src/main/java/edu/wpi/grip/ui/analysis/AnalysisController.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ private void exportCsv() {
210210
private <E> Stream<Map.Entry<Step, E>> sortedStream(Map<Step, E> m) {
211211
return m.entrySet()
212212
.stream()
213+
.filter(e -> stepIndexer.indexOf(e.getKey()) >= 0)
213214
.sorted((e1, e2) -> stepIndexer.compare(e1.getKey(), e2.getKey()));
214215
}
215216

0 commit comments

Comments
 (0)