From 66eb1927358b90586ffa2c4810bbd94dce5cc7b2 Mon Sep 17 00:00:00 2001 From: Risto Lahtela <24460436+Rsl1122@users.noreply.github.com> Date: Sun, 7 Feb 2021 23:04:51 +0200 Subject: [PATCH] Changed how first filter with CompleteSetException works Now if the first filter instead says (skip) and returns 0 players. I considered that all players could be returned, but it is better if users get to choose their filter again in this case. Affects issues: - Fixed #1742 --- .../storage/database/queries/filter/Filter.java | 17 ++++++++++++----- .../database/queries/filter/QueryFilters.java | 5 +---- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/filter/Filter.java b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/filter/Filter.java index a24adc368..0d8d2d3ea 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/filter/Filter.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/filter/Filter.java @@ -39,12 +39,15 @@ public interface Filter { * @param query Query for the filter * @return Set of UUIDs this filter applies to * @throws IllegalArgumentException If the arguments are not valid. - * @throws CompleteSetException If the arguments produce a complete set. */ Set getMatchingUUIDs(SpecifiedFilterInformation query); default Result apply(SpecifiedFilterInformation query) { - return new Result(null, getKind(), getMatchingUUIDs(query)); + try { + return new Result(null, getKind(), getMatchingUUIDs(query)); + } catch (CompleteSetException allMatch) { + return new Result(null, getKind() + " (skip)", new HashSet<>()); + } } class Result { @@ -62,9 +65,13 @@ public interface Filter { } public Result apply(Filter filter, SpecifiedFilterInformation query) { - Set got = filter.getMatchingUUIDs(query); - currentUUIDs.retainAll(got); - return new Result(this, filter.getKind(), currentUUIDs); + try { + Set got = filter.getMatchingUUIDs(query); + currentUUIDs.retainAll(got); + return new Result(this, filter.getKind(), currentUUIDs); + } catch (CompleteSetException allMatch) { + return notApplied(filter); + } } public Result notApplied(Filter filter) { diff --git a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/filter/QueryFilters.java b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/filter/QueryFilters.java index 2820ce511..3c19dd242 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/filter/QueryFilters.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/filter/QueryFilters.java @@ -96,8 +96,7 @@ public class QueryFilters { String kind = specifiedFilterInformation.getKind(); Filter filter = getFilter(kind).orElseThrow(() -> new BadRequestException("Filter kind not supported: '" + kind + "'")); - current = getResult(current, filter, specifiedFilterInformation); - return current; + return getResult(current, filter, specifiedFilterInformation); } private Filter.Result getResult(Filter.Result current, Filter filter, SpecifiedFilterInformation query) { @@ -107,8 +106,6 @@ public class QueryFilters { throw new BadRequestException("Bad parameters for filter '" + filter.getKind() + "': expecting " + Arrays.asList(filter.getExpectedParameters()) + ", but was given " + query.getSetParameters()); - } catch (CompleteSetException complete) { - return current == null ? null : current.notApplied(filter); } }