From 4801ce15a46317c7cc0fc0d8c3543c0802e468eb Mon Sep 17 00:00:00 2001 From: Titouan Vervack Date: Fri, 26 Apr 2024 11:50:56 +0200 Subject: [PATCH] Small cleanup Using a local variable and putIfAbsent makes the code more compact and legible --- .../internal/core/target/TargetDefinition.java | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/TargetDefinition.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/TargetDefinition.java index 2230612ca2..ff47a12241 100644 --- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/TargetDefinition.java +++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/TargetDefinition.java @@ -1270,15 +1270,12 @@ private void updateIUContainerElements(Element containersElement, List for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); if (node instanceof Element) { - if (repoURL == null - && node.getNodeName().equalsIgnoreCase(TargetDefinitionPersistenceHelper.REPOSITORY)) { + String nodeName = node.getNodeName(); + if (repoURL == null && nodeName.equalsIgnoreCase(TargetDefinitionPersistenceHelper.REPOSITORY)) { repoURL = ((Element) node).getAttribute(TargetDefinitionPersistenceHelper.LOCATION); - if (!oldContainersByRepo.containsKey(repoURL)) { - oldContainersByRepo.put(repoURL, new ArrayList<>()); - } + oldContainersByRepo.putIfAbsent(repoURL, new ArrayList<>()); oldContainersByRepo.get(repoURL).add(container); - } else if (node.getNodeName() - .equalsIgnoreCase(TargetDefinitionPersistenceHelper.INSTALLABLE_UNIT)) { + } else if (nodeName.equalsIgnoreCase(TargetDefinitionPersistenceHelper.INSTALLABLE_UNIT)) { units.add((Element) node); } } @@ -1297,11 +1294,10 @@ private void updateIUContainerElements(Element containersElement, List for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); if (node instanceof Element) { - if (repoURL == null - && node.getNodeName().equalsIgnoreCase(TargetDefinitionPersistenceHelper.REPOSITORY)) { + String nodeName = node.getNodeName(); + if (repoURL == null && nodeName.equalsIgnoreCase(TargetDefinitionPersistenceHelper.REPOSITORY)) { repoURL = ((Element) node).getAttribute(TargetDefinitionPersistenceHelper.LOCATION); - } else if (node.getNodeName() - .equalsIgnoreCase(TargetDefinitionPersistenceHelper.INSTALLABLE_UNIT)) { + } else if (nodeName.equalsIgnoreCase(TargetDefinitionPersistenceHelper.INSTALLABLE_UNIT)) { units.add((Element) node); } }