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 2b439a13e91f9a0830c031fd24c551f1c585cbf6..b66abf8c67bd7aa3fdd00c3bd819fa05b4fed7f4 100644 (file)
@@ -8,7 +8,7 @@
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
 
 import com.google.common.collect.ImmutableList;
-import java.util.LinkedList;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Objects;
 import org.opendaylight.yangtools.concepts.Immutable;
@@ -20,34 +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;
 
-public class DeviationEffectiveStatementImpl extends EffectiveStatementBase<SchemaNodeIdentifier, DeviationStatement>
+public class DeviationEffectiveStatementImpl extends DeclaredEffectiveStatementBase<SchemaNodeIdentifier, DeviationStatement>
         implements Deviation, Immutable {
-
     private final SchemaPath targetPath;
-    private Deviate deviate;
-    private String reference;
-    private final ImmutableList<UnknownSchemaNode> unknownSchemaNodes;
+    private final Deviate deviate;
+    private final String reference;
+    private final List<UnknownSchemaNode> unknownSchemaNodes;
 
     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);
     }
 
@@ -107,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 +
+                "]";
     }
 }