Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf2019-05-16 06:41:17 -0400
committerThomas Wolf2019-05-22 02:47:50 -0400
commit2cd5ab8d6f1321384e17675fe7e6df5bd61d3839 (patch)
tree4293594b3aa9e07dda42353811ef0f2ee0364cdf
parentaf39fca07a7c7d10a94c8e74ed31d0483b25bc1a (diff)
downloadegit-2cd5ab8d6f1321384e17675fe7e6df5bd61d3839.tar.gz
egit-2cd5ab8d6f1321384e17675fe7e6df5bd61d3839.tar.xz
egit-2cd5ab8d6f1321384e17675fe7e6df5bd61d3839.zip
Simplify comparators by using Comparator.comparing()
Clean up (unwrap) comparators that just forward to another comparator. CommonUtils.RESOURCE_NAME_COMPARATOR is left unchanged; using Comparator.comparing() there would cause Policy.getComparator() being called once only and very early, which might change behavior if Policy.setComparator() is used. Change-Id: I852f97e2d885063ce3bed273603fd8b241f2e953 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/CommonUtils.java12
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/clone/SourceBranchPage.java8
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitEditorPage.java13
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/RefSpecPanel.java9
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/fetch/FetchSourcePage.java10
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/GlobalConfigurationPreferencePage.java10
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/pull/PullWizardPage.java9
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/push/PushBranchPage.java10
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/GitSynchronizeWizardPage.java11
9 files changed, 22 insertions, 70 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/CommonUtils.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/CommonUtils.java
index 524e6c414..de7d5fc8f 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/CommonUtils.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/CommonUtils.java
@@ -148,9 +148,8 @@ public class CommonUtils {
* Instance of comparator which sorts {@link Ref} names using
* {@link CommonUtils#STRING_ASCENDING_COMPARATOR}.
*/
- public static final Comparator<Ref> REF_ASCENDING_COMPARATOR = //
- (a, b) -> STRING_ASCENDING_COMPARATOR.compare(a.getName(),
- b.getName());
+ public static final Comparator<Ref> REF_ASCENDING_COMPARATOR = Comparator
+ .comparing(Ref::getName, STRING_ASCENDING_COMPARATOR);
/**
* Comparator for comparing {@link IResource} by the result of
@@ -163,10 +162,9 @@ public class CommonUtils {
* Comparator for comparing (@link Path} by the result of
* {@link Path#toAbsolutePath()}
*/
- public static final Comparator<Path> PATH_STRING_COMPARATOR = //
- (a, b) -> STRING_ASCENDING_COMPARATOR.compare(
- a.toAbsolutePath().toString(),
- b.toAbsolutePath().toString());
+ public static final Comparator<Path> PATH_STRING_COMPARATOR = Comparator
+ .comparing(p -> p.toAbsolutePath().toString(),
+ STRING_ASCENDING_COMPARATOR);
/**
* Programmatically run command based on its id and given selection
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/clone/SourceBranchPage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/clone/SourceBranchPage.java
index 4cb736614..fecb69e95 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/clone/SourceBranchPage.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/clone/SourceBranchPage.java
@@ -19,7 +19,6 @@ import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
-import java.util.Comparator;
import java.util.List;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -376,12 +375,7 @@ class SourceBranchPage extends WizardPage {
}
}
}
- Collections.sort(availableRefs, new Comparator<Ref>() {
- @Override
- public int compare(final Ref ref1, final Ref ref2) {
- return CommonUtils.REF_ASCENDING_COMPARATOR.compare(ref1, ref2);
- }
- });
+ Collections.sort(availableRefs, CommonUtils.REF_ASCENDING_COMPARATOR);
if (idHEAD != null && head == null) {
head = idHEAD;
availableRefs.add(0, idHEAD);
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitEditorPage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitEditorPage.java
index 90942c4a0..7497d3c6d 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitEditorPage.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitEditorPage.java
@@ -375,15 +375,10 @@ public class CommitEditorPage extends FormPage
Repository repository = getCommit().getRepository();
List<Ref> tags = new ArrayList<>(
repository.getRefDatabase().getRefsByPrefix(Constants.R_TAGS));
- Collections.sort(tags, new Comparator<Ref>() {
-
- @Override
- public int compare(Ref r1, Ref r2) {
- return CommonUtils.STRING_ASCENDING_COMPARATOR.compare(
- Repository.shortenRefName(r1.getName()),
- Repository.shortenRefName(r2.getName()));
- }
- });
+ Collections.sort(tags,
+ Comparator.comparing(
+ ref -> Repository.shortenRefName(ref.getName()),
+ CommonUtils.STRING_ASCENDING_COMPARATOR));
return tags;
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/RefSpecPanel.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/RefSpecPanel.java
index 4dbd10203..b2d2cb3f7 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/RefSpecPanel.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/RefSpecPanel.java
@@ -17,7 +17,6 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
-import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
@@ -1733,12 +1732,8 @@ public class RefSpecPanel {
private List<RefContentProposal> createContentProposals(
final Collection<Ref> refs, final Ref head) {
- final TreeSet<Ref> set = new TreeSet<>(new Comparator<Ref>() {
- @Override
- public int compare(Ref ref1, Ref ref2) {
- return CommonUtils.REF_ASCENDING_COMPARATOR.compare(ref1, ref2);
- }
- });
+ final TreeSet<Ref> set = new TreeSet<>(
+ CommonUtils.REF_ASCENDING_COMPARATOR);
set.addAll(refs);
if (head != null) {
set.add(head);
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/fetch/FetchSourcePage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/fetch/FetchSourcePage.java
index e17a9d5b3..6668b63f8 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/fetch/FetchSourcePage.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/fetch/FetchSourcePage.java
@@ -13,7 +13,6 @@ package org.eclipse.egit.ui.internal.fetch;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.Comparator;
import java.util.List;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -158,13 +157,8 @@ public class FetchSourcePage extends WizardPage {
|| ref.getName().startsWith(Constants.R_TAGS))
proposals.add(ref);
}
- Collections.sort(proposals, new Comparator<Ref>() {
- @Override
- public int compare(Ref ref1, Ref ref2) {
- return CommonUtils.REF_ASCENDING_COMPARATOR
- .compare(ref1, ref2);
- }
- });
+ Collections.sort(proposals,
+ CommonUtils.REF_ASCENDING_COMPARATOR);
this.remoteRefs = proposals;
} catch (IllegalStateException e) {
setErrorMessage(e.getMessage());
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/GlobalConfigurationPreferencePage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/GlobalConfigurationPreferencePage.java
index c87bad37a..221f04151 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/GlobalConfigurationPreferencePage.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/GlobalConfigurationPreferencePage.java
@@ -264,14 +264,8 @@ public class GlobalConfigurationPreferencePage extends PreferencePage implements
}
private void sortRepositoriesByName() {
- Collections.sort(repositories, new Comparator<Repository>() {
-
- @Override
- public int compare(Repository repo1, Repository repo2) {
- return String.CASE_INSENSITIVE_ORDER.compare(getName(repo1),
- getName(repo2));
- }
- });
+ Collections.sort(repositories, Comparator.comparing(this::getName,
+ String.CASE_INSENSITIVE_ORDER));
}
private String[] getRepositoryComboItems() {
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/pull/PullWizardPage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/pull/PullWizardPage.java
index 7f343c0ea..81bf5b2f1 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/pull/PullWizardPage.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/pull/PullWizardPage.java
@@ -127,13 +127,8 @@ public class PullWizardPage extends WizardPage {
try {
this.remoteConfigs = RemoteConfig
.getAllRemoteConfigs(repository.getConfig());
- Collections.sort(remoteConfigs, new Comparator<RemoteConfig>() {
- @Override
- public int compare(RemoteConfig first, RemoteConfig second) {
- return String.CASE_INSENSITIVE_ORDER
- .compare(first.getName(), second.getName());
- }
- });
+ Collections.sort(remoteConfigs, Comparator.comparing(
+ RemoteConfig::getName, String.CASE_INSENSITIVE_ORDER));
setDefaultUpstreamConfig();
} catch (URISyntaxException e) {
this.remoteConfigs = new ArrayList<>();
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/push/PushBranchPage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/push/PushBranchPage.java
index 06734b7d3..d904a8e08 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/push/PushBranchPage.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/push/PushBranchPage.java
@@ -175,14 +175,8 @@ public class PushBranchPage extends WizardPage {
});
try {
this.remoteConfigs = RemoteConfig.getAllRemoteConfigs(repository.getConfig());
- Collections.sort(remoteConfigs, new Comparator<RemoteConfig>() {
-
- @Override
- public int compare(RemoteConfig first, RemoteConfig second) {
- return String.CASE_INSENSITIVE_ORDER.compare(
- first.getName(), second.getName());
- }
- });
+ Collections.sort(remoteConfigs, Comparator.comparing(
+ RemoteConfig::getName, String.CASE_INSENSITIVE_ORDER));
} catch (URISyntaxException e) {
this.remoteConfigs = new ArrayList<>();
handleError(e);
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/GitSynchronizeWizardPage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/GitSynchronizeWizardPage.java
index b494fbb2d..eabc4fa51 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/GitSynchronizeWizardPage.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/GitSynchronizeWizardPage.java
@@ -287,15 +287,8 @@ class GitSynchronizeWizardPage extends WizardPage {
List<Repository> repositoriesList = new ArrayList<>(
resources.keySet());
- Collections.sort(repositoriesList, new Comparator<Repository>() {
- @Override
- public int compare(Repository o1, Repository o2) {
- String name1 = o1.getWorkTree().getName();
- String name2 = o2.getWorkTree().getName();
-
- return name1.compareToIgnoreCase(name2);
- }
- });
+ Collections.sort(repositoriesList, Comparator.comparing(
+ r -> r.getWorkTree().getName(), String.CASE_INSENSITIVE_ORDER));
treeViewer.setInput(repositoriesList
.toArray(new Repository[0]));

Back to the top