From bb9cc6b851572a3b756f65738034e546bd33e17d Mon Sep 17 00:00:00 2001 From: Munir Ahmad Date: Sat, 24 Feb 2018 12:42:55 -0500 Subject: Swap while loops with foreach where applicable Change-Id: Id3b54e8192f0e60657aa4c50af56c1ef98fbff5e Issue-ID: SO-437 Signed-off-by: Munir Ahmad --- .../mso/bpmn/core/domain/ServiceDecomposition.java | 37 ++++++++-------------- 1 file changed, 14 insertions(+), 23 deletions(-) (limited to 'bpmn/MSOCoreBPMN') diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/ServiceDecomposition.java b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/ServiceDecomposition.java index 0e985cc8f1..15a1cee5c0 100644 --- a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/ServiceDecomposition.java +++ b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/ServiceDecomposition.java @@ -186,15 +186,13 @@ public class ServiceDecomposition extends JsonWrapper implements Serializable { @JsonIgnore public String getVnfResource(String resourceObjectId) { - Iterator iter = getServiceResources().iterator(); - while (iter.hasNext()) { - Resource resource = iter.next(); - //resource.getModelInfo().getModelInvariantId(); + for (Resource resource : getServiceResources()) { + //resource.getModelInfo().getModelInvariantId(); - if ("extracted information".equals(resourceObjectId)){ - return resource.toJsonString(); - } - } + if ("extracted information".equals(resourceObjectId)) { + return resource.toJsonString(); + } + } return ""; } @@ -290,13 +288,11 @@ public class ServiceDecomposition extends JsonWrapper implements Serializable { public boolean replaceResource(Resource newResource){ boolean result = false; List serviceResources = getServiceResources(); - Iterator iter = serviceResources.iterator(); - while (iter.hasNext()) { - Resource resource = iter.next(); + for (Resource resource : (Iterable) serviceResources) { System.out.println("resource found"); - if (resource.resourceType == newResource.resourceType){ + if (resource.resourceType == newResource.resourceType) { System.out.println("resource type matches"); - if (resource.getResourceId().equalsIgnoreCase(newResource.getResourceId())){ + if (resource.getResourceId().equalsIgnoreCase(newResource.getResourceId())) { System.out.println("resource id matches"); //returns TRUE if replacement is a success result = Collections.replaceAll(serviceResources, resource, newResource); @@ -326,12 +322,9 @@ public class ServiceDecomposition extends JsonWrapper implements Serializable { */ public boolean deleteResource(Resource resource){ List serviceResources = getServiceResources(); - Iterator iter = serviceResources.iterator(); - while (iter.hasNext()) { - Resource item = iter.next(); - - if (item.resourceType == resource.resourceType){ - if (item.getResourceId().equalsIgnoreCase(resource.getResourceId())){ + for (Resource item : (Iterable) serviceResources) { + if (item.resourceType == resource.resourceType) { + if (item.getResourceId().equalsIgnoreCase(resource.getResourceId())) { //returns TRUE if replacement is a success return serviceResources.remove(resource); } @@ -377,10 +370,8 @@ public class ServiceDecomposition extends JsonWrapper implements Serializable { @JsonIgnore public Resource getServiceResource(String resourceId){ List resources = getServiceResources(); - Iterator iter = resources.iterator(); - while (iter.hasNext()){ - Resource resource = iter.next(); - if (resource.getResourceId().equalsIgnoreCase(resourceId)){ + for (Resource resource : resources) { + if (resource.getResourceId().equalsIgnoreCase(resourceId)) { //match return resource; } -- cgit 1.2.3-korg