General clean-ups 99/50399/10
authorStephen Kitt <skitt@redhat.com>
Fri, 13 Jan 2017 09:09:25 +0000 (10:09 +0100)
committerSam Hague <shague@redhat.com>
Mon, 30 Jan 2017 19:51:13 +0000 (19:51 +0000)
Automated refactors:
* use List::sort instead of Collections::sort
* use foreach loops
* use switch statements instead of if/else if constructs
* use contains() instead of comparing indexOf()
* use Collection::removeIf instead of looping explicitly
* use Optional::ifPresent where possible
* use Map::computeIfAbsent instead of conditional puts
* use try with resources

Change-Id: I1f6c2986abb0f151bb4ff1bc262b1c1ae11c523f
Signed-off-by: Stephen Kitt <skitt@redhat.com>
27 files changed:
openstack/net-virt-providers/src/main/java/org/opendaylight/netvirt/openstack/netvirt/providers/openflow13/PipelineOrchestratorImpl.java
openstack/net-virt-providers/src/main/java/org/opendaylight/netvirt/openstack/netvirt/providers/openflow13/services/EgressAclService.java
openstack/net-virt-providers/src/main/java/org/opendaylight/netvirt/openstack/netvirt/providers/openflow13/services/IngressAclService.java
openstack/net-virt/src/main/java/org/opendaylight/netvirt/openstack/netvirt/impl/SecurityGroupCacheManagerImpl.java
vpnservice/aclservice/impl/src/main/java/org/opendaylight/netvirt/aclservice/utils/AclServiceUtils.java
vpnservice/bgpmanager/bgpmanager-impl/src/main/java/org/opendaylight/netvirt/bgpmanager/oam/BgpCountersBroadcaster.java
vpnservice/dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/netvirt/dhcpservice/DhcpPktHandler.java
vpnservice/elanmanager/elanmanager-api/src/main/java/org/opendaylight/netvirt/elanmanager/utils/ElanL2GwCacheUtils.java
vpnservice/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/ha/HwvtepHAUtil.java
vpnservice/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/ha/listeners/HwvtepNodeBaseListener.java
vpnservice/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/listeners/HwvtepTerminationPointListener.java
vpnservice/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/netvirt/elan/utils/ElanUtils.java
vpnservice/elanmanager/elanmanager-impl/src/test/java/org/opendaylight/netvirt/elan/l2gw/nodehandlertest/GlobalAugmentationHelper.java
vpnservice/elanmanager/elanmanager-impl/src/test/java/org/opendaylight/netvirt/elan/l2gw/nodehandlertest/NodeConnectedHandlerUtils.java
vpnservice/fibmanager/fibmanager-impl/src/main/java/org/opendaylight/netvirt/fibmanager/NexthopManager.java
vpnservice/ipv6service/impl/src/main/java/org/opendaylight/netvirt/ipv6service/VirtualRouter.java
vpnservice/ipv6service/impl/src/main/java/org/opendaylight/netvirt/ipv6service/VirtualSubnet.java
vpnservice/ipv6service/impl/src/main/java/org/opendaylight/netvirt/ipv6service/utils/Ipv6ServiceUtils.java
vpnservice/it/impl/src/test/java/org/opendaylight/netvirt/it/PortInfo.java
vpnservice/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronPortChangeListener.java
vpnservice/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronRouterChangeListener.java
vpnservice/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronvpnManager.java
vpnservice/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronvpnUtils.java
vpnservice/vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/netvirt/vpnmanager/ArpMonitorStopTask.java
vpnservice/vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/netvirt/vpnmanager/TunnelInterfaceStateListener.java
vpnservice/vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/netvirt/vpnmanager/VpnOpDataSyncer.java
vpnservice/vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/netvirt/vpnmanager/VpnUtil.java

index 86fc2767dd5c842ce36cb7b8aa86077c8b78f264..9fcbe1f9aac5202afab458272d29b6b510741666 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2015 Red Hat, Inc. and others. All rights reserved.
+ * Copyright © 2014, 2017 Red Hat, Inc. and others. All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -103,7 +103,7 @@ public class PipelineOrchestratorImpl implements ConfigInterface, NodeCacheListe
         // insert the service if not already there. The list is ordered based of table ID.
         if (!staticPipeline.contains(service) && !isTableInPipeline(service.getTable())) {
             staticPipeline.add(service);
-            Collections.sort(staticPipeline, Service.insertComparator);
+            staticPipeline.sort(Service.insertComparator);
         }
         LOG.info("registerService: {}", staticPipeline);
     }
index 0a7bc6751bf43616c4aec61b1b84de2259f9e831..a8ef5445f687c03a14b76dc809abfa0ff89de545 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 - 2016 Red Hat, Inc. and others. All rights reserved.
+ * Copyright © 2014, 2017 Red Hat, Inc. and others. All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -247,56 +247,62 @@ public class EgressAclService extends AbstractServiceInstance implements EgressA
                 portSecurityRule.setSecurityRuleProtocol(null);
             }
         } else {
-            if (portSecurityRule.getSecurityRuleProtocol().equals(MatchUtils.TCP_PROTOCOL)) {
-                portSecurityRule.setSecurityRulePortMin(PORT_RANGE_MIN);
-                portSecurityRule.setSecurityRulePortMax(PORT_RANGE_MAX);
-                egressAclTcp(dpidLong, segmentationId, srcMac,
-                        portSecurityRule,dstAddress, write,
-                        Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, false);
-            } else if (portSecurityRule.getSecurityRuleProtocol().equals(MatchUtils.UDP_PROTOCOL)) {
-                portSecurityRule.setSecurityRulePortMin(PORT_RANGE_MIN);
-                portSecurityRule.setSecurityRulePortMax(PORT_RANGE_MAX);
-                egressAclUdp(dpidLong, segmentationId, srcMac,
-                        portSecurityRule, dstAddress, write,
-                        Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, false);
-            } else if (portSecurityRule.getSecurityRuleProtocol().equals(MatchUtils.ICMP_PROTOCOL)) {
-                egressAclIcmp(dpidLong, segmentationId, srcMac,
-                        portSecurityRule, dstAddress,write,
-                        Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, false);
-            } else {
-                MatchBuilder matchBuilder = new MatchBuilder();
-                String flowId = "Egress_Other_" + segmentationId + "_" + srcMac + "_";
-                matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder,srcMac,null,MatchUtils.ETHERTYPE_IPV4);
-                short proto = 0;
-                try {
-                    Integer protocol = new Integer(portSecurityRule.getSecurityRuleProtocol());
-                    proto = protocol.shortValue();
-                    flowId = flowId + proto;
-                } catch (NumberFormatException e) {
-                    LOG.error("Protocol vlaue conversion failure", e);
-                }
-                matchBuilder = MatchUtils.createIpProtocolAndEthMatch(matchBuilder, proto, srcMac, null);
-                if (null != dstAddress) {
-                    flowId = flowId + dstAddress;
-                    matchBuilder = MatchUtils.addRemoteIpPrefix(matchBuilder, null,
-                                                                 MatchUtils.iPv4PrefixFromIPv4Address(dstAddress));
-                } else if (null != portSecurityRule.getSecurityRuleRemoteIpPrefix()) {
-                    flowId = flowId + portSecurityRule.getSecurityRuleRemoteIpPrefix();
-                    if(isIpv6) {
-                        matchBuilder = MatchUtils.addRemoteIpv6Prefix(matchBuilder,null,
-                                new Ipv6Prefix(portSecurityRule.getSecurityRuleRemoteIpPrefix()));
-                    } else {
-                        if (!portSecurityRule.getSecurityRuleRemoteIpPrefix().contains("/0")) {
-                            matchBuilder = MatchUtils.addRemoteIpPrefix(matchBuilder, null,
-                                new Ipv4Prefix(portSecurityRule.getSecurityRuleRemoteIpPrefix()));
+            switch (portSecurityRule.getSecurityRuleProtocol()) {
+                case MatchUtils.TCP_PROTOCOL:
+                    portSecurityRule.setSecurityRulePortMin(PORT_RANGE_MIN);
+                    portSecurityRule.setSecurityRulePortMax(PORT_RANGE_MAX);
+                    egressAclTcp(dpidLong, segmentationId, srcMac,
+                            portSecurityRule, dstAddress, write,
+                            Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, false);
+                    break;
+                case MatchUtils.UDP_PROTOCOL:
+                    portSecurityRule.setSecurityRulePortMin(PORT_RANGE_MIN);
+                    portSecurityRule.setSecurityRulePortMax(PORT_RANGE_MAX);
+                    egressAclUdp(dpidLong, segmentationId, srcMac,
+                            portSecurityRule, dstAddress, write,
+                            Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, false);
+                    break;
+                case MatchUtils.ICMP_PROTOCOL:
+                    egressAclIcmp(dpidLong, segmentationId, srcMac,
+                            portSecurityRule, dstAddress, write,
+                            Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, false);
+                    break;
+                default:
+                    MatchBuilder matchBuilder = new MatchBuilder();
+                    String flowId = "Egress_Other_" + segmentationId + "_" + srcMac + "_";
+                    matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder, srcMac, null,
+                            MatchUtils.ETHERTYPE_IPV4);
+                    short proto = 0;
+                    try {
+                        Integer protocol = new Integer(portSecurityRule.getSecurityRuleProtocol());
+                        proto = protocol.shortValue();
+                        flowId = flowId + proto;
+                    } catch (NumberFormatException e) {
+                        LOG.error("Protocol vlaue conversion failure", e);
+                    }
+                    matchBuilder = MatchUtils.createIpProtocolAndEthMatch(matchBuilder, proto, srcMac, null);
+                    if (null != dstAddress) {
+                        flowId = flowId + dstAddress;
+                        matchBuilder = MatchUtils.addRemoteIpPrefix(matchBuilder, null,
+                                MatchUtils.iPv4PrefixFromIPv4Address(dstAddress));
+                    } else if (null != portSecurityRule.getSecurityRuleRemoteIpPrefix()) {
+                        flowId = flowId + portSecurityRule.getSecurityRuleRemoteIpPrefix();
+                        if (isIpv6) {
+                            matchBuilder = MatchUtils.addRemoteIpv6Prefix(matchBuilder, null,
+                                    new Ipv6Prefix(portSecurityRule.getSecurityRuleRemoteIpPrefix()));
+                        } else {
+                            if (!portSecurityRule.getSecurityRuleRemoteIpPrefix().contains("/0")) {
+                                matchBuilder = MatchUtils.addRemoteIpPrefix(matchBuilder, null,
+                                        new Ipv4Prefix(portSecurityRule.getSecurityRuleRemoteIpPrefix()));
+                            }
                         }
                     }
-                }
-                flowId = flowId + "_Permit";
-                NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
-                FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowId, priority, matchBuilder, getTable());
-                addInstructionWithConntrackCommit(flowBuilder, false);
-                syncFlow(flowBuilder ,nodeBuilder, write);
+                    flowId = flowId + "_Permit";
+                    NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
+                    FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowId, priority, matchBuilder, getTable());
+                    addInstructionWithConntrackCommit(flowBuilder, false);
+                    syncFlow(flowBuilder, nodeBuilder, write);
+                    break;
             }
         }
     }
index 2eb144fe2d5b054ed8067eb1b4839b0c2df2ed17..2bb5db3926e52e612afd491b1ea92af27cdb2d69 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 - 2016 Red Hat, Inc. and others. All rights reserved.
+ * Copyright © 2014, 2017 Red Hat, Inc. and others. All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -229,54 +229,60 @@ public class IngressAclService extends AbstractServiceInstance implements Ingres
                 portSecurityRule.setSecurityRuleProtocol(null);
             }
         } else {
-            if (portSecurityRule.getSecurityRuleProtocol().equals(MatchUtils.TCP_PROTOCOL)) {
-                portSecurityRule.setSecurityRulePortMin(PORT_RANGE_MIN);
-                portSecurityRule.setSecurityRulePortMax(PORT_RANGE_MAX);
-                ingressAclTcp(dpidLong, segmentationId, dstMac, portSecurityRule, srcAddress,
-                        write, Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, false);
-            } else if (portSecurityRule.getSecurityRuleProtocol().equals(MatchUtils.UDP_PROTOCOL)) {
-                portSecurityRule.setSecurityRulePortMin(PORT_RANGE_MIN);
-                portSecurityRule.setSecurityRulePortMax(PORT_RANGE_MAX);
-                ingressAclUdp(dpidLong, segmentationId, dstMac, portSecurityRule, srcAddress,
-                        write, Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, false);
-            } else if (portSecurityRule.getSecurityRuleProtocol().equals(MatchUtils.ICMP_PROTOCOL)) {
-                ingressAclIcmp(dpidLong, segmentationId, dstMac, portSecurityRule, srcAddress,
-                        write, Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, false);
-            } else {
-                MatchBuilder matchBuilder = new MatchBuilder();
-                String flowId = "Ingress_Other_" + segmentationId + "_" + dstMac + "_";
-                matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder,null,dstMac,MatchUtils.ETHERTYPE_IPV4);
-                short proto = 0;
-                try {
-                    Integer protocol = new Integer(portSecurityRule.getSecurityRuleProtocol());
-                    proto = protocol.shortValue();
-                    flowId = flowId + proto;
-                } catch (NumberFormatException e) {
-                    LOG.error("Protocol vlaue conversion failure", e);
-                }
-                matchBuilder = MatchUtils.createIpProtocolAndEthMatch(matchBuilder, proto, null, dstMac);
-                if (null != srcAddress) {
-                    flowId = flowId + srcAddress;
-                    matchBuilder = MatchUtils.addRemoteIpPrefix(matchBuilder,
-                                                                MatchUtils.iPv4PrefixFromIPv4Address(srcAddress), null);
-                } else if (null != portSecurityRule.getSecurityRuleRemoteIpPrefix()) {
-                    flowId = flowId + portSecurityRule.getSecurityRuleRemoteIpPrefix();
-                    if(isIpv6) {
-                        matchBuilder = MatchUtils.addRemoteIpv6Prefix(matchBuilder,null,
-                                new Ipv6Prefix(portSecurityRule.getSecurityRuleRemoteIpPrefix()));
-                    } else {
-                        if (!portSecurityRule.getSecurityRuleRemoteIpPrefix().contains("/0")) {
-                            matchBuilder = MatchUtils.addRemoteIpPrefix(matchBuilder,
-                                    new Ipv4Prefix(portSecurityRule.getSecurityRuleRemoteIpPrefix()),null);
+            switch (portSecurityRule.getSecurityRuleProtocol()) {
+                case MatchUtils.TCP_PROTOCOL:
+                    portSecurityRule.setSecurityRulePortMin(PORT_RANGE_MIN);
+                    portSecurityRule.setSecurityRulePortMax(PORT_RANGE_MAX);
+                    ingressAclTcp(dpidLong, segmentationId, dstMac, portSecurityRule, srcAddress,
+                            write, Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, false);
+                    break;
+                case MatchUtils.UDP_PROTOCOL:
+                    portSecurityRule.setSecurityRulePortMin(PORT_RANGE_MIN);
+                    portSecurityRule.setSecurityRulePortMax(PORT_RANGE_MAX);
+                    ingressAclUdp(dpidLong, segmentationId, dstMac, portSecurityRule, srcAddress,
+                            write, Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, false);
+                    break;
+                case MatchUtils.ICMP_PROTOCOL:
+                    ingressAclIcmp(dpidLong, segmentationId, dstMac, portSecurityRule, srcAddress,
+                            write, Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, false);
+                    break;
+                default:
+                    MatchBuilder matchBuilder = new MatchBuilder();
+                    String flowId = "Ingress_Other_" + segmentationId + "_" + dstMac + "_";
+                    matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder, null, dstMac,
+                            MatchUtils.ETHERTYPE_IPV4);
+                    short proto = 0;
+                    try {
+                        Integer protocol = new Integer(portSecurityRule.getSecurityRuleProtocol());
+                        proto = protocol.shortValue();
+                        flowId = flowId + proto;
+                    } catch (NumberFormatException e) {
+                        LOG.error("Protocol vlaue conversion failure", e);
+                    }
+                    matchBuilder = MatchUtils.createIpProtocolAndEthMatch(matchBuilder, proto, null, dstMac);
+                    if (null != srcAddress) {
+                        flowId = flowId + srcAddress;
+                        matchBuilder = MatchUtils.addRemoteIpPrefix(matchBuilder,
+                                MatchUtils.iPv4PrefixFromIPv4Address(srcAddress), null);
+                    } else if (null != portSecurityRule.getSecurityRuleRemoteIpPrefix()) {
+                        flowId = flowId + portSecurityRule.getSecurityRuleRemoteIpPrefix();
+                        if (isIpv6) {
+                            matchBuilder = MatchUtils.addRemoteIpv6Prefix(matchBuilder, null,
+                                    new Ipv6Prefix(portSecurityRule.getSecurityRuleRemoteIpPrefix()));
+                        } else {
+                            if (!portSecurityRule.getSecurityRuleRemoteIpPrefix().contains("/0")) {
+                                matchBuilder = MatchUtils.addRemoteIpPrefix(matchBuilder,
+                                        new Ipv4Prefix(portSecurityRule.getSecurityRuleRemoteIpPrefix()), null);
+                            }
                         }
                     }
-                }
-                flowId = flowId + "_Permit";
-                NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
-                FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowId, protoPortMatchPriority,
-                                                                      matchBuilder, getTable());
-                addInstructionWithConntrackCommit(flowBuilder, false);
-                syncFlow(flowBuilder ,nodeBuilder, write);
+                    flowId = flowId + "_Permit";
+                    NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
+                    FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowId, protoPortMatchPriority,
+                            matchBuilder, getTable());
+                    addInstructionWithConntrackCommit(flowBuilder, false);
+                    syncFlow(flowBuilder, nodeBuilder, write);
+                    break;
             }
         }
     }
index 053399670c437dfe0e2a6d64cd3ee36293483ba0..ebae7789f0c1f8773cba2abbbca4c9892bed4dbd 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2015 HP, Inc. and others. All rights reserved.
+ * Copyright © 2014, 2017 HP, Inc. and others. All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -28,7 +28,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.util.ArrayList;
-import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.HashMap;
@@ -83,11 +82,7 @@ public class SecurityGroupCacheManagerImpl implements ConfigInterface, SecurityG
     @Override
     public void addToCache(String remoteSgUuid, String portUuid, NodeId nodeId) {
         LOG.debug("In addToCache remoteSgUuid:" + remoteSgUuid + " portUuid:" + portUuid);
-        Map<String, NodeId> remoteSgPorts = securityGroupCache.get(remoteSgUuid);
-        if (null == remoteSgPorts) {
-            remoteSgPorts = new HashMap<>();
-            securityGroupCache.put(remoteSgUuid, remoteSgPorts);
-        }
+        Map<String, NodeId> remoteSgPorts = securityGroupCache.computeIfAbsent(remoteSgUuid, k -> new HashMap<>());
         remoteSgPorts.put(portUuid, nodeId);
     }
 
@@ -123,10 +118,7 @@ public class SecurityGroupCacheManagerImpl implements ConfigInterface, SecurityG
             LOG.debug("The port list is empty for security group:" + securityGroupUuid);
             return;
         }
-        Set portSet = portList.entrySet();
-        Iterator itr = portSet.iterator();
-        while(itr.hasNext()) {
-            Map.Entry<String, NodeId> portEntry = (Map.Entry)itr.next();
+        for (Map.Entry<String, NodeId> portEntry : portList.entrySet()) {
             String cachedportUuid = portEntry.getKey();
             NodeId nodeId = portEntry.getValue();
             if (cachedportUuid.equals(port.getID())) {
@@ -137,7 +129,7 @@ public class SecurityGroupCacheManagerImpl implements ConfigInterface, SecurityG
                 cachedport = neutronL3Adapter.getPortFromCleanupCache(cachedportUuid);
                 if (null == cachedport) {
                     LOG.error("In processPortRemoved cachedport port not found in neuton cache:"
-                                + " cachedportUuid:" + cachedportUuid);
+                            + " cachedportUuid:" + cachedportUuid);
                     continue;
                 }
             }
@@ -164,10 +156,7 @@ public class SecurityGroupCacheManagerImpl implements ConfigInterface, SecurityG
             LOG.debug("The port list is empty for security group:" + securityGroupUuid);
             return;
         }
-        Set portSet = portList.entrySet();
-        Iterator itr = portSet.iterator();
-        while(itr.hasNext()) {
-            Map.Entry<String, NodeId> portEntry = (Map.Entry)itr.next();
+        for (Map.Entry<String, NodeId> portEntry : portList.entrySet()) {
             String cachedportUuid = portEntry.getKey();
             NodeId nodeId = portEntry.getValue();
             if (cachedportUuid.equals(port.getID())) {
@@ -178,7 +167,7 @@ public class SecurityGroupCacheManagerImpl implements ConfigInterface, SecurityG
                 cachedport = neutronL3Adapter.getPortFromCleanupCache(cachedportUuid);
                 if (null == cachedport) {
                     LOG.error("In processPortRemoved cachedport port not found in neuton cache:"
-                                + " cachedportUuid:" + cachedportUuid);
+                            + " cachedportUuid:" + cachedportUuid);
                     continue;
                 }
             }
index 0a5854d744c638af5db563bb01b845602931e368..6793ffa7f123dc1e817a94dc4689636508c6456f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Red Hat, Inc. and others. All rights reserved.
+ * Copyright © 2016, 2017 Red Hat, Inc. and others. All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -146,17 +146,12 @@ public final class AclServiceUtils {
      */
     public static <T extends DataObject> Optional<T> read(
             DataBroker broker, LogicalDatastoreType datastoreType, InstanceIdentifier<T> path) {
-
-        Optional<T> result = Optional.absent();
-        ReadOnlyTransaction tx = broker.newReadOnlyTransaction();
-        try {
-            result = tx.read(datastoreType, path).checkedGet();
+        try (ReadOnlyTransaction tx = broker.newReadOnlyTransaction()) {
+            return tx.read(datastoreType, path).checkedGet();
         } catch (ReadFailedException e) {
             LOG.warn("Failed to read InstanceIdentifier {} from {}", path, datastoreType, e);
-        } finally {
-            tx.close();
+            return Optional.absent();
         }
-        return result;
     }
 
     /**
index cbd8ebcbbe5d3b4728bab6f46fa195c9d1b506b8..34d1950abe3302d097826be583029a2cad3f85f8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ * Copyright © 2015, 2017 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -27,9 +27,7 @@ public class BgpCountersBroadcaster extends NotificationBroadcasterSupport imple
     public Map<String, String> retrieveCounterMap() {
         LOGGER.trace("Polled retrieveCounterMap");
         Map<String, String> countersVal = new HashMap<>(bgpCountersMap);
-        Iterator<Map.Entry<String, String>> entries = countersVal.entrySet().iterator();
-        while (entries.hasNext()) {
-            Map.Entry<String, String> entry = entries.next();
+        for (Map.Entry<String, String> entry : countersVal.entrySet()) {
             LOGGER.trace(entry.getKey() + ", Value from MBean= " + entry.getValue());
         }
         return countersVal;
index ef42c3a7760ae6a152ae7045b82adad1b2d351c2..8578d683874d2c2adfe290976e6d381f20089715 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ * Copyright © 2015, 2017 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -13,7 +13,6 @@ import java.math.BigInteger;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.util.Arrays;
-import java.util.Iterator;
 import java.util.List;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
@@ -499,11 +498,9 @@ public class DhcpPktHandler implements PacketProcessingListener {
             return;
         }
         ByteArrayOutputStream result = new ByteArrayOutputStream();
-        Iterator<HostRoutes> iter = hostRoutes.iterator();
-        while (iter.hasNext()) {
-            HostRoutes hostRoute = iter.next();
+        for (HostRoutes hostRoute : hostRoutes) {
             if (hostRoute.getNexthop().getIpv4Address() == null
-                    || hostRoute.getDestination().getIpv4Prefix() == null ) {
+                    || hostRoute.getDestination().getIpv4Prefix() == null) {
                 // we only deal with IPv4 addresses
                 return;
             }
index 8cb6269edd4c948ac6495acc9d2209e258187e8b..71e569d2414d74a87115b18370f6f80d8413ce93 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ * Copyright © 2016, 2017 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -34,11 +34,7 @@ public class ElanL2GwCacheUtils {
         ConcurrentMap<String, L2GatewayDevice> deviceMap = cachedMap.get(elanName);
         if (deviceMap == null) {
             synchronized (ElanL2GwCacheUtils.class) {
-                deviceMap = cachedMap.get(elanName);
-                if (deviceMap == null) {
-                    deviceMap = new ConcurrentHashMap<>();
-                    cachedMap.put(elanName, deviceMap);
-                }
+                deviceMap = cachedMap.computeIfAbsent(elanName, k -> new ConcurrentHashMap<>());
             }
         }
         deviceMap.put(l2GwDevice.getHwvtepNodeId(), l2GwDevice);
index 69cfae232ff02576915940c24afe2bc514a7d381..ae9b9d0039e3bf9d7bfec8cc18c10983e53d5cce 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ * Copyright © 2016, 2017 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -365,7 +365,7 @@ public class HwvtepHAUtil {
      * @return child Switches
      */
     public static Set<InstanceIdentifier<Node>> getPSChildrenIdsForHAPSNode(String psNodId) {
-        if (psNodId.indexOf(PHYSICALSWITCH) < 0) {
+        if (!psNodId.contains(PHYSICALSWITCH)) {
             return Collections.emptySet();
         }
         String nodeId = convertToGlobalNodeId(psNodId);
index 5912ba84963531327073e9aa817295f63b361331..b7b4761be6be018b15f453bb2ffea428c1640a2b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ * Copyright © 2016, 2017 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -85,7 +85,7 @@ public abstract class HwvtepNodeBaseListener implements DataTreeChangeListener<N
             Node original = HwvtepHAUtil.getOriginal(mod);
             if (updated != null && original != null) {
                 if (updated != null && original != null) {
-                    if (nodeId.indexOf(HwvtepHAUtil.PHYSICALSWITCH) < 0) {
+                    if (!nodeId.contains(HwvtepHAUtil.PHYSICALSWITCH)) {
                         onGlobalNodeUpdate(key, updated, original, tx);
                     } else {
                         onPsNodeUpdate(key, updated, original, tx);
@@ -105,7 +105,7 @@ public abstract class HwvtepNodeBaseListener implements DataTreeChangeListener<N
             Node deleted = HwvtepHAUtil.getRemoved(mod);
             String nodeId = key.firstKeyOf(Node.class).getNodeId().getValue();
             if (deleted != null) {
-                if (nodeId.indexOf(HwvtepHAUtil.PHYSICALSWITCH) < 0) {
+                if (!nodeId.contains(HwvtepHAUtil.PHYSICALSWITCH)) {
                     LOG.info("Handle global node delete {}", deleted.getNodeId().getValue());
                     onGlobalNodeDelete(key, deleted, tx);
                 } else {
@@ -127,7 +127,7 @@ public abstract class HwvtepNodeBaseListener implements DataTreeChangeListener<N
             Node node = HwvtepHAUtil.getCreated(mod);
             String nodeId = key.firstKeyOf(Node.class).getNodeId().getValue();
             if (node != null) {
-                if (nodeId.indexOf(HwvtepHAUtil.PHYSICALSWITCH) < 0) {
+                if (!nodeId.contains(HwvtepHAUtil.PHYSICALSWITCH)) {
                     LOG.info("Handle global node add {}", node.getNodeId().getValue());
                     onGlobalNodeAdd(key, node, tx);
                 } else {
index 2e5b9e759bcb29fda0d212d7122ccf680e6baa76..09d0b614451840f6f0964c6fee4695c3e24e0a09 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ * Copyright © 2016, 2017 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -81,12 +81,7 @@ public class HwvtepTerminationPointListener
             return;
         }
         synchronized (HwvtepTerminationPointListener.class) {
-            List<Runnable> list = waitingJobsList.get(key);
-            if (list == null) {
-                list = new ArrayList<>();
-                waitingJobsList.put(key, list);
-            }
-            list.add(runnable);
+            waitingJobsList.computeIfAbsent(key, k -> new ArrayList<>()).add(runnable);
             LOG.debug("added the job to wait list of physical locator {}", key);
         }
     }
index b093bf27b32a4ce67d55fb97a144530f42279229..8224d0b36e36a8222677b9a857d75cdb0cf0e493 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ * Copyright © 2016, 2017 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -297,29 +297,19 @@ public class ElanUtils {
     @SuppressWarnings("checkstyle:IllegalCatch")
     public <T extends DataObject> Optional<T> read(DataBroker broker, LogicalDatastoreType datastoreType,
             InstanceIdentifier<T> path) {
-        ReadOnlyTransaction tx = broker != null ? broker.newReadOnlyTransaction()
-                : this.broker.newReadOnlyTransaction();
-        Optional<T> result = Optional.absent();
-        try {
-            CheckedFuture<Optional<T>, ReadFailedException> checkedFuture = tx.read(datastoreType, path);
-            result = checkedFuture.get();
+        try (ReadOnlyTransaction tx = broker != null ? broker.newReadOnlyTransaction()
+                : this.broker.newReadOnlyTransaction()) {
+            return tx.read(datastoreType, path).get();
         } catch (Exception e) {
             throw new RuntimeException(e);
-        } finally {
-            tx.close();
         }
-
-        return result;
     }
 
     public <T extends DataObject> Optional<T> read2(LogicalDatastoreType datastoreType, InstanceIdentifier<T> path)
             throws ReadFailedException {
-        ReadOnlyTransaction tx = broker.newReadOnlyTransaction();
-        try {
+        try (ReadOnlyTransaction tx = broker.newReadOnlyTransaction()) {
             CheckedFuture<Optional<T>, ReadFailedException> checkedFuture = tx.read(datastoreType, path);
             return checkedFuture.checkedGet();
-        } finally {
-            tx.close();
         }
     }
 
index f9920a9578c55d146c60c68a1156dd465d791804..9786da41aad030d9bfeccb5c770bfe4b2b0736bb 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ * Copyright © 2016, 2017 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -9,6 +9,7 @@ package org.opendaylight.netvirt.elan.l2gw.nodehandlertest;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.stream.Collectors;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentationBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalSwitchRef;
@@ -22,7 +23,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hw
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.SwitchesKey;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
 /**
@@ -102,11 +102,10 @@ public class GlobalAugmentationHelper {
     //physicallocators
     public static void addGlobalTerminationPoints(NodeBuilder nodeBuilder, InstanceIdentifier<Node> nodeIid,
                                                   List<String> globalTerminationPointIp) {
-        List<TerminationPoint> terminationPoints = new ArrayList<>();
-        for (int i = 0; i < globalTerminationPointIp.size(); i++) {
-            terminationPoints.add(TestBuilders.buildTerminationPoint(nodeIid, globalTerminationPointIp.get(i)));
-        }
-        nodeBuilder.setTerminationPoint(terminationPoints);
+        nodeBuilder.setTerminationPoint(
+                globalTerminationPointIp.stream()
+                        .map(ip -> TestBuilders.buildTerminationPoint(nodeIid, ip))
+                        .collect(Collectors.toList()));
     }
 
     public static void addSwitches(HwvtepGlobalAugmentationBuilder augmentationBuilder, InstanceIdentifier<Node> psId) {
index 99499239901b5ed6b664ff301ce34360b02141b1..976c923d260c580b08f7a84f7bc242f9af09d33d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ * Copyright © 2016, 2017 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -10,6 +10,7 @@ package org.opendaylight.netvirt.elan.l2gw.nodehandlertest;
 import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.OPERATIONAL;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 import java.util.UUID;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
@@ -99,12 +100,7 @@ public class NodeConnectedHandlerUtils {
     }
 
     public List<String> getData(String data) {
-        String[] dataArray = data.split(",");
-        List<String> logicalSwitch = new ArrayList<>();
-        for (int i = 0; i < dataArray.length; i++) {
-            logicalSwitch.add(dataArray[i]);
-        }
-        return logicalSwitch;
+        return Arrays.asList(data.split(","));
     }
 
     public static Uuid getUUid(String key) {
index cd47e98e601be540de79db748f017e7583b12fa0..1506dd1f04d6a347e7df3644d6a010cd2623f9de 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ * Copyright © 2015, 2017 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -627,26 +627,31 @@ public class NexthopManager implements AutoCloseable {
 
     private ConfTransportTypeL3vpn createConfTransportType(String type) {
         ConfTransportTypeL3vpn confTransType;
-        if (type.equals(ITMConstants.TUNNEL_TYPE_GRE)) {
-            confTransType = new ConfTransportTypeL3vpnBuilder().setTransportType(TunnelTypeGre.class).build();
-            LOG.trace("Setting the confTransportType to GRE.");
-        } else if (type.equals(ITMConstants.TUNNEL_TYPE_VXLAN)) {
-            confTransType = new ConfTransportTypeL3vpnBuilder().setTransportType(TunnelTypeVxlan.class).build();
-            LOG.trace("Setting the confTransportType to VxLAN.");
-        } else {
-            LOG.trace("Invalid transport type {} passed to Config DS ", type);
-            confTransType = null;
+        switch (type) {
+            case ITMConstants.TUNNEL_TYPE_GRE:
+                confTransType = new ConfTransportTypeL3vpnBuilder().setTransportType(TunnelTypeGre.class).build();
+                LOG.trace("Setting the confTransportType to GRE.");
+                break;
+            case ITMConstants.TUNNEL_TYPE_VXLAN:
+                confTransType = new ConfTransportTypeL3vpnBuilder().setTransportType(TunnelTypeVxlan.class).build();
+                LOG.trace("Setting the confTransportType to VxLAN.");
+                break;
+            default:
+                LOG.trace("Invalid transport type {} passed to Config DS ", type);
+                confTransType = null;
+                break;
         }
         return confTransType;
     }
 
     public Class<? extends TunnelTypeBase> getReqTunType(String transportType) {
-        if (transportType.equals("VXLAN")) {
-            return TunnelTypeVxlan.class;
-        } else if (transportType.equals("GRE")) {
-            return TunnelTypeGre.class;
-        } else {
-            return TunnelTypeMplsOverGre.class;
+        switch (transportType) {
+            case "VXLAN":
+                return TunnelTypeVxlan.class;
+            case "GRE":
+                return TunnelTypeGre.class;
+            default:
+                return TunnelTypeMplsOverGre.class;
         }
     }
 
index a58265995cea1a0cbc214a3ae15b3f4c2765a00f..661c4858c41ba275a860a626f28fe76d3f174627 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Dell Inc. and others.  All rights reserved.
+ * Copyright © 2015, 2017 Dell Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -8,9 +8,7 @@
 
 package org.opendaylight.netvirt.ipv6service;
 
-import java.util.Collection;
 import java.util.HashMap;
-import java.util.Iterator;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -81,25 +79,16 @@ public class VirtualRouter  {
     }
 
     public void removeSelf() {
-        Collection<VirtualPort> intfs = interfaces.values();
-
-        Iterator itr = intfs.iterator();
-        while (itr.hasNext()) {
-            VirtualPort intf = (VirtualPort) itr.next();
+        for (VirtualPort intf : interfaces.values()) {
             if (intf != null) {
                 intf.setRouter(null);
             }
         }
 
-        Collection<VirtualSubnet> snets = subnets.values();
-
-        Iterator itr2 = snets.iterator();
-        while (itr2.hasNext()) {
-            VirtualSubnet snet = (VirtualSubnet) itr2.next();
+        for (VirtualSubnet snet : subnets.values()) {
             if (snet != null) {
                 snet.setRouter(null);
             }
         }
-        return;
     }
 }
index 3624ed57f4acac58a641482c395acc4d0a71a576..84ec72caeed1d6dc861041e79c572d60a2d8b217 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Dell Inc. and others.  All rights reserved.
+ * Copyright © 2015, 2017 Dell Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -8,9 +8,7 @@
 
 package org.opendaylight.netvirt.ipv6service;
 
-import java.util.Collection;
 import java.util.HashMap;
-import java.util.Iterator;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
@@ -138,11 +136,7 @@ public class VirtualSubnet  {
     }
 
     public void removeSelf() {
-        Collection<VirtualPort> intfs = interfaces.values();
-
-        Iterator itr = intfs.iterator();
-        while (itr.hasNext()) {
-            VirtualPort intf = (VirtualPort) itr.next();
+        for (VirtualPort intf : interfaces.values()) {
             if (intf != null) {
                 intf.removeSubnetInfo(subnetUUID);
             }
@@ -151,6 +145,5 @@ public class VirtualSubnet  {
         if (router != null) {
             router.removeSubnet(this);
         }
-        return;
     }
 }
index 7adebfafbff7a4526f12ebfa9b13e911b54636c6..f6d894fbef2569f8dd96b0603c23af4ad28a708e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Red Hat, Inc. and others.  All rights reserved.
+ * Copyright © 2016, 2017 Red Hat, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -95,16 +95,11 @@ public class Ipv6ServiceUtils {
      */
     public static <T extends DataObject> Optional<T> read(DataBroker broker, LogicalDatastoreType datastoreType,
                                                           InstanceIdentifier<T> path) {
-        ReadOnlyTransaction tx = broker.newReadOnlyTransaction();
-        Optional<T> result = Optional.absent();
-        try {
-            result = tx.read(datastoreType, path).get();
+        try (ReadOnlyTransaction tx = broker.newReadOnlyTransaction()) {
+            return tx.read(datastoreType, path).get();
         } catch (InterruptedException | ExecutionException e) {
             throw new RuntimeException(e);
-        } finally {
-            tx.close();
         }
-        return result;
     }
 
     /**
index d4c2509bd9693440ebc554651d00ce20fe507a39..259bade7ddea1253e527959d7f8248930a7064b3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Red Hat, Inc. and others.  All rights reserved.
+ * Copyright © 2016, 2017 Red Hat, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -42,11 +42,7 @@ public class PortInfo {
     }
 
     public PortIp allocateFixedIp(int ipVersion, String ipPfx, String subnetId) {
-        PortIp portIp = fixedIpList.get(ipPfx);
-        if (portIp == null) {
-            portIp = new PortIp(ipVersion, ipPfx, subnetId);
-            fixedIpList.put(ipPfx, portIp);
-        }
+        PortIp portIp = fixedIpList.computeIfAbsent(ipPfx, k -> new PortIp(ipVersion, ipPfx, subnetId));
 
         if (NetvirtITConstants.IPV4 == ipVersion) {
             portIp.setFixedIp(ipFor(ipPfx, ofPort));
index f05af99793b939661074b6b2d12e1d9840b89a75..bb0fd29706e6c74befb59132d90d1ab7d15ec307 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ * Copyright © 2015, 2017 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -12,7 +12,6 @@ import static org.opendaylight.netvirt.neutronvpn.NeutronvpnUtils.buildfloatingI
 import com.google.common.base.Optional;
 import com.google.common.util.concurrent.ListenableFuture;
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.List;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
@@ -233,13 +232,7 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
         List<FixedIps> oldIPs = (original.getFixedIps() != null) ? original.getFixedIps() : new ArrayList<>();
         List<FixedIps> newIPs = (update.getFixedIps() != null) ? update.getFixedIps() : new ArrayList<>();
         if (!oldIPs.equals(newIPs)) {
-            Iterator<FixedIps> iterator = newIPs.iterator();
-            while (iterator.hasNext()) {
-                FixedIps ip = iterator.next();
-                if (oldIPs.remove(ip)) {
-                    iterator.remove();
-                }
-            }
+            newIPs.removeIf(oldIPs::remove);
             handleNeutronPortUpdated(original, update);
         }
         if (NeutronConstants.DEVICE_OWNER_GATEWAY_INF.equals(update.getDeviceOwner())) {
index 8df269c66105cc7ae7054fc7aa1c8e8e32a4a25d..484697ab9a601833ea0034d3b46b6ab4596c2c86 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ * Copyright © 2016, 2017 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -10,7 +10,6 @@ package org.opendaylight.netvirt.neutronvpn;
 import com.google.common.base.Optional;
 import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
@@ -102,13 +101,7 @@ public class NeutronRouterChangeListener extends AsyncDataTreeChangeListenerBase
         List<Routes> oldRoutes = (original.getRoutes() != null) ? original.getRoutes() : new ArrayList<>();
         List<Routes> newRoutes = (update.getRoutes() != null) ? update.getRoutes() : new ArrayList<>();
         if (!oldRoutes.equals(newRoutes)) {
-            Iterator<Routes> iterator = newRoutes.iterator();
-            while (iterator.hasNext()) {
-                Routes route = iterator.next();
-                if (oldRoutes.remove(route)) {
-                    iterator.remove();
-                }
-            }
+            newRoutes.removeIf(oldRoutes::remove);
 
             handleChangedRoutes(vpnId, newRoutes, NwConstants.ADD_FLOW);
 
index 24867756d2a42667e12ffca7ae500ac586724a82..406fd815734ebfbf1e23a332094043049ddc400d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ * Copyright © 2015, 2017 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -1309,11 +1309,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                 }
                 LOG.trace("Adding extra route for destination {} onto vpn {} with nexthop {} ", destination,
                         vpnId.getValue(), nextHop);
-                List<String> hops = adjMap.get(destination);
-                if (hops == null) {
-                    hops = new ArrayList<>();
-                    adjMap.put(destination, hops);
-                }
+                List<String> hops = adjMap.computeIfAbsent(destination, k -> new ArrayList<>());
                 if (!hops.contains(nextHop)) {
                     hops.add(nextHop);
                 }
index e58b3b81bc2d3b6e2192d9d92a86441de68567e6..d257580c908eaa7d628a2e9e79654d0cd37ae51c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ * Copyright © 2016, 2017 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -867,12 +867,7 @@ public class NeutronvpnUtils {
         subnetMap.put(subnet.getUuid(), subnet);
         IpAddress gatewayIp = subnet.getGatewayIp();
         if (gatewayIp != null) {
-            Set<Uuid> gwIps = subnetGwIpMap.get(gatewayIp);
-            if (gwIps == null) {
-                gwIps = Sets.newConcurrentHashSet();
-                subnetGwIpMap.put(gatewayIp, gwIps);
-            }
-            gwIps.add(subnet.getUuid());
+            subnetGwIpMap.computeIfAbsent(gatewayIp, k -> Sets.newConcurrentHashSet()).add(subnet.getUuid());
         }
     }
 
index 3afcb254e53dc80b111403cbf5611093eea2fc2c..b51946635cae2cbe7905546d4f43aee7fe5ca02d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright © 2016, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -46,9 +46,7 @@ public class ArpMonitorStopTask implements Callable<List<ListenableFuture<Void>>
         final List<ListenableFuture<Void>> futures = new ArrayList<>();
         WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
         java.util.Optional<Long> monitorIdOptional = AlivenessMonitorUtils.getMonitorIdFromInterface(macEntry);
-        if (monitorIdOptional.isPresent()) {
-            AlivenessMonitorUtils.stopArpMonitoring(alivenessManager, monitorIdOptional.get());
-        }
+        monitorIdOptional.ifPresent(aLong -> AlivenessMonitorUtils.stopArpMonitoring(alivenessManager, aLong));
         removeMipAdjacency(macEntry.getIpAddress().getHostAddress(),
                 macEntry.getVpnName(), macEntry.getInterfaceName(), tx);
         VpnUtil.removeLearntVpnVipToPort(dataBroker, macEntry.getVpnName(),
index 54371b6ad35c0a1823db54f8ee3aa74fff49776a..94a7073df5e5e25712774109457e38120ddafa85 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ * Copyright © 2016, 2017 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -309,9 +309,7 @@ public class TunnelInterfaceStateListener extends AsyncDataTreeChangeListenerBas
             }
 
             //Iterate over the VpnId-to-Rd map.
-            Iterator<Map.Entry<Long, String>> entries = vpnIdRdMap.entrySet().iterator();
-            while (entries.hasNext()) {
-                Map.Entry<Long, String> entry = entries.next();
+            for (Map.Entry<Long, String> entry : vpnIdRdMap.entrySet()) {
                 Long vpnId = entry.getKey();
                 rd = entry.getValue();
                 if ((tunnelAction == TunnelAction.TUNNEL_EP_ADD)
index 91c1fb2df2c937229354a8ccc4ddc7a79a70c317..2c6a770f912d677668480943c9a4fe123be8d8b6 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ * Copyright © 2016, 2017 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -72,12 +72,7 @@ public class VpnOpDataSyncer {
         List<Runnable> notifieeList = null;
         try {
             synchronized (listenerMap) {
-                notifieeList = listenerMap.get(vpnName);
-                if (notifieeList == null) {
-                    notifieeList = new ArrayList<>();
-                    listenerMap.put(vpnName, notifieeList);
-                }
-                notifieeList.add(notifyTask);
+                listenerMap.computeIfAbsent(vpnName, k -> new ArrayList<>()).add(notifyTask);
             }
 
             synchronized (notifyTask) {
index 205608587065640c58557f52dd99a1411134bd3e..74504bcd7a2986ed0794f0285fc13649106d15d8 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright © 2016, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -771,20 +771,12 @@ public class VpnUtil {
         };
 
     public static <T extends DataObject> Optional<T> read(DataBroker broker, LogicalDatastoreType datastoreType,
-        InstanceIdentifier<T> path) {
-
-        ReadOnlyTransaction tx = broker.newReadOnlyTransaction();
-
-        Optional<T> result = Optional.absent();
-        try {
-            result = tx.read(datastoreType, path).get();
+                                                          InstanceIdentifier<T> path) {
+        try (ReadOnlyTransaction tx = broker.newReadOnlyTransaction()) {
+            return tx.read(datastoreType, path).get();
         } catch (InterruptedException | ExecutionException e) {
             throw new RuntimeException(e);
-        } finally {
-            tx.close();
         }
-
-        return result;
     }
 
     public static <T extends DataObject> void asyncUpdate(DataBroker broker, LogicalDatastoreType datastoreType,