Sho SHIMIZU

Apply more functional style

Change-Id: Ib2194054dcddbc975f426c5a17a89031e3b1166d
...@@ -16,8 +16,8 @@ ...@@ -16,8 +16,8 @@
16 package org.onosproject.driver.ovsdb; 16 package org.onosproject.driver.ovsdb;
17 17
18 import java.util.Collection; 18 import java.util.Collection;
19 -import java.util.HashSet;
20 import java.util.Set; 19 import java.util.Set;
20 +import java.util.stream.Collectors;
21 21
22 import org.onlab.packet.IpAddress; 22 import org.onlab.packet.IpAddress;
23 import org.onosproject.net.DeviceId; 23 import org.onosproject.net.DeviceId;
...@@ -36,8 +36,6 @@ import org.onosproject.ovsdb.controller.OvsdbController; ...@@ -36,8 +36,6 @@ import org.onosproject.ovsdb.controller.OvsdbController;
36 import org.onosproject.ovsdb.controller.OvsdbNodeId; 36 import org.onosproject.ovsdb.controller.OvsdbNodeId;
37 import org.onosproject.ovsdb.controller.OvsdbPort; 37 import org.onosproject.ovsdb.controller.OvsdbPort;
38 38
39 -import com.google.common.collect.Sets;
40 -
41 /** 39 /**
42 * The implementation of BridageConfig. 40 * The implementation of BridageConfig.
43 */ 41 */
...@@ -63,18 +61,16 @@ public class OvsdbBridgeConfig extends AbstractHandlerBehaviour ...@@ -63,18 +61,16 @@ public class OvsdbBridgeConfig extends AbstractHandlerBehaviour
63 DriverHandler handler = handler(); 61 DriverHandler handler = handler();
64 DeviceId deviceId = handler.data().deviceId(); 62 DeviceId deviceId = handler.data().deviceId();
65 OvsdbClientService clientService = getOvsdbClientService(handler); 63 OvsdbClientService clientService = getOvsdbClientService(handler);
66 - Set<OvsdbBridge> ovsdbSet = clientService.getBridges(); 64 + Set<OvsdbBridge> bridges = clientService.getBridges();
67 - Collection<BridgeDescription> bridges = Sets.newHashSet(); 65 +
68 - ovsdbSet.forEach(o -> { 66 + return bridges.stream()
69 - BridgeName bridgeName = BridgeName 67 + .map(x -> new DefaultBridgeDescription(
70 - .bridgeName(o.bridgeName().value()); 68 + BridgeName.bridgeName(x.bridgeName().value()),
71 - DeviceId ownDeviceId = DeviceId.deviceId("of:" + o.datapathId().value()); 69 + deviceId,
72 - BridgeDescription description = new DefaultBridgeDescription(bridgeName, 70 + DeviceId.deviceId("of:" + x.datapathId().value())
73 - deviceId, 71 + )
74 - ownDeviceId); 72 + )
75 - bridges.add(description); 73 + .collect(Collectors.toSet());
76 - });
77 - return bridges;
78 } 74 }
79 75
80 @Override 76 @Override
...@@ -105,14 +101,15 @@ public class OvsdbBridgeConfig extends AbstractHandlerBehaviour ...@@ -105,14 +101,15 @@ public class OvsdbBridgeConfig extends AbstractHandlerBehaviour
105 public Collection<PortDescription> getPorts() { 101 public Collection<PortDescription> getPorts() {
106 DriverHandler handler = handler(); 102 DriverHandler handler = handler();
107 OvsdbClientService clientService = getOvsdbClientService(handler); 103 OvsdbClientService clientService = getOvsdbClientService(handler);
108 - Set<OvsdbPort> ovsdbSet = clientService.getPorts(); 104 + Set<OvsdbPort> ports = clientService.getPorts();
109 - Collection<PortDescription> ports = Sets.newHashSet(); 105 +
110 - ovsdbSet.forEach(o -> { 106 + return ports.stream()
111 - PortNumber port = PortNumber.portNumber(o.portNumber().value()); 107 + .map(x -> new DefaultPortDescription(
112 - PortDescription description = new DefaultPortDescription(port, true); 108 + PortNumber.portNumber(x.portNumber().value()),
113 - ports.add(description); 109 + true
114 - }); 110 + )
115 - return ports; 111 + )
112 + .collect(Collectors.toSet());
116 } 113 }
117 114
118 // OvsdbNodeId(IP:port) is used in the adaptor while DeviceId(ovsdb:IP:port) 115 // OvsdbNodeId(IP:port) is used in the adaptor while DeviceId(ovsdb:IP:port)
...@@ -137,15 +134,16 @@ public class OvsdbBridgeConfig extends AbstractHandlerBehaviour ...@@ -137,15 +134,16 @@ public class OvsdbBridgeConfig extends AbstractHandlerBehaviour
137 134
138 @Override 135 @Override
139 public Set<PortNumber> getPortNumbers() { 136 public Set<PortNumber> getPortNumbers() {
140 - Set<PortNumber> ports = new HashSet<>();
141 DriverHandler handler = handler(); 137 DriverHandler handler = handler();
142 OvsdbClientService clientService = getOvsdbClientService(handler); 138 OvsdbClientService clientService = getOvsdbClientService(handler);
143 - Set<OvsdbPort> ovsdbSet = clientService.getPorts(); 139 + Set<OvsdbPort> ports = clientService.getPorts();
144 - ovsdbSet.forEach(o -> { 140 +
145 - PortNumber port = PortNumber.portNumber(o.portNumber().value(), 141 + return ports.stream()
146 - o.portName().value()); 142 + .map(x -> PortNumber.portNumber(
147 - ports.add(port); 143 + x.portNumber().value(),
148 - }); 144 + x.portName().value()
149 - return ports; 145 + )
146 + )
147 + .collect(Collectors.toSet());
150 } 148 }
151 } 149 }
......
...@@ -18,6 +18,7 @@ package org.onosproject.driver.ovsdb; ...@@ -18,6 +18,7 @@ package org.onosproject.driver.ovsdb;
18 import java.util.Collection; 18 import java.util.Collection;
19 19
20 import java.util.Set; 20 import java.util.Set;
21 +import java.util.stream.Collectors;
21 22
22 import org.onlab.packet.IpAddress; 23 import org.onlab.packet.IpAddress;
23 import org.onosproject.net.DeviceId; 24 import org.onosproject.net.DeviceId;
...@@ -25,7 +26,6 @@ import org.onosproject.net.behaviour.DefaultTunnelDescription; ...@@ -25,7 +26,6 @@ import org.onosproject.net.behaviour.DefaultTunnelDescription;
25 import org.onosproject.net.behaviour.IpTunnelEndPoint; 26 import org.onosproject.net.behaviour.IpTunnelEndPoint;
26 import org.onosproject.net.behaviour.TunnelConfig; 27 import org.onosproject.net.behaviour.TunnelConfig;
27 import org.onosproject.net.behaviour.TunnelDescription; 28 import org.onosproject.net.behaviour.TunnelDescription;
28 -import org.onosproject.net.behaviour.TunnelEndPoint;
29 import org.onosproject.net.behaviour.TunnelName; 29 import org.onosproject.net.behaviour.TunnelName;
30 import org.onosproject.net.driver.AbstractHandlerBehaviour; 30 import org.onosproject.net.driver.AbstractHandlerBehaviour;
31 import org.onosproject.net.driver.DriverHandler; 31 import org.onosproject.net.driver.DriverHandler;
...@@ -34,8 +34,6 @@ import org.onosproject.ovsdb.controller.OvsdbController; ...@@ -34,8 +34,6 @@ import org.onosproject.ovsdb.controller.OvsdbController;
34 import org.onosproject.ovsdb.controller.OvsdbNodeId; 34 import org.onosproject.ovsdb.controller.OvsdbNodeId;
35 import org.onosproject.ovsdb.controller.OvsdbTunnel; 35 import org.onosproject.ovsdb.controller.OvsdbTunnel;
36 36
37 -import com.google.common.collect.Sets;
38 -
39 /** 37 /**
40 * OVSDB-based implementation of tunnel config behaviour. 38 * OVSDB-based implementation of tunnel config behaviour.
41 */ 39 */
...@@ -90,20 +88,18 @@ public class OvsdbTunnelConfig extends AbstractHandlerBehaviour ...@@ -90,20 +88,18 @@ public class OvsdbTunnelConfig extends AbstractHandlerBehaviour
90 public Collection<TunnelDescription> getTunnels() { 88 public Collection<TunnelDescription> getTunnels() {
91 DriverHandler handler = handler(); 89 DriverHandler handler = handler();
92 OvsdbClientService ovsdbNode = getOvsdbNode(handler); 90 OvsdbClientService ovsdbNode = getOvsdbNode(handler);
93 - Set<OvsdbTunnel> ovsdbSet = ovsdbNode.getTunnels(); 91 + Set<OvsdbTunnel> tunnels = ovsdbNode.getTunnels();
94 - Collection<TunnelDescription> tunnels = Sets.newHashSet(); 92 +
95 - ovsdbSet.forEach(o -> { 93 + return tunnels.stream()
96 - TunnelEndPoint ipSrc = IpTunnelEndPoint.ipTunnelPoint(o.localIp()); 94 + .map(x ->
97 - TunnelEndPoint ipDst = IpTunnelEndPoint.ipTunnelPoint(o.remoteIp()); 95 + new DefaultTunnelDescription(
98 - TunnelName name = TunnelName.tunnelName(o.tunnelName().toString()); 96 + IpTunnelEndPoint.ipTunnelPoint(x.localIp()),
99 - TunnelDescription des = new DefaultTunnelDescription( 97 + IpTunnelEndPoint.ipTunnelPoint(x.remoteIp()),
100 - ipSrc, 98 + TunnelDescription.Type.VXLAN,
101 - ipDst, 99 + TunnelName.tunnelName(x.tunnelName().toString())
102 - TunnelDescription.Type.VXLAN, 100 + )
103 - name); 101 + )
104 - tunnels.add(des); 102 + .collect(Collectors.toSet());
105 - });
106 - return tunnels;
107 } 103 }
108 104
109 // OvsdbNodeId(IP:port) is used in the adaptor while DeviceId(ovsdb:IP:port) 105 // OvsdbNodeId(IP:port) is used in the adaptor while DeviceId(ovsdb:IP:port)
......