Only create the search parameters once per search.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 21 Jan 2014 06:22:42 +0000 (07:22 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 21 Jan 2014 06:22:42 +0000 (07:22 +0100)
src/main/java/net/pterodactylus/xdcc/ui/stdin/SearchCommand.java

index 170365a..0ae1b15 100644 (file)
@@ -22,6 +22,7 @@ import static java.util.Arrays.asList;
 import static java.util.regex.Pattern.CASE_INSENSITIVE;
 import static java.util.regex.Pattern.UNICODE_CASE;
 import static java.util.regex.Pattern.compile;
+import static java.util.stream.Collectors.toList;
 
 import java.io.IOException;
 import java.io.Writer;
@@ -72,9 +73,10 @@ public class SearchCommand implements Command {
        @Override
        public State execute(State state, List<String> parameters, Writer outputWriter) throws IOException {
                List<Result> lastResult = newArrayList();
+               List<SearchParameter> searchParameters = parameters.stream().map(SearchParameter::from).collect(toList());
                for (Bot bot : newArrayList(core.bots())) {
                        for (Pack pack : newArrayList(bot)) {
-                               if (parameters.stream().map(SearchParameter::from).allMatch((parameter) -> parameter.matches(pack.name()))) {
+                               if (searchParameters.stream().allMatch((parameter) -> parameter.matches(pack.name()))) {
                                        lastResult.add(new Result(core, bot, pack));
                                }
                        }