From 21dd3a9fa8e71901bb279708152d7d787089adc7 Mon Sep 17 00:00:00 2001 From: Elsa Zacharia Date: Thu, 4 Jan 2024 10:03:04 +0530 Subject: [PATCH] simplify collection emptiness check Use isEmpty() API of collections to simplify the emptiness check.reduces one extra comparison. --- .../eclipse/e4/ui/internal/workbench/ModelAssembler.java | 2 +- .../eclipse/e4/ui/internal/workbench/ModelServiceImpl.java | 2 +- .../e4/ui/internal/workbench/PartActivationHistory.java | 2 +- .../eclipse/e4/ui/internal/workbench/PartServiceImpl.java | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ModelAssembler.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ModelAssembler.java index fa38a66102c..56c50517a5a 100644 --- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ModelAssembler.java +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ModelAssembler.java @@ -526,7 +526,7 @@ public void processFragment(MModelFragments fragmentsContainer, MModelFragment f log(LogLevel.DEBUG, "Nothing to merge for fragment {} of {}", contributorURI, //$NON-NLS-1$ contributorName); } - if (evalImports && fragmentsContainer.getImports().size() > 0) { + if (evalImports && !fragmentsContainer.getImports().isEmpty()) { resolveImports(fragmentsContainer.getImports(), addedElements); } } diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ModelServiceImpl.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ModelServiceImpl.java index bf51b7eec40..baaec512ba8 100644 --- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ModelServiceImpl.java +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ModelServiceImpl.java @@ -450,7 +450,7 @@ public MUIElement find(String id, MUIElement searchRoot) { } List elements = findElements(searchRoot, id, MUIElement.class); - if (elements.size() > 0) { + if (!elements.isEmpty()) { return elements.get(0); } return null; diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/PartActivationHistory.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/PartActivationHistory.java index 2399075d396..46cc662f896 100644 --- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/PartActivationHistory.java +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/PartActivationHistory.java @@ -323,7 +323,7 @@ && isValid(perspective, candidate)) { List activeCandidates = modelService.findElements(perspective, null, MPart.class, singletonList(EPartService.ACTIVE_ON_CLOSE_TAG)); - if (activeCandidates.size() > 0) { + if (!activeCandidates.isEmpty()) { activeCandidates.get(0).getTags().remove(EPartService.ACTIVE_ON_CLOSE_TAG); MPart candidate = activeCandidates.get(0); if (partService.isInContainer(perspective, candidate) diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/PartServiceImpl.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/PartServiceImpl.java index 815a8254e1a..7177c9b1fca 100644 --- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/PartServiceImpl.java +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/PartServiceImpl.java @@ -453,7 +453,7 @@ private void internalFixContext(MPart part, MUIElement oldSelectedElement) { @Override public MPart findPart(String id) { List parts = getParts(MPart.class, id); - return parts.size() > 0 ? parts.get(0) : null; + return parts.isEmpty() ? null : parts.get(0); } private List getParts(Class cls, String id) { @@ -1020,7 +1020,7 @@ private MPart addPart(MPart providedPart, MPart localPart) { } else { // Find the first visible stack in the area List sharedStacks = modelService.findElements(area, null, MPartStack.class); - if (sharedStacks.size() > 0) { + if (!sharedStacks.isEmpty()) { for (MPartStack stack : sharedStacks) { if (stack.isToBeRendered()) { stack.getChildren().add(providedPart); @@ -1085,7 +1085,7 @@ private void addToLastContainer(String category, MPart part) { descId += ":*"; //$NON-NLS-1$ List phList = modelService.findElements(workbenchWindow, descId, MPlaceholder.class, null, EModelService.PRESENTATION); - if (phList.size() > 0) { + if (!phList.isEmpty()) { MUIElement phParent = phList.get(0).getParent(); if (phParent instanceof MPartStack) { MPartStack theStack = (MPartStack) phParent;