Fix modernizer warnings in sal-distributed-eos 97/94697/1
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 21 Jan 2021 16:08:08 +0000 (17:08 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 21 Jan 2021 16:08:36 +0000 (17:08 +0100)
There are just two violations, fix them up and enable enforcement.

Change-Id: I07e38270d0b24fa5ca4a701808e2b20c0b820803
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/sal-distributed-eos/pom.xml
opendaylight/md-sal/sal-distributed-eos/src/main/java/org/opendaylight/controller/cluster/entityownership/selectionstrategy/LeastLoadedCandidateSelectionStrategy.java

index 6811e0ec114c067b4ae2bd7d447f1b3abffabfa7..73e970bc3472122f9c691f75dbe0f2bf5ab99f43 100644 (file)
   <artifactId>sal-distributed-eos</artifactId>
   <packaging>bundle</packaging>
 
   <artifactId>sal-distributed-eos</artifactId>
   <packaging>bundle</packaging>
 
-  <properties>
-    <!-- FIXME: Remove this -->
-    <odlparent.modernizer.enforce>false</odlparent.modernizer.enforce>
-  </properties>
-
   <dependencies>
     <dependency>
       <groupId>org.opendaylight.mdsal</groupId>
   <dependencies>
     <dependency>
       <groupId>org.opendaylight.mdsal</groupId>
index 2ef4426dddc3c85bd67dd833fcabc50d1e5762fa..fc53f9545e2bf1b42c3073d82a1b93c402136686 100644 (file)
@@ -7,9 +7,10 @@
  */
 package org.opendaylight.controller.cluster.entityownership.selectionstrategy;
 
  */
 package org.opendaylight.controller.cluster.entityownership.selectionstrategy;
 
+import static com.google.common.base.Preconditions.checkArgument;
+import static java.util.Objects.requireNonNullElse;
+
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.MoreObjects;
-import com.google.common.base.Preconditions;
 import com.google.common.base.Strings;
 import java.util.Collection;
 import java.util.HashMap;
 import com.google.common.base.Strings;
 import java.util.Collection;
 import java.util.HashMap;
@@ -31,17 +32,17 @@ public class LeastLoadedCandidateSelectionStrategy extends AbstractEntityOwnerSe
 
     @Override
     public String newOwner(final String currentOwner, final Collection<String> viableCandidates) {
 
     @Override
     public String newOwner(final String currentOwner, final Collection<String> viableCandidates) {
-        Preconditions.checkArgument(viableCandidates.size() > 0);
+        checkArgument(viableCandidates.size() > 0);
         String leastLoadedCandidate = null;
         long leastLoadedCount = Long.MAX_VALUE;
 
         if (!Strings.isNullOrEmpty(currentOwner)) {
         String leastLoadedCandidate = null;
         long leastLoadedCount = Long.MAX_VALUE;
 
         if (!Strings.isNullOrEmpty(currentOwner)) {
-            long localVal = MoreObjects.firstNonNull(localStatistics.get(currentOwner), 0L);
+            long localVal = requireNonNullElse(localStatistics.get(currentOwner), 0L);
             localStatistics.put(currentOwner, localVal - 1);
         }
 
         for (String candidateName : viableCandidates) {
             localStatistics.put(currentOwner, localVal - 1);
         }
 
         for (String candidateName : viableCandidates) {
-            long val = MoreObjects.firstNonNull(localStatistics.get(candidateName), 0L);
+            long val = requireNonNullElse(localStatistics.get(candidateName), 0L);
             if (val < leastLoadedCount) {
                 leastLoadedCount = val;
                 leastLoadedCandidate = candidateName;
             if (val < leastLoadedCount) {
                 leastLoadedCount = val;
                 leastLoadedCandidate = candidateName;