diff options
Diffstat (limited to 'src/main/java/sevenUnitsGUI/FilterComparator.java')
-rw-r--r-- | src/main/java/sevenUnitsGUI/FilterComparator.java | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/src/main/java/sevenUnitsGUI/FilterComparator.java b/src/main/java/sevenUnitsGUI/FilterComparator.java index 484a98f..ff942fb 100644 --- a/src/main/java/sevenUnitsGUI/FilterComparator.java +++ b/src/main/java/sevenUnitsGUI/FilterComparator.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018 Adrien Hopkins + * Copyright (C) 2018, 2022, 2024, 2025 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 @@ -21,9 +21,9 @@ import java.util.Objects; /** * A comparator that compares strings using a filter. - * + * * @param <T> type of element being compared - * + * * @author Adrien Hopkins * @since 2019-01-15 * @since v0.1.0 @@ -31,21 +31,21 @@ import java.util.Objects; final class FilterComparator<T> implements Comparator<T> { /** * The filter that the comparator is filtered by. - * + * * @since 2019-01-15 * @since v0.1.0 */ private final String filter; /** * The comparator to use if the arguments are otherwise equal. - * + * * @since 2019-01-15 * @since v0.1.0 */ private final Comparator<T> comparator; /** * Whether or not the comparison is case-sensitive. - * + * * @since 2019-04-14 * @since v0.2.0 */ @@ -53,7 +53,7 @@ final class FilterComparator<T> implements Comparator<T> { /** * Creates the {@code FilterComparator}. - * + * * @param filter * @since 2019-01-15 * @since v0.1.0 @@ -64,7 +64,7 @@ final class FilterComparator<T> implements Comparator<T> { /** * Creates the {@code FilterComparator}. - * + * * @param filter string to filter by * @param comparator comparator to fall back to if all else fails, null is * compareTo. @@ -79,7 +79,7 @@ final class FilterComparator<T> implements Comparator<T> { /** * Creates the {@code FilterComparator}. - * + * * @param filter string to filter by * @param comparator comparator to fall back to if all else fails, null is * compareTo. @@ -118,19 +118,18 @@ final class FilterComparator<T> implements Comparator<T> { // elements that start with the filter always go first if (str0.startsWith(this.filter) && !str1.startsWith(this.filter)) return -1; - else if (!str0.startsWith(this.filter) && str1.startsWith(this.filter)) + if (!str0.startsWith(this.filter) && str1.startsWith(this.filter)) return 1; // elements that contain the filter but don't start with them go next if (str0.contains(this.filter) && !str1.contains(this.filter)) return -1; - else if (!str0.contains(this.filter) && !str1.contains(this.filter)) + if (!str0.contains(this.filter) && !str1.contains(this.filter)) return 1; // other elements go last if (this.comparator == null) return str0.compareTo(str1); - else - return this.comparator.compare(arg0, arg1); + return this.comparator.compare(arg0, arg1); } } |