aclservice: drop nullToEmpty and reqNonNullOrElse 14/79914/3
authorStephen Kitt <skitt@redhat.com>
Fri, 25 Jan 2019 08:49:12 +0000 (09:49 +0100)
committerSam Hague <shague@redhat.com>
Sat, 26 Jan 2019 13:26:54 +0000 (13:26 +0000)
Change-Id: Ie843944d23f8ebb5b8be09852ac43a503afb97b3
Signed-off-by: Stephen Kitt <skitt@redhat.com>
aclservice/impl/src/main/java/org/opendaylight/netvirt/aclservice/stats/AclLiveStatisticsHelper.java
aclservice/impl/src/main/java/org/opendaylight/netvirt/aclservice/stats/AclLiveStatisticsRpcServiceImpl.java
aclservice/impl/src/main/java/org/opendaylight/netvirt/aclservice/utils/AclDataUtil.java

index 941a8cb620c9c75574fc360b43bd576d6c2f2f21..955e59b20cb838973d949d3ea38a204c9d7b1efb 100644 (file)
@@ -10,16 +10,15 @@ package org.opendaylight.netvirt.aclservice.stats;
 
 import java.math.BigInteger;
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
+import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.genius.mdsalutil.MetaDataUtil;
 import org.opendaylight.genius.mdsalutil.NwConstants;
 import org.opendaylight.netvirt.aclservice.utils.AclConstants;
-import org.opendaylight.netvirt.aclservice.utils.AclDataUtil;
 import org.opendaylight.netvirt.aclservice.utils.AclServiceUtils;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatisticsInputBuilder;
@@ -72,14 +71,14 @@ public final class AclLiveStatisticsHelper {
      * @param dataBroker the data broker
      * @return the acl port stats
      */
-    public static List<AclPortStats> getAclPortStats(Direction direction, @Nullable List<String> interfaceNames,
+    public static List<AclPortStats> getAclPortStats(Direction direction, @Nonnull List<String> interfaceNames,
             OpendaylightDirectStatisticsService odlDirectStatsService, DataBroker dataBroker) {
         LOG.trace("Get ACL port stats for direction {} and interfaces {}", direction, interfaceNames);
         List<AclPortStats> lstAclPortStats = new ArrayList<>();
 
         FlowCookie aclDropFlowCookieMask = new FlowCookie(COOKIE_ACL_DROP_FLOW_MASK);
 
-        for (String interfaceName : AclDataUtil.requireNonNullElse(interfaceNames, Collections.<String>emptyList())) {
+        for (String interfaceName : interfaceNames) {
             AclPortStatsBuilder aclStatsBuilder = new AclPortStatsBuilder().setInterfaceName(interfaceName);
 
             Interface interfaceState = AclServiceUtils.getInterfaceStateFromOperDS(dataBroker, interfaceName);
index 72361e73f818dcbc1bbfcfbe360110db35e07dab..a333d72c8732bbbfad758e171360a63fe8aeb70c 100644 (file)
@@ -10,9 +10,11 @@ package org.opendaylight.netvirt.aclservice.stats;
 
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
+import java.util.ArrayList;
 import java.util.List;
 import javax.inject.Inject;
 import javax.inject.Singleton;
+import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.OpendaylightDirectStatisticsService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.acl.live.statistics.rev161129.AclLiveStatisticsService;
@@ -74,8 +76,10 @@ public class AclLiveStatisticsRpcServiceImpl implements AclLiveStatisticsService
         // Default direction is Both
         Direction direction = input.getDirection() == null ? Direction.Both : input.getDirection();
 
-        List<AclPortStats> lstAclInterfaceStats = AclLiveStatisticsHelper.getAclPortStats(direction,
-                input.getInterfaceNames(), this.odlDirectStatsService, this.dataBroker);
+        @Nullable List<String> interfaceNames = input.getInterfaceNames();
+        List<AclPortStats> lstAclInterfaceStats =
+            interfaceNames != null ? AclLiveStatisticsHelper.getAclPortStats(direction, interfaceNames,
+                this.odlDirectStatsService, this.dataBroker) : new ArrayList<>();
 
         GetAclPortStatisticsOutputBuilder output =
                 new GetAclPortStatisticsOutputBuilder().setAclPortStats(lstAclInterfaceStats);
index dd4ab5d387e02ef505cabd98b1b72bbe8d710c56..1cfa4ef9691b0225da8577026bd602fcf58fcd74 100644 (file)
@@ -8,8 +8,6 @@
 
 package org.opendaylight.netvirt.aclservice.utils;
 
-import static java.util.Objects.requireNonNull;
-
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableMap.Builder;
 import java.math.BigInteger;
@@ -247,10 +245,4 @@ public class AclDataUtil implements AclDataCache {
     public Map<String, Acl> getAclMap() {
         return ImmutableMap.copyOf(aclMap);
     }
-
-    // Use Objects.requireNonNullElse instead with JDK9+
-    @Nonnull
-    public static <T> T requireNonNullElse(@Nullable T obj, @Nonnull T defaultObj) {
-        return obj != null ? obj : requireNonNull(defaultObj);
-    }
 }