sfc: drop nullToEmpty and requireNonNullOrElse 22/79922/3
authorStephen Kitt <skitt@redhat.com>
Fri, 25 Jan 2019 08:53:24 +0000 (09:53 +0100)
committerSam Hague <shague@redhat.com>
Sat, 26 Jan 2019 13:29:26 +0000 (13:29 +0000)
Change-Id: I1256c7df73351d8d93f5ee73c20dd9c319859026
Signed-off-by: Stephen Kitt <skitt@redhat.com>
sfc/classifier/impl/src/main/java/org/opendaylight/netvirt/sfc/classifier/providers/GeniusProvider.java
sfc/classifier/impl/src/main/java/org/opendaylight/netvirt/sfc/classifier/utils/SfcUtils.java [deleted file]
sfc/translator/src/main/java/org/opendaylight/netvirt/sfc/translator/SfcTranslatorUtils.java [deleted file]
sfc/translator/src/main/java/org/opendaylight/netvirt/sfc/translator/portchain/NeutronPortChainListener.java

index 6bc689b629187ea4c3b0a5a39d9f9d2aece850b4..a8ea11a0c9d827328db9656a903332e7fe6a1bb6 100644 (file)
@@ -8,8 +8,6 @@
 
 package org.opendaylight.netvirt.sfc.classifier.providers;
 
-import static org.opendaylight.netvirt.sfc.classifier.utils.SfcUtils.nullToEmpty;
-
 import com.google.common.net.InetAddresses;
 import java.math.BigInteger;
 import java.util.Collections;
@@ -274,7 +272,7 @@ public class GeniusProvider {
 
             Class<? extends InterfaceTypeBase> ifType = tp.getInterfaceType();
             if (InterfaceTypeVxlan.class.equals(ifType)) {
-                for (Options tpOption : nullToEmpty(tp.getOptions())) {
+                for (Options tpOption : tp.nonnullOptions()) {
                     // From the VXLAN Tunnels, we want the one with the GPE option set
                     if (OPTION_KEY_REMOTE_IP.equals(tpOption.key().getOption())) {
                         if (OPTION_VALUE_FLOW.equals(tpOption.getValue()) && tp.getOfport() != null) {
diff --git a/sfc/classifier/impl/src/main/java/org/opendaylight/netvirt/sfc/classifier/utils/SfcUtils.java b/sfc/classifier/impl/src/main/java/org/opendaylight/netvirt/sfc/classifier/utils/SfcUtils.java
deleted file mode 100644 (file)
index 61f8ea6..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright © 2018 Red Hat, Inc. and others.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.netvirt.sfc.classifier.utils;
-
-import static java.util.Collections.emptyList;
-
-import java.util.List;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-
-public final class SfcUtils {
-    private SfcUtils() {
-        // Utility class
-    }
-
-    // TODO Replace this with mdsal's DataObjectUtils.nullToEmpty when upgrading to mdsal 3
-    @Nonnull
-    public static <T> List<T> nullToEmpty(final @Nullable List<T> input) {
-        return input != null ? input : emptyList();
-    }
-}
diff --git a/sfc/translator/src/main/java/org/opendaylight/netvirt/sfc/translator/SfcTranslatorUtils.java b/sfc/translator/src/main/java/org/opendaylight/netvirt/sfc/translator/SfcTranslatorUtils.java
deleted file mode 100644 (file)
index 1be3afe..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright © 2018 Red Hat, Inc. and others.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.netvirt.sfc.translator;
-
-import static java.util.Collections.emptyList;
-
-import java.util.List;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-
-public final class SfcTranslatorUtils {
-    private SfcTranslatorUtils() {
-        // Utility class
-    }
-
-    // TODO Replace this with mdsal's DataObjectUtils.nullToEmpty when upgrading to mdsal 3
-    @Nonnull
-    public static <T> List<T> nullToEmpty(final @Nullable List<T> input) {
-        return input != null ? input : emptyList();
-    }
-}
index a7eeb799a31c378c409481a8d9b4e3627a1747a5..ba5216765b951272c845e541dc6fbc86dd5a3fa0 100644 (file)
@@ -8,9 +8,8 @@
 
 package org.opendaylight.netvirt.sfc.translator.portchain;
 
-import static org.opendaylight.netvirt.sfc.translator.SfcTranslatorUtils.nullToEmpty;
-
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -79,11 +78,15 @@ public class NeutronPortChainListener extends DelegatingDataTreeListener<PortCha
      */
     @Override
     public void update(PortChain origPortChain, PortChain updatePortChain) {
-        List<Uuid> oldFcList = new ArrayList<>(nullToEmpty(origPortChain.getFlowClassifiers()));
-        oldFcList.removeAll(nullToEmpty(updatePortChain.getFlowClassifiers()));
-        if (!oldFcList.isEmpty()) {
-            LOG.debug("Removing old list {}", oldFcList);
-            processFlowClassifiers(origPortChain, oldFcList, null, false);
+        List<Uuid> oldFcList = origPortChain.getFlowClassifiers();
+        oldFcList = oldFcList != null ? new ArrayList<>(oldFcList) : new ArrayList<>();
+        @Nullable List<Uuid> newFcList = updatePortChain.getFlowClassifiers();
+        if (oldFcList != null && newFcList != null) {
+            oldFcList.removeAll(newFcList);
+            if (!oldFcList.isEmpty()) {
+                LOG.debug("Removing old list {}", oldFcList);
+                processFlowClassifiers(origPortChain, oldFcList, null, false);
+            }
         }
         processPortChain(updatePortChain);
     }
@@ -109,20 +112,26 @@ public class NeutronPortChainListener extends DelegatingDataTreeListener<PortCha
         List<ServiceFunction> portChainServiceFunctionList = new ArrayList<>();
 
         //Read chain related port pair group from neutron data store
-        for (Uuid ppgUuid : nullToEmpty(newPortChain.getPortPairGroups())) {
-            PortPairGroup ppg = neutronMdsalHelper.getNeutronPortPairGroup(ppgUuid);
-            if (ppg != null) {
-                List<PortPair> portPairList = new ArrayList<>();
-                portPairGroupList.add(ppg);
-                for (Uuid ppUuid : nullToEmpty(ppg.getPortPairs())) {
-                    PortPair pp = neutronMdsalHelper.getNeutronPortPair(ppUuid);
-                    if (pp == null) {
-                        LOG.error("Port pair {} does not exist in the neutron data store", ppUuid);
-                        return;
+        @Nullable List<Uuid> newPortPairGroups = newPortChain.getPortPairGroups();
+        if (newPortPairGroups != null) {
+            for (Uuid ppgUuid : newPortPairGroups) {
+                PortPairGroup ppg = neutronMdsalHelper.getNeutronPortPairGroup(ppgUuid);
+                if (ppg != null) {
+                    List<PortPair> portPairList = new ArrayList<>();
+                    portPairGroupList.add(ppg);
+                    @org.eclipse.jdt.annotation.Nullable List<Uuid> ppgPortPairs = ppg.getPortPairs();
+                    if (ppgPortPairs != null) {
+                        for (Uuid ppUuid : ppgPortPairs) {
+                            PortPair pp = neutronMdsalHelper.getNeutronPortPair(ppUuid);
+                            if (pp == null) {
+                                LOG.error("Port pair {} does not exist in the neutron data store", ppUuid);
+                                return;
+                            }
+                            portPairList.add(pp);
+                        }
                     }
-                    portPairList.add(pp);
+                    groupPortPairsList.put(ppgUuid, portPairList);
                 }
-                groupPortPairsList.put(ppgUuid, portPairList);
             }
         }
 
@@ -173,8 +182,9 @@ public class NeutronPortChainListener extends DelegatingDataTreeListener<PortCha
         // The RSP will automatically be created from the SFP added above.
 
         // Add ACLs from flow classifiers
-        processFlowClassifiers(newPortChain, nullToEmpty(newPortChain.getFlowClassifiers()), sfp.getName().getValue(),
-            true);
+        @Nullable List<Uuid> newFlowClassifiers = newPortChain.getFlowClassifiers();
+        processFlowClassifiers(newPortChain, newFlowClassifiers != null ? newFlowClassifiers : Collections.emptyList(),
+            sfp.getName().getValue(), true);
     }
 
     private void processFlowClassifiers(PortChain pc, @Nonnull List<Uuid> flowClassifiers, @Nullable String sfpName,