Use String concatenation instead of StringBuffer/Builder
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / effective / DeviationEffectiveStatementImpl.java
index 66a19f22ab3504e883ed27da28a451c5b9256e46..b66abf8c67bd7aa3fdd00c3bd819fa05b4fed7f4 100644 (file)
@@ -7,9 +7,10 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
 
-import java.util.LinkedList;
+import com.google.common.collect.ImmutableList;
+import java.util.ArrayList;
 import java.util.List;
-
+import java.util.Objects;
 import org.opendaylight.yangtools.concepts.Immutable;
 import org.opendaylight.yangtools.yang.model.api.Deviation;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
@@ -19,36 +20,29 @@ import org.opendaylight.yangtools.yang.model.api.stmt.DeviationStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 
-import com.google.common.collect.ImmutableList;
-
-public class DeviationEffectiveStatementImpl extends EffectiveStatementBase<SchemaNodeIdentifier, DeviationStatement>
+public class DeviationEffectiveStatementImpl extends DeclaredEffectiveStatementBase<SchemaNodeIdentifier, DeviationStatement>
         implements Deviation, Immutable {
+    private final SchemaPath targetPath;
+    private final Deviate deviate;
+    private final String reference;
+    private final List<UnknownSchemaNode> unknownSchemaNodes;
 
-    private SchemaPath targetPath;
-    private Deviate deviate;
-    private String reference;
-    private ImmutableList<UnknownSchemaNode> unknownSchemaNodes;
-
-    public DeviationEffectiveStatementImpl(StmtContext<SchemaNodeIdentifier, DeviationStatement, ?> ctx) {
+    public DeviationEffectiveStatementImpl(final StmtContext<SchemaNodeIdentifier, DeviationStatement, ?> ctx) {
         super(ctx);
+        this.targetPath = ctx.getStatementArgument().asSchemaPath();
 
-        List<UnknownSchemaNode> unknownSchemaNodesInit = new LinkedList<>();
+        DeviateEffectiveStatementImpl deviateStmt = firstEffective(DeviateEffectiveStatementImpl.class);
+        this.deviate = (deviateStmt == null) ? null : deviateStmt.argument();
 
-        targetPath = SchemaPath.create(ctx.getStatementArgument().getPathFromRoot(), ctx.getStatementArgument()
-                .isAbsolute());
+        ReferenceEffectiveStatementImpl referenceStmt = firstEffective(ReferenceEffectiveStatementImpl.class);
+        this.reference = (referenceStmt == null) ? null : referenceStmt.argument();
 
+        List<UnknownSchemaNode> unknownSchemaNodesInit = new ArrayList<>();
         for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
-            if (effectiveStatement instanceof DeviateEffectiveStatementImpl) {
-                deviate = ((DeviateEffectiveStatementImpl) effectiveStatement).argument();
-            }
-            if (effectiveStatement instanceof ReferenceEffectiveStatementImpl) {
-                reference = ((ReferenceEffectiveStatementImpl) effectiveStatement).argument();
-            }
             if (effectiveStatement instanceof UnknownSchemaNode) {
                 unknownSchemaNodesInit.add((UnknownSchemaNode) effectiveStatement);
             }
         }
-
         unknownSchemaNodes = ImmutableList.copyOf(unknownSchemaNodesInit);
     }
 
@@ -76,14 +70,14 @@ public class DeviationEffectiveStatementImpl extends EffectiveStatementBase<Sche
     public int hashCode() {
         final int prime = 31;
         int result = 1;
-        result = prime * result + ((targetPath == null) ? 0 : targetPath.hashCode());
-        result = prime * result + ((deviate == null) ? 0 : deviate.hashCode());
-        result = prime * result + ((reference == null) ? 0 : reference.hashCode());
+        result = prime * result + Objects.hashCode(targetPath);
+        result = prime * result + Objects.hashCode(deviate);
+        result = prime * result + Objects.hashCode(reference);
         return result;
     }
 
     @Override
-    public boolean equals(Object obj) {
+    public boolean equals(final Object obj) {
         if (this == obj) {
             return true;
         }
@@ -94,25 +88,13 @@ public class DeviationEffectiveStatementImpl extends EffectiveStatementBase<Sche
             return false;
         }
         DeviationEffectiveStatementImpl other = (DeviationEffectiveStatementImpl) obj;
-        if (targetPath == null) {
-            if (other.targetPath != null) {
-                return false;
-            }
-        } else if (!targetPath.equals(other.targetPath)) {
+        if (!Objects.equals(targetPath, other.targetPath)) {
             return false;
         }
-        if (deviate == null) {
-            if (other.deviate != null) {
-                return false;
-            }
-        } else if (!deviate.equals(other.deviate)) {
+        if (!Objects.equals(deviate, other.deviate)) {
             return false;
         }
-        if (reference == null) {
-            if (other.reference != null) {
-                return false;
-            }
-        } else if (!reference.equals(other.reference)) {
+        if (!Objects.equals(reference, other.reference)) {
             return false;
         }
         return true;
@@ -120,12 +102,10 @@ public class DeviationEffectiveStatementImpl extends EffectiveStatementBase<Sche
 
     @Override
     public String toString() {
-        StringBuilder sb = new StringBuilder(DeviationEffectiveStatementImpl.class.getSimpleName());
-        sb.append("[");
-        sb.append("targetPath=").append(targetPath);
-        sb.append(", deviate=").append(deviate);
-        sb.append(", reference=").append(reference);
-        sb.append("]");
-        return sb.toString();
+        return DeviationEffectiveStatementImpl.class.getSimpleName() + "[" +
+                "targetPath=" + targetPath +
+                ", deviate=" + deviate +
+                ", reference=" + reference +
+                "]";
     }
-}
\ No newline at end of file
+}