summaryrefslogtreecommitdiff
path: root/src/main/java/sevenUnitsGUI/FilterComparator.java
diff options
context:
space:
mode:
authorAdrien Hopkins <adrien.p.hopkins@gmail.com>2025-06-15 19:42:01 -0500
committerAdrien Hopkins <adrien.p.hopkins@gmail.com>2025-06-15 19:42:01 -0500
commit2fdbc084fd1d78f0b7633db34460b1195de264f3 (patch)
tree4c908950d9b049394f8160b8159b498aec586ecc /src/main/java/sevenUnitsGUI/FilterComparator.java
parented53492243ecad8d975401a97f5b634328ad2c71 (diff)
parentbccb5b5e3452421c81c1fb58f83391ba6584807c (diff)
Merge release 1.0.0 into stable branchHEADstable
See the tag 'v1.0.0' or the changelog for more information about this release.
Diffstat (limited to 'src/main/java/sevenUnitsGUI/FilterComparator.java')
-rw-r--r--src/main/java/sevenUnitsGUI/FilterComparator.java25
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);
}
}