Use String concatenation instead of StringBuffer/Builder
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / effective / RpcEffectiveStatementImpl.java
index 0eef258d300ccd4e457ddc059451625562667101..0e640571202ebea0b240bfdd197a9dd5b4b1b649 100644 (file)
@@ -7,58 +7,36 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
 
-import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
 import java.util.Collection;
 import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
 import java.util.Objects;
 import java.util.Set;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
-import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.opendaylight.yangtools.yang.model.api.stmt.RpcStatement;
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.RpcStatement;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
-
-public class RpcEffectiveStatementImpl extends AbstractEffectiveDocumentedNode<QName, RpcStatement> implements RpcDefinition {
-    private final QName qname;
-    private final SchemaPath path;
 
-    private ContainerSchemaNode input;
-    private ContainerSchemaNode output;
+public class RpcEffectiveStatementImpl extends AbstractEffectiveSchemaNode<RpcStatement> implements RpcDefinition {
+    private final ContainerSchemaNode input;
+    private final ContainerSchemaNode output;
+    private final Set<TypeDefinition<?>> typeDefinitions;
+    private final Set<GroupingDefinition> groupings;
 
-    ImmutableSet<TypeDefinition<?>> typeDefinitions;
-    ImmutableSet<GroupingDefinition> groupings;
-    ImmutableList<UnknownSchemaNode> unknownNodes;
-
-    public RpcEffectiveStatementImpl(StmtContext<QName, RpcStatement, EffectiveStatement<QName, RpcStatement>> ctx) {
+    public RpcEffectiveStatementImpl(final StmtContext<QName, RpcStatement, EffectiveStatement<QName, RpcStatement>> ctx) {
         super(ctx);
-        this.qname = ctx.getStatementArgument();
-        this.path = Utils.getSchemaPath(ctx);
-
-        initSubstatements();
-
-    }
+        this.input = firstEffective(InputEffectiveStatementImpl.class);
+        this.output = firstEffective(OutputEffectiveStatementImpl.class);
 
-    private void initSubstatements() {
+        // initSubstatements
         Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
-
-        List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
         Set<GroupingDefinition> groupingsInit = new HashSet<>();
         Set<TypeDefinition<?>> typeDefinitionsInit = new HashSet<>();
-
         for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
-            if (effectiveStatement instanceof UnknownSchemaNode) {
-                UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
-                unknownNodesInit.add(unknownNode);
-            }
             if (effectiveStatement instanceof GroupingDefinition) {
                 GroupingDefinition groupingDefinition = (GroupingDefinition) effectiveStatement;
                 groupingsInit.add(groupingDefinition);
@@ -67,47 +45,21 @@ public class RpcEffectiveStatementImpl extends AbstractEffectiveDocumentedNode<Q
                 TypeDefinition<?> typeDefinition = (TypeDefinition<?>) effectiveStatement;
                 typeDefinitionsInit.add(typeDefinition);
             }
-            if (this.input == null && effectiveStatement instanceof InputEffectiveStatementImpl) {
-                this.input = (InputEffectiveStatementImpl) effectiveStatement;
-            }
-            if (this.output == null && effectiveStatement instanceof OutputEffectiveStatementImpl) {
-                this.output = (OutputEffectiveStatementImpl) effectiveStatement;
-            }
         }
-
-        this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
         this.groupings = ImmutableSet.copyOf(groupingsInit);
         this.typeDefinitions = ImmutableSet.copyOf(typeDefinitionsInit);
     }
 
-    @Override
-    public QName getQName() {
-        return qname;
-    }
-
-    @Override
-    public SchemaPath getPath() {
-        return path;
-    }
-
     @Override
     public ContainerSchemaNode getInput() {
         return input;
     }
 
-    void setInput(final ContainerSchemaNode input) {
-        this.input = input;
-    }
-
     @Override
     public ContainerSchemaNode getOutput() {
         return output;
     }
 
-    void setOutput(final ContainerSchemaNode output) {
-        this.output = output;
-    }
-
     @Override
     public Set<TypeDefinition<?>> getTypeDefinitions() {
         return typeDefinitions;
@@ -118,17 +70,12 @@ public class RpcEffectiveStatementImpl extends AbstractEffectiveDocumentedNode<Q
         return groupings;
     }
 
-    @Override
-    public List<UnknownSchemaNode> getUnknownSchemaNodes() {
-        return unknownNodes;
-    }
-
     @Override
     public int hashCode() {
         final int prime = 31;
         int result = 1;
-        result = prime * result + Objects.hashCode(qname);
-        result = prime * result + Objects.hashCode(path);
+        result = prime * result + Objects.hashCode(getQName());
+        result = prime * result + Objects.hashCode(getPath());
         return result;
     }
 
@@ -144,36 +91,20 @@ public class RpcEffectiveStatementImpl extends AbstractEffectiveDocumentedNode<Q
             return false;
         }
         final RpcEffectiveStatementImpl other = (RpcEffectiveStatementImpl) obj;
-        if (qname == null) {
-            if (other.qname != null) {
-                return false;
-            }
-        } else if (!qname.equals(other.qname)) {
-            return false;
-        }
-        if (path == null) {
-            if (other.path != null) {
-                return false;
-            }
-        } else if (!path.equals(other.path)) {
-            return false;
-        }
-        return true;
+        return Objects.equals(getQName(), other.getQName()) && Objects.equals(getPath(), other.getPath());
     }
 
     @Override
     public String toString() {
-        StringBuilder sb = new StringBuilder(RpcEffectiveStatementImpl.class.getSimpleName());
-        sb.append("[");
-        sb.append("qname=");
-        sb.append(qname);
-        sb.append(", path=");
-        sb.append(path);
-        sb.append(", input=");
-        sb.append(input);
-        sb.append(", output=");
-        sb.append(output);
-        sb.append("]");
-        return sb.toString();
+        return RpcEffectiveStatementImpl.class.getSimpleName() + "[" +
+                "qname=" +
+                getQName() +
+                ", path=" +
+                getPath() +
+                ", input=" +
+                input +
+                ", output=" +
+                output +
+                "]";
     }
 }