Sho SHIMIZU

Apply more functional style

This commit keeps the original behavior, but it may cause a cast error.
It is better to use filter() to avoid the cast error.

Change-Id: Ieb3150e9775ed0689b3861de5179ff1346d2a3e6
...@@ -30,8 +30,8 @@ import org.onosproject.net.flowobjective.ForwardingObjective; ...@@ -30,8 +30,8 @@ import org.onosproject.net.flowobjective.ForwardingObjective;
30 import org.onosproject.store.service.EventuallyConsistentMap; 30 import org.onosproject.store.service.EventuallyConsistentMap;
31 import org.slf4j.Logger; 31 import org.slf4j.Logger;
32 32
33 -import java.util.ArrayList;
34 import java.util.List; 33 import java.util.List;
34 +import java.util.stream.Collectors;
35 35
36 import static org.slf4j.LoggerFactory.getLogger; 36 import static org.slf4j.LoggerFactory.getLogger;
37 37
...@@ -84,11 +84,12 @@ public class PolicyHandler { ...@@ -84,11 +84,12 @@ public class PolicyHandler {
84 * @return policy list 84 * @return policy list
85 */ 85 */
86 public List<Policy> getPolicies() { 86 public List<Policy> getPolicies() {
87 - List<Policy> policies = new ArrayList<>(); 87 + return policyStore.values()
88 - policyStore.values().forEach(policy -> policies.add( 88 + .stream()
89 - new TunnelPolicy((TunnelPolicy) policy))); 89 + // keep the original behavior, but it may cause a cast error
90 - 90 + // it is better to use filter() to omit instances not being TunnelPolicy
91 - return policies; 91 + .map(policy -> new TunnelPolicy((TunnelPolicy) policy))
92 + .collect(Collectors.toList());
92 } 93 }
93 94
94 /** 95 /**
......