Do not use String.toString() 42/35542/3
authorRobert Varga <rovarga@cisco.com>
Mon, 29 Feb 2016 11:36:17 +0000 (12:36 +0100)
committerRobert Varga <rovarga@cisco.com>
Mon, 7 Mar 2016 16:29:38 +0000 (17:29 +0100)
Use Strings.isNullOrEmpty instead of open-coding the check, also add
preconditions for fields and eliminate a String.toString() call.

Change-Id: Ic25a60511514ea623d1d9bdde9675faec8d538f8
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/EntityOwnerChangeListener.java

index d10bc21..fcc325e 100644 (file)
@@ -10,6 +10,8 @@ package org.opendaylight.controller.cluster.datastore.entityownership;
 import static org.opendaylight.controller.cluster.datastore.entityownership.EntityOwnersModel.createEntity;
 import com.google.common.base.Objects;
 import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
 import java.util.Collection;
 import org.opendaylight.controller.md.sal.common.api.clustering.Entity;
 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
@@ -30,13 +32,13 @@ class EntityOwnerChangeListener extends AbstractEntityOwnerChangeListener {
     private final String localMemberName;
     private final EntityOwnershipListenerSupport listenerSupport;
 
-    EntityOwnerChangeListener(String localMemberName, EntityOwnershipListenerSupport listenerSupport) {
-        this.localMemberName = localMemberName;
-        this.listenerSupport = listenerSupport;
+    EntityOwnerChangeListener(final String localMemberName, final EntityOwnershipListenerSupport listenerSupport) {
+        this.localMemberName = Preconditions.checkNotNull(localMemberName);
+        this.listenerSupport = Preconditions.checkNotNull(listenerSupport);
     }
 
     @Override
-    public void onDataTreeChanged(Collection<DataTreeCandidate> changes) {
+    public void onDataTreeChanged(final Collection<DataTreeCandidate> changes) {
         for(DataTreeCandidate change: changes) {
             DataTreeCandidateNode changeRoot = change.getRootNode();
             LeafNode<?> ownerLeaf = (LeafNode<?>) changeRoot.getDataAfter().get();
@@ -56,7 +58,7 @@ class EntityOwnerChangeListener extends AbstractEntityOwnerChangeListener {
             if(!Objects.equal(origOwner, newOwner)) {
                 boolean isOwner = Objects.equal(localMemberName, newOwner);
                 boolean wasOwner = Objects.equal(localMemberName, origOwner);
-                boolean hasOwner = newOwner != null && !newOwner.toString().isEmpty();
+                boolean hasOwner = !Strings.isNullOrEmpty(newOwner);
 
                 Entity entity = createEntity(change.getRootPath());