diff options
author | Adrien Hopkins <ahopk127@my.yorku.ca> | 2022-05-18 09:38:49 -0500 |
---|---|---|
committer | Adrien Hopkins <ahopk127@my.yorku.ca> | 2022-05-18 09:38:49 -0500 |
commit | 42c7e596747873afeb572be551dd991986beb51c (patch) | |
tree | 16d76e22fca2774979470ab34f18433b890e5e5c /src/main/java/sevenUnitsGUI | |
parent | 213a9b78cf39776c3832983e9d9c26435bad2282 (diff) |
Added front-end code information to the design document
Diffstat (limited to 'src/main/java/sevenUnitsGUI')
-rw-r--r-- | src/main/java/sevenUnitsGUI/FilterComparator.java | 10 | ||||
-rw-r--r-- | src/main/java/sevenUnitsGUI/MutablePredicate.java | 70 |
2 files changed, 9 insertions, 71 deletions
diff --git a/src/main/java/sevenUnitsGUI/FilterComparator.java b/src/main/java/sevenUnitsGUI/FilterComparator.java index f34d0c0..c0a67e8 100644 --- a/src/main/java/sevenUnitsGUI/FilterComparator.java +++ b/src/main/java/sevenUnitsGUI/FilterComparator.java @@ -90,11 +90,19 @@ final class FilterComparator<T> implements Comparator<T> { */ public FilterComparator(final String filter, final Comparator<T> comparator, final boolean caseSensitive) { - this.filter = Objects.requireNonNull(filter, "filter must not be null."); + Objects.requireNonNull(filter, "filter must not be null."); + this.filter = caseSensitive ? filter : filter.toLowerCase(); this.comparator = comparator; this.caseSensitive = caseSensitive; } + /** + * Compares two objects according to whether or not they match a filter. + * Objects whose string representation starts with the filter's text go + * first, then those that contain it but don't start with it, then those that + * don't contain it. Objects in the same order here are sorted by their + * string representation's compareTo or the provided comparator. + */ @Override public int compare(final T arg0, final T arg1) { // if this is case insensitive, make them lowercase diff --git a/src/main/java/sevenUnitsGUI/MutablePredicate.java b/src/main/java/sevenUnitsGUI/MutablePredicate.java deleted file mode 100644 index 6cb8689..0000000 --- a/src/main/java/sevenUnitsGUI/MutablePredicate.java +++ /dev/null @@ -1,70 +0,0 @@ -/** - * Copyright (C) 2019 Adrien Hopkins - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <https://www.gnu.org/licenses/>. - */ -package sevenUnitsGUI; - -import java.util.function.Predicate; - -/** - * A container for a predicate, which can be changed later. - * - * @author Adrien Hopkins - * @since 2019-04-13 - * @since v0.2.0 - */ -final class MutablePredicate<T> implements Predicate<T> { - /** - * The predicate stored in this {@code MutablePredicate} - * - * @since 2019-04-13 - * @since v0.2.0 - */ - private Predicate<T> predicate; - - /** - * Creates the {@code MutablePredicate}. - * - * @since 2019-04-13 - * @since v0.2.0 - */ - public MutablePredicate(final Predicate<T> predicate) { - this.predicate = predicate; - } - - /** - * @return predicate - * @since 2019-04-13 - * @since v0.2.0 - */ - public final Predicate<T> getPredicate() { - return this.predicate; - } - - /** - * @param predicate - * new value of predicate - * @since 2019-04-13 - * @since v0.2.0 - */ - public final void setPredicate(final Predicate<T> predicate) { - this.predicate = predicate; - } - - @Override - public boolean test(final T t) { - return this.predicate.test(t); - } -} |