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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -39,6 +39,12 @@ public class Preconditions {
|
||||
}
|
||||
}
|
||||
|
||||
public static void checkSmaller(final long a, final long b, final String message, final Object... args) {
|
||||
if (a >= b) {
|
||||
throw new IllegalStateException(MessageFormat.format(message, args) + " Expected: " + a + " < " + b);
|
||||
}
|
||||
}
|
||||
|
||||
public static void checkEqual(final Object actual, final Object expected) {
|
||||
checkEqual(actual, expected, "expected {0} is equal to {1}", actual, expected);
|
||||
}
|
||||
@@ -74,6 +80,18 @@ public class Preconditions {
|
||||
checkEqual(actual, true, message, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that the given value is false.
|
||||
*
|
||||
* @param actual must be false
|
||||
* @param message formatted with {@link MessageFormat}
|
||||
* @param args arguments for the message
|
||||
* @throws IllegalStateException if {@code actual} is not false
|
||||
*/
|
||||
public static void checkFalse(final boolean actual, final String message, final Object... args) {
|
||||
checkEqual(actual, false, message, args);
|
||||
}
|
||||
|
||||
public static void checkNull(final Object actual, final String message, final Object... args) {
|
||||
if (actual != null) {
|
||||
throw new IllegalStateException(MessageFormat.format(message, args));
|
||||
|
||||
Reference in New Issue
Block a user