Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Keppler2019-11-23 12:47:12 -0500
committerMichael Keppler2019-11-24 10:47:04 -0500
commit8d15ef9e8b12e56a3ba5a656bd0d427ea4e63745 (patch)
tree2f3a6a8497fb1b617308e0242af27e560514e80b
parent7c7b2e528b16412f9325515121c9019b0a202cf5 (diff)
downloadegit-8d15ef9e8b12e56a3ba5a656bd0d427ea4e63745.tar.gz
egit-8d15ef9e8b12e56a3ba5a656bd0d427ea4e63745.tar.xz
egit-8d15ef9e8b12e56a3ba5a656bd0d427ea4e63745.zip
Simplify comparator code
Use lambda style comparators where possible. They are easier to read. Change-Id: I21ce3ad901851f2fba70ea5d661ea31afd7b9b6d Signed-off-by: Michael Keppler <Michael.Keppler@gmx.de>
-rw-r--r--org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitResourceVariantTreeTest.java10
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitSelectionDialog.java15
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java30
3 files changed, 12 insertions, 43 deletions
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitResourceVariantTreeTest.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitResourceVariantTreeTest.java
index 6afb51f65..b981578fa 100644
--- a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitResourceVariantTreeTest.java
+++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitResourceVariantTreeTest.java
@@ -136,14 +136,8 @@ public class GitResourceVariantTreeTest extends GitTestCase {
// then
IResource[] roots = grvt.roots();
// sort in order to be able to assert the project instances
- Arrays.sort(roots, new Comparator<IResource>() {
- @Override
- public int compare(IResource r1, IResource r2) {
- String path1 = r1.getFullPath().toString();
- String path2 = r2.getFullPath().toString();
- return path1.compareTo(path2);
- }
- });
+ Arrays.sort(roots, Comparator
+ .comparing(resource -> resource.getFullPath().toString()));
assertEquals(2, roots.length);
IResource actualProject = roots[0];
assertEquals(this.project.project, actualProject);
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitSelectionDialog.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitSelectionDialog.java
index e0e4d6fc6..144b8740e 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitSelectionDialog.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitSelectionDialog.java
@@ -175,17 +175,10 @@ public class CommitSelectionDialog extends FilteredItemsSelectionDialog {
@Override
protected Comparator getItemsComparator() {
- return new Comparator<RepositoryCommit>() {
-
- @Override
- public int compare(RepositoryCommit o1, RepositoryCommit o2) {
- int compare = o1.getRepositoryName().compareToIgnoreCase(
- o2.getRepositoryName());
- if (compare == 0)
- compare = o1.getRevCommit().compareTo(o2.getRevCommit());
- return compare;
- }
- };
+ return Comparator
+ .comparing(RepositoryCommit::getRepositoryName,
+ String.CASE_INSENSITIVE_ORDER)
+ .thenComparing(RepositoryCommit::getRevCommit);
}
private Repository[] getRepositories() {
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java
index a8c5d1779..e8a3e0113 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java
@@ -681,30 +681,12 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener,
Set<RefFilter> filters = helper.getRefFilters();
List<RefFilter> sortedFilters = new ArrayList<>(
filters);
- sortedFilters.sort(new Comparator<RefFilter>() {
-
- private int category(RefFilter filter) {
- if (filter.isPreconfigured()) {
- return 100;
- }
- return 1000;
- }
-
- @Override
- public int compare(RefFilter o1, RefFilter o2) {
- int cat1 = category(o1);
- int cat2 = category(o2);
-
- if (cat1 != cat2) {
- return cat1 - cat2;
- }
-
- String name1 = o1.getFilterString();
- String name2 = o2.getFilterString();
-
- return name1.compareTo(name2);
- }
- });
+ sortedFilters
+ .sort(Comparator
+ .comparing(RefFilter::isPreconfigured,
+ Comparator.reverseOrder())
+ .thenComparing(RefFilter::getFilterString,
+ String.CASE_INSENSITIVE_ORDER));
for (RefFilter filter : sortedFilters) {
Action action = new ShownRefAction(filter, () -> {

Back to the top