Fix mergeable if-the-else statements 05/83705/3
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 16 Aug 2019 13:32:11 +0000 (15:32 +0200)
committerRobert Varga <nite@hq.sk>
Fri, 16 Aug 2019 14:50:43 +0000 (14:50 +0000)
This fixes DTOs to use simple return expressions. While we are in
the area, also optimize toString() methods to lower their footprint.

Change-Id: Ie206c2942c5fb9b6cbbdc2a31d197560559fd660
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/yang/types/NodeWrappedType.java
binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/model/util/generated/type/builder/AbstractTypeMemberBuilder.java
binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/model/util/generated/type/builder/MethodSignatureBuilderImpl.java
binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/model/util/generated/type/builder/MethodSignatureImpl.java
entityownership/mdsal-eos-common-api/src/main/java/org/opendaylight/mdsal/eos/common/api/GenericEntity.java

index 14dcd27af983b909c0be01a9d917db4a677a406f..9d9f67e6c9615562eef04d0e7fb1c9f0497810f7 100644 (file)
@@ -42,10 +42,7 @@ public final class NodeWrappedType extends NodeImpl {
             return false;
         }
         NodeWrappedType nodeWrappedType = (NodeWrappedType) obj;
-        if (!wrappedType.equals(nodeWrappedType.wrappedType)) {
-            return false;
-        }
-        return true;
+        return wrappedType.equals(nodeWrappedType.wrappedType);
     }
 
     @Override
index e2b7cbc1876ca21e20aee4351994b79859a2265d..75a24ad47516a9311f9f040d7e93211a591232f8 100644 (file)
@@ -131,10 +131,7 @@ abstract class AbstractTypeMemberBuilder<T extends TypeMemberBuilder<T>> impleme
         if (this == obj) {
             return true;
         }
-        if (obj == null) {
-            return false;
-        }
-        if (getClass() != obj.getClass()) {
+        if (obj == null || getClass() != obj.getClass()) {
             return false;
         }
         final AbstractTypeMemberBuilder<?> other = (AbstractTypeMemberBuilder<?>) obj;
@@ -143,20 +140,12 @@ abstract class AbstractTypeMemberBuilder<T extends TypeMemberBuilder<T>> impleme
 
     @Override
     public String toString() {
-        final StringBuilder builder = new StringBuilder();
-        builder.append("GeneratedPropertyImpl [name=");
-        builder.append(getName());
-        builder.append(", annotations=");
-        builder.append(getAnnotationBuilders());
-        builder.append(", comment=");
-        builder.append(getComment());
-        builder.append(", returnType=");
-        builder.append(getReturnType());
-        builder.append(", isFinal=");
-        builder.append(isFinal());
-        builder.append(", modifier=");
-        builder.append(getAccessModifier());
-        builder.append("]");
-        return builder.toString();
+        return new StringBuilder().append("GeneratedPropertyImpl [name=").append(getName())
+                .append(", annotations=").append(getAnnotationBuilders())
+                .append(", comment=").append(getComment())
+                .append(", returnType=").append(getReturnType())
+                .append(", isFinal=").append(isFinal())
+                .append(", modifier=").append(getAccessModifier())
+                .append(']').toString();
     }
 }
index a8e6247215f07650816f8a431755dfa796e8814b..f82bbfa9d74458fabd1230cb111be2bc9af8b779 100644 (file)
@@ -74,39 +74,22 @@ final class MethodSignatureBuilderImpl extends AbstractTypeMemberBuilder<MethodS
         if (this == obj) {
             return true;
         }
-        if (obj == null) {
-            return false;
-        }
-        if (getClass() != obj.getClass()) {
+        if (obj == null || getClass() != obj.getClass()) {
             return false;
         }
         final MethodSignatureBuilderImpl other = (MethodSignatureBuilderImpl) obj;
-        if (!Objects.equals(getName(), other.getName())) {
-            return false;
-        }
-        if (!Objects.equals(this.parameters, other.parameters)) {
-            return false;
-        }
-        if (!Objects.equals(getReturnType(), other.getReturnType())) {
-            return false;
-        }
-        return true;
+        return Objects.equals(getName(), other.getName())
+                && Objects.equals(this.parameters, other.parameters)
+                && Objects.equals(getReturnType(), other.getReturnType());
     }
 
     @Override
     public String toString() {
-        final StringBuilder builder = new StringBuilder();
-        builder.append("MethodSignatureBuilderImpl [name=");
-        builder.append(getName());
-        builder.append(", returnType=");
-        builder.append(getReturnType());
-        builder.append(", parameters=");
-        builder.append(this.parameters);
-        builder.append(", annotationBuilders=");
-        builder.append(getAnnotationBuilders());
-        builder.append(", comment=");
-        builder.append(getComment());
-        builder.append("]");
-        return builder.toString();
+        return new StringBuilder().append("MethodSignatureBuilderImpl [name=").append(getName())
+                .append(", returnType=").append(getReturnType())
+                .append(", parameters=").append(this.parameters)
+                .append(", annotationBuilders=").append(getAnnotationBuilders())
+                .append(", comment=").append(getComment())
+                .append(']').toString();
     }
 }
index 7d3b7a62f35be3fe22df1375c09ac7a1c29790b6..867e905b8ee7c21ae29fb32267b9cbf6ae77256e 100644 (file)
@@ -15,7 +15,6 @@ import org.opendaylight.mdsal.binding.model.api.MethodSignature;
 import org.opendaylight.mdsal.binding.model.api.Type;
 
 class MethodSignatureImpl extends AbstractTypeMember implements MethodSignature {
-
     private final List<Parameter> params;
     private final boolean isAbstract;
     private final boolean isDefault;
@@ -67,47 +66,31 @@ class MethodSignatureImpl extends AbstractTypeMember implements MethodSignature
         if (this == obj) {
             return true;
         }
-        if (obj == null) {
-            return false;
-        }
-        if (getClass() != obj.getClass()) {
+        if (obj == null || getClass() != obj.getClass()) {
             return false;
         }
         final MethodSignatureImpl other = (MethodSignatureImpl) obj;
-        if (!Objects.equals(getName(), other.getName())) {
-            return false;
-        }
-        if (!Objects.equals(this.params, other.params)) {
-            return false;
-        }
-        if (!Objects.equals(getReturnType(), other.getReturnType())) {
-            return false;
-        }
-        return true;
+        return Objects.equals(getName(), other.getName())
+                && Objects.equals(this.params, other.params)
+                && Objects.equals(getReturnType(), other.getReturnType());
     }
 
     @Override
     public String toString() {
-        final StringBuilder builder = new StringBuilder();
-        builder.append("MethodSignatureImpl [name=");
-        builder.append(getName());
-        builder.append(", comment=");
-        builder.append(getComment());
-        if (getDefiningType() != null) {
-            builder.append(", definingType=");
-            builder.append(getDefiningType().getPackageName());
-            builder.append(".");
-            builder.append(getDefiningType().getName());
+        final StringBuilder builder = new StringBuilder().append("MethodSignatureImpl [name=").append(getName())
+                .append(", comment=").append(getComment())
+                .append(", definingType=");
+
+        final Type defType = getDefiningType();
+        if (defType != null) {
+            builder.append(defType.getPackageName()).append('.').append(defType.getName());
         } else {
-            builder.append(", definingType= null");
+            builder.append(" null");
         }
-        builder.append(", returnType=");
-        builder.append(getReturnType());
-        builder.append(", params=");
-        builder.append(this.params);
-        builder.append(", annotations=");
-        builder.append(getAnnotations());
-        builder.append("]");
-        return builder.toString();
+
+        return builder.append(", returnType=").append(getReturnType())
+                .append(", params=").append(this.params)
+                .append(", annotations=").append(getAnnotations())
+                .append(']').toString();
     }
 }
index 2e7a0bec9d1fa3f5d3435feece67b61be748e7ef..3f5deea45615c6da82f231786f3c981318eabfe5 100644 (file)
@@ -69,28 +69,16 @@ public class GenericEntity<T extends Path<T>> implements Serializable, Identifia
         return type;
     }
 
-    @SuppressWarnings("unchecked")
     @Override
     public boolean equals(final Object obj) {
         if (this == obj) {
             return true;
         }
-
         if (obj == null || getClass() != obj.getClass()) {
             return false;
         }
-
-        GenericEntity<T> entity = (GenericEntity<T>) obj;
-
-        if (!id.equals(entity.id)) {
-            return false;
-        }
-
-        if (!type.equals(entity.type)) {
-            return false;
-        }
-
-        return true;
+        final GenericEntity<?> entity = (GenericEntity<?>) obj;
+        return id.equals(entity.id) && type.equals(entity.type);
     }
 
     @Override