Sho SHIMIZU
Committed by Gerrit Code Review

Refactor: Revise implemtation of getAvailableLambdas()

Change-Id: Ief731b9c3b9899819ad26549ecab936d14cad74a
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
15 */ 15 */
16 package org.onosproject.net.resource.impl; 16 package org.onosproject.net.resource.impl;
17 17
18 +import com.google.common.collect.ImmutableList;
18 import com.google.common.collect.Sets; 19 import com.google.common.collect.Sets;
19 import org.apache.felix.scr.annotations.Activate; 20 import org.apache.felix.scr.annotations.Activate;
20 import org.apache.felix.scr.annotations.Component; 21 import org.apache.felix.scr.annotations.Component;
...@@ -46,6 +47,7 @@ import org.onosproject.net.resource.link.MplsLabelResourceAllocation; ...@@ -46,6 +47,7 @@ import org.onosproject.net.resource.link.MplsLabelResourceAllocation;
46 import org.onosproject.net.resource.link.MplsLabelResourceRequest; 47 import org.onosproject.net.resource.link.MplsLabelResourceRequest;
47 import org.slf4j.Logger; 48 import org.slf4j.Logger;
48 49
50 +import java.util.Collection;
49 import java.util.Collections; 51 import java.util.Collections;
50 import java.util.HashMap; 52 import java.util.HashMap;
51 import java.util.HashSet; 53 import java.util.HashSet;
...@@ -53,7 +55,6 @@ import java.util.Iterator; ...@@ -53,7 +55,6 @@ import java.util.Iterator;
53 import java.util.Map; 55 import java.util.Map;
54 import java.util.Set; 56 import java.util.Set;
55 57
56 -import static com.google.common.base.Preconditions.checkArgument;
57 import static com.google.common.base.Preconditions.checkNotNull; 58 import static com.google.common.base.Preconditions.checkNotNull;
58 import static org.onosproject.security.AppGuard.checkPermission; 59 import static org.onosproject.security.AppGuard.checkPermission;
59 import static org.slf4j.LoggerFactory.getLogger; 60 import static org.slf4j.LoggerFactory.getLogger;
...@@ -114,15 +115,12 @@ public class LinkResourceManager ...@@ -114,15 +115,12 @@ public class LinkResourceManager
114 * @param links the links 115 * @param links the links
115 * @return available lambdas on specified links 116 * @return available lambdas on specified links
116 */ 117 */
117 - private Iterable<LambdaResource> getAvailableLambdas(Iterable<Link> links) { 118 + private Collection<LambdaResource> getAvailableLambdas(Iterable<Link> links) {
118 checkNotNull(links); 119 checkNotNull(links);
119 - Iterator<Link> i = links.iterator(); 120 + return ImmutableList.copyOf(links).stream()
120 - checkArgument(i.hasNext()); 121 + .map(this::getAvailableLambdas)
121 - Set<LambdaResource> lambdas = new HashSet<>(getAvailableLambdas(i.next())); 122 + .reduce(Sets::intersection)
122 - while (i.hasNext()) { 123 + .orElse(Collections.emptySet());
123 - lambdas.retainAll(getAvailableLambdas(i.next()));
124 - }
125 - return lambdas;
126 } 124 }
127 125
128 126
......