Skip to content

Commit

Permalink
fix: string commands were erroring (#426)
Browse files Browse the repository at this point in the history
So the list that is being filtered is immutable, hence doesn't work with in conjunction with removeIf.

There are two solutions, either
- stream it (which I've done in this PR)
OR
- create a new ArrayList each time for filtering since that is mutable
  • Loading branch information
TreemanKing authored and sekwah41 committed Nov 18, 2024
1 parent 6847b0e commit 8afbae5
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

public class CommandWithSubCommands implements CommandTemplate {

Expand Down Expand Up @@ -171,7 +172,8 @@ public List<String> filterTabResults(List<String> tabList, String lastArg) {
if(tabList == null) {
return null;
}
tabList.removeIf(arg -> !arg.startsWith(lastArg));
return tabList;
return tabList.stream()
.filter(arg -> arg.startsWith(lastArg))
.collect(Collectors.toList());
}
}

0 comments on commit 8afbae5

Please sign in to comment.