Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Keppler2019-06-20 13:25:18 -0400
committerMichael Keppler2019-06-25 01:35:46 -0400
commit49573a86da2997b44073bd8606479218d23b5371 (patch)
tree0897d5946d4d8c7709a6e4d7cbf81688b525b395
parent58ba9fb83ae041fabed390261a79a7f34f40f9f3 (diff)
downloadegit-49573a86da2997b44073bd8606479218d23b5371.tar.gz
egit-49573a86da2997b44073bd8606479218d23b5371.tar.xz
egit-49573a86da2997b44073bd8606479218d23b5371.zip
Use computeIfAbsent where possible
Analysis was done with Sonarlint. Change-Id: I9d543d37886c7cfbd3a43ecf4477b8e8f3f573ff Signed-off-by: Michael Keppler <Michael.Keppler@gmx.de>
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/internal/util/ResourceUtil.java13
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/op/IgnoreOperation.java7
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/blame/AuthorColors.java8
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffEditorOutlinePage.java13
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/SubmoduleCommand.java7
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingViewContentProvider.java7
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/GitSynchronizeWizardPage.java7
7 files changed, 21 insertions, 41 deletions
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/util/ResourceUtil.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/util/ResourceUtil.java
index e2a62e6fc..b29a05e2b 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/util/ResourceUtil.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/util/ResourceUtil.java
@@ -508,7 +508,7 @@ public class ResourceUtil {
*/
public static Map<Repository, Collection<String>> splitResourcesByRepository(
Collection<IResource> resources) {
- Map<Repository, Collection<String>> result = new HashMap<Repository, Collection<String>>();
+ Map<Repository, Collection<String>> result = new HashMap<>();
for (IResource resource : resources) {
RepositoryMapping repositoryMapping = RepositoryMapping
.getMapping(resource);
@@ -547,7 +547,7 @@ public class ResourceUtil {
Collection<IPath> paths) {
RepositoryCache repositoryCache = Activator.getDefault()
.getRepositoryCache();
- Map<Repository, Collection<String>> result = new HashMap<Repository, Collection<String>>();
+ Map<Repository, Collection<String>> result = new HashMap<>();
for (IPath path : paths) {
Repository repository = repositoryCache.getRepository(path);
if (repository != null) {
@@ -607,11 +607,8 @@ public class ResourceUtil {
private static void addPathToMap(@NonNull Repository repository,
@Nullable String path, Map<Repository, Collection<String>> result) {
if (path != null) {
- Collection<String> resourcesList = result.get(repository);
- if (resourcesList == null) {
- resourcesList = new ArrayList<>();
- result.put(repository, resourcesList);
- }
+ Collection<String> resourcesList = result
+ .computeIfAbsent(repository, key -> new ArrayList<>());
resourcesList.add(path);
}
}
@@ -633,7 +630,7 @@ public class ResourceUtil {
final IModelProviderDescriptor[] modelDescriptors = ModelProvider
.getModelProviderDescriptors();
- final Set<ResourceMapping> mappings = new LinkedHashSet<ResourceMapping>();
+ final Set<ResourceMapping> mappings = new LinkedHashSet<>();
for (IModelProviderDescriptor candidate : modelDescriptors) {
try {
final IResource[] resources = candidate
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/op/IgnoreOperation.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/op/IgnoreOperation.java
index ffbe16c4e..6654d63cb 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/op/IgnoreOperation.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/op/IgnoreOperation.java
@@ -123,11 +123,8 @@ public class IgnoreOperation implements IEGitOperation {
return null;
}
IPath parent = path.removeLastSegments(1);
- Collection<String> values = result.get(parent);
- if (values == null) {
- values = new LinkedHashSet<>();
- result.put(parent, values);
- }
+ Collection<String> values = result.computeIfAbsent(parent,
+ key -> new LinkedHashSet<>());
values.add(path.lastSegment());
progress.worked(1);
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/blame/AuthorColors.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/blame/AuthorColors.java
index 271f87899..eb31fa8ec 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/blame/AuthorColors.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/blame/AuthorColors.java
@@ -69,12 +69,8 @@ public class AuthorColors {
* @return the corresponding color
*/
public RGB getCommitterRGB(String author) {
- RGB rgb = colors.get(author);
- if (rgb == null) {
- rgb = COMMITTER_RGBs[count++ % COMMITTER_RGBs.length];
- colors.put(author, rgb);
- }
- return rgb;
+ return colors.computeIfAbsent(author,
+ key -> COMMITTER_RGBs[count++ % COMMITTER_RGBs.length]);
}
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffEditorOutlinePage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffEditorOutlinePage.java
index a95ca96eb..b570a2ff2 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffEditorOutlinePage.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffEditorOutlinePage.java
@@ -357,13 +357,12 @@ public class DiffEditorOutlinePage extends NestedContentOutlinePage {
} else {
path = "/"; //$NON-NLS-1$
}
- Folder folder = folders.get(path);
- if (folder == null) {
- folder = new Folder();
- folder.name = path;
- folder.files = new ArrayList<>();
- folders.put(path, folder);
- }
+ Folder folder = folders.computeIfAbsent(path, key -> {
+ Folder newFolder = new Folder();
+ newFolder.name = key;
+ newFolder.files = new ArrayList<>();
+ return newFolder;
+ });
folder.files.add(range);
parents.put(range, folder);
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/SubmoduleCommand.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/SubmoduleCommand.java
index 3880efdcc..1c0c4ec51 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/SubmoduleCommand.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/SubmoduleCommand.java
@@ -48,11 +48,8 @@ public abstract class SubmoduleCommand<V extends RepositoryTreeNode<?>> extends
Repository parent = node.getParent().getRepository();
String path = Repository.stripWorkDir(parent.getWorkTree(),
node.getRepository().getWorkTree());
- List<String> paths = repoPaths.get(parent);
- if (paths == null) {
- paths = new ArrayList<>();
- repoPaths.put(parent, paths);
- }
+ List<String> paths = repoPaths.computeIfAbsent(parent,
+ key -> new ArrayList<>());
paths.add(path);
}
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingViewContentProvider.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingViewContentProvider.java
index a0f58339f..48981715e 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingViewContentProvider.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingViewContentProvider.java
@@ -212,11 +212,8 @@ public class StagingViewContentProvider extends WorkbenchContentProvider {
private static void addChild(Map<IPath, List<Object>> childrenForPath,
IPath path, Object child) {
- List<Object> children = childrenForPath.get(path);
- if (children == null) {
- children = new ArrayList<>();
- childrenForPath.put(path, children);
- }
+ List<Object> children = childrenForPath.computeIfAbsent(path,
+ key -> new ArrayList<>());
children.add(child);
}
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 eabc4fa51..04f0a0725 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
@@ -103,11 +103,8 @@ class GitSynchronizeWizardPage extends WizardPage {
if (repositoryMapping == null)
continue;
Repository repo = repositoryMapping.getRepository();
- Set<IProject> projects = resources.get(repo);
- if (projects == null) {
- projects = new HashSet<>();
- resources.put(repo, projects);
- }
+ Set<IProject> projects = resources.computeIfAbsent(repo,
+ key -> new HashSet<>());
projects.add(project);
}

Back to the top