rewrite query completion
The old implementation searched for all possible values and then executed each query to see what matches. The new implementation uses several indices to find only the matching values.
This commit is contained in:
@@ -7,6 +7,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@@ -62,4 +63,31 @@ public class CollectionUtils {
|
||||
return collection.stream().filter(predicate).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static <T> int indexOf(final List<T> list, final Predicate<T> predicate) {
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
if (predicate.test(list.get(i))) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static <V, T extends Collection<V>> T removeAll(final T collection, final T remove,
|
||||
final Supplier<T> generator) {
|
||||
|
||||
final T result = generator.get();
|
||||
result.addAll(collection);
|
||||
result.removeAll(remove);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static <V, T extends Collection<V>> T retainAll(final T collection, final T retain,
|
||||
final Supplier<T> generator) {
|
||||
|
||||
final T result = generator.get();
|
||||
result.addAll(collection);
|
||||
result.retainAll(retain);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user