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 6811e0e..73e970b 100644 (file)
   <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>
index 2ef4426..fc53f95 100644 (file)
@@ -7,9 +7,10 @@
  */
 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.base.MoreObjects;
-import com.google.common.base.Preconditions;
 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) {
-        Preconditions.checkArgument(viableCandidates.size() > 0);
+        checkArgument(viableCandidates.size() > 0);
         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) {
-            long val = MoreObjects.firstNonNull(localStatistics.get(candidateName), 0L);
+            long val = requireNonNullElse(localStatistics.get(candidateName), 0L);
             if (val < leastLoadedCount) {
                 leastLoadedCount = val;
                 leastLoadedCandidate = candidateName;