Avoid comparing objects using == 95/81095/1
authorStephen Kitt <skitt@redhat.com>
Thu, 21 Mar 2019 15:00:22 +0000 (16:00 +0100)
committerStephen Kitt <skitt@redhat.com>
Thu, 21 Mar 2019 15:00:22 +0000 (16:00 +0100)
A number of BigInteger instances are compared using == or !=; this
patch uses .equals() or variants thereof instead.

Change-Id: I3ac654b0dd5d255304bca93d6fbc4cdbfec05514
Signed-off-by: Stephen Kitt <skitt@redhat.com>
fibmanager/impl/src/main/java/org/opendaylight/netvirt/fibmanager/BaseVrfEntryHandler.java
fibmanager/impl/src/main/java/org/opendaylight/netvirt/fibmanager/BgpRouteVrfEntryHandler.java
natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/ha/SnatCentralizedSwitchChangeListener.java
natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/ha/WeightedCentralizedSwitchScheduler.java
natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/AbstractSnatService.java
natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/Ipv6ForwardingService.java

index 05b5b1af09ba9043ac4eacdc26fc74c37cc76675..afe659fff58a775c93e7bd51383624315dfc3a09 100644 (file)
@@ -510,7 +510,7 @@ public class BaseVrfEntryHandler implements AutoCloseable {
                 vrfEntry.getDestPrefix(), vpnId, localDpnId, remoteDpnId);
         String rd = vrfTableKey.getRouteDistinguisher();
 
-        if (localDpnId != null && localDpnId != BigInteger.ZERO) {
+        if (localDpnId != null && !BigInteger.ZERO.equals(localDpnId)) {
             // localDpnId is not known when clean up happens for last vm for a vpn on a dpn
             if (extraRouteOptional.isPresent()) {
                 nextHopManager.deleteLoadBalancingNextHop(vpnId, remoteDpnId, vrfEntry.getDestPrefix());
index 1c0d62db6d9a6cdec85f4052a68e6e69de4f7a67..59fdbf1e2cba976a0031b10410f2bd99397893eb 100644 (file)
@@ -347,7 +347,7 @@ public class BgpRouteVrfEntryHandler extends BaseVrfEntryHandler
                 vrfEntry.getDestPrefix(), vpnId, localDpnId, remoteDpnId);
         String rd = vrfTableKey.getRouteDistinguisher();
 
-        if (localDpnId != null && localDpnId != BigInteger.ZERO) {
+        if (localDpnId != null && !BigInteger.ZERO.equals(localDpnId)) {
             // localDpnId is not known when clean up happens for last vm for a vpn on a dpn
             if (extraRouteOptional.isPresent()) {
                 nexthopManager.deleteLoadBalancingNextHop(vpnId, remoteDpnId, vrfEntry.getDestPrefix());
index 1b326d2e5ce7e19098f2f13ebda18bf4fb5f8df2..b262e4d4cca093ab5fbeb98abf750c8587e423fb 100644 (file)
@@ -11,8 +11,8 @@ package org.opendaylight.netvirt.natservice.ha;
 import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
 
 import java.math.BigInteger;
-
 import java.time.Duration;
+import java.util.Objects;
 import java.util.concurrent.ExecutionException;
 import javax.annotation.PostConstruct;
 import javax.inject.Inject;
@@ -98,7 +98,7 @@ public class SnatCentralizedSwitchChangeListener
         ListenableFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, confTx -> {
             Routers origRouter = NatUtil.getRoutersFromConfigDS(confTx, origRouterToNaptSwitch.getRouterName());
             Routers updatedRouter = NatUtil.getRoutersFromConfigDS(confTx, updatedRouterToNaptSwitch.getRouterName());
-            if (origPrimarySwitchId != updatedPrimarySwitchId) {
+            if (!Objects.equals(origPrimarySwitchId, updatedPrimarySwitchId)) {
                 if (origRouter != null) {
                     snatServiceManger.notify(confTx, origRouter, null, origPrimarySwitchId, null,
                             SnatServiceManager.Action.CNT_ROUTER_ALL_SWITCH_DISBL);
index 86bf977355494dc7c75f6e6c8715e238b4fab7d5..d0db56e018327bfa13bda4e30fbdf714d2a1ef41 100644 (file)
@@ -12,7 +12,6 @@ import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
 import static org.opendaylight.genius.infra.Datastore.OPERATIONAL;
 
 import com.google.common.base.Optional;
-
 import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -22,11 +21,9 @@ import java.util.Map;
 import java.util.Map.Entry;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ExecutionException;
-
 import javax.annotation.Nullable;
 import javax.inject.Inject;
 import javax.inject.Singleton;
-
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
@@ -94,7 +91,7 @@ public class WeightedCentralizedSwitchScheduler implements CentralizedSwitchSche
     public boolean scheduleCentralizedSwitch(Routers router) {
         String providerNet = NatUtil.getElanInstancePhysicalNetwok(router.getNetworkId().getValue(),dataBroker);
         BigInteger nextSwitchId = getSwitchWithLowestWeight(providerNet);
-        if (nextSwitchId == BigInteger.valueOf(0)) {
+        if (BigInteger.ZERO.equals(nextSwitchId)) {
             LOG.error("In scheduleCentralizedSwitch, unable to schedule the router {} as there is no available switch.",
                     router.getRouterName());
             return false;
@@ -158,7 +155,7 @@ public class WeightedCentralizedSwitchScheduler implements CentralizedSwitchSche
         String providerNet = NatUtil.getElanInstancePhysicalNetwok(router.getNetworkId().getValue(),dataBroker);
         String routerName = router.getRouterName();
         BigInteger primarySwitchId = NatUtil.getPrimaryNaptfromRouterName(dataBroker, routerName);
-        if (primarySwitchId == null || primarySwitchId == BigInteger.valueOf(0)) {
+        if (primarySwitchId == null || BigInteger.ZERO.equals(primarySwitchId)) {
             LOG.info("releaseCentralizedSwitch: NAPT Switch is not allocated for router {}", router.getRouterName());
             return false;
         }
index ed0b368c97f949f2c86ce2155a7fc004e1968121..9d5a52030829153b84505dc8706ef82db4e2d0aa 100644 (file)
@@ -216,7 +216,7 @@ public abstract class AbstractSnatService implements SnatServiceListener {
         List<BigInteger> switches = naptSwitchSelector.getDpnsForVpn(routerName);
         addCentralizedRouter(confTx, routers, primarySwitchId, primarySwitchId);
         for (BigInteger dpnId : switches) {
-            if (primarySwitchId != dpnId) {
+            if (!Objects.equals(primarySwitchId, dpnId)) {
                 addCentralizedRouter(confTx, routers, primarySwitchId, dpnId);
             }
         }
@@ -237,7 +237,7 @@ public abstract class AbstractSnatService implements SnatServiceListener {
         String routerName = routers.getRouterName();
         List<BigInteger> switches = naptSwitchSelector.getDpnsForVpn(routerName);
         for (BigInteger dpnId : switches) {
-            if (primarySwitchId != dpnId) {
+            if (!Objects.equals(primarySwitchId, dpnId)) {
                 removeCentralizedRouter(confTx, routers, primarySwitchId, dpnId);
             }
         }
index f60c274a36849d27509aaab44cd51a9a9683764c..dfe21c9d59630e322d71357d47a2b3b8136a1898 100644 (file)
@@ -14,6 +14,7 @@ import static org.opendaylight.netvirt.natservice.internal.NatUtil.getGroupIdKey
 import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Objects;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
@@ -101,7 +102,7 @@ public class Ipv6ForwardingService implements SnatServiceListener {
          */
         addCentralizedRouter(confTx, routers, primarySwitchId, primarySwitchId);
         for (BigInteger dpnId : switches) {
-            if (primarySwitchId != dpnId) {
+            if (!Objects.equals(primarySwitchId, dpnId)) {
                 addCentralizedRouter(confTx, routers, primarySwitchId, dpnId);
             }
         }
@@ -160,7 +161,7 @@ public class Ipv6ForwardingService implements SnatServiceListener {
          */
         removeCentralizedRouter(confTx, routers, primarySwitchId, primarySwitchId);
         for (BigInteger dpnId : switches) {
-            if (primarySwitchId != dpnId) {
+            if (!Objects.equals(primarySwitchId, dpnId)) {
                 removeCentralizedRouter(confTx, routers, primarySwitchId, dpnId);
             }
         }
@@ -220,7 +221,7 @@ public class Ipv6ForwardingService implements SnatServiceListener {
         if (!routerHasIpv6ExtSubnet(origRouter) && routerHasIpv6ExtSubnet(updatedRouter)) {
             List<BigInteger> switches = naptSwitchSelector.getDpnsForVpn(routerName);
             for (BigInteger dpnId : switches) {
-                if (primarySwitchId != dpnId) {
+                if (!Objects.equals(primarySwitchId, dpnId)) {
                     LOG.info("handleRouterUpdate (non-NAPTSwitch) : Installing flows on switch {} for router {}",
                             dpnId, routerName);
                     addIpv6PsNatMissEntryNonNaptSwitch(confTx, dpnId, routerId, routerName,