X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=yang%2Fyang-parser-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fparser%2Fstmt%2Frfc6020%2Feffective%2FDeviationEffectiveStatementImpl.java;h=b66abf8c67bd7aa3fdd00c3bd819fa05b4fed7f4;hb=refs%2Fchanges%2F18%2F35918%2F2;hp=c424b9e151814b9a6c5f0b2a3af8c81718d545af;hpb=4078c52f76ce904726f0e127eba1a96c7bae357d;p=yangtools.git diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/DeviationEffectiveStatementImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/DeviationEffectiveStatementImpl.java index c424b9e151..b66abf8c67 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/DeviationEffectiveStatementImpl.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/DeviationEffectiveStatementImpl.java @@ -7,17 +7,105 @@ */ package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective; +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; +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.DeviationStatement; import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier; import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext; -public class DeviationEffectiveStatementImpl extends - EffectiveStatementBase { +public class DeviationEffectiveStatementImpl extends DeclaredEffectiveStatementBase + implements Deviation, Immutable { + private final SchemaPath targetPath; + private final Deviate deviate; + private final String reference; + private final List unknownSchemaNodes; - public DeviationEffectiveStatementImpl( - StmtContext ctx) { + public DeviationEffectiveStatementImpl(final StmtContext ctx) { super(ctx); + this.targetPath = ctx.getStatementArgument().asSchemaPath(); + DeviateEffectiveStatementImpl deviateStmt = firstEffective(DeviateEffectiveStatementImpl.class); + this.deviate = (deviateStmt == null) ? null : deviateStmt.argument(); + + ReferenceEffectiveStatementImpl referenceStmt = firstEffective(ReferenceEffectiveStatementImpl.class); + this.reference = (referenceStmt == null) ? null : referenceStmt.argument(); + + List unknownSchemaNodesInit = new ArrayList<>(); + for (final EffectiveStatement effectiveStatement : effectiveSubstatements()) { + if (effectiveStatement instanceof UnknownSchemaNode) { + unknownSchemaNodesInit.add((UnknownSchemaNode) effectiveStatement); + } + } + unknownSchemaNodes = ImmutableList.copyOf(unknownSchemaNodesInit); + } + + @Override + public SchemaPath getTargetPath() { + return targetPath; + } + + @Override + public Deviate getDeviate() { + return deviate; + } + + @Override + public String getReference() { + return reference; } -} \ No newline at end of file + @Override + public List getUnknownSchemaNodes() { + return unknownSchemaNodes; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + Objects.hashCode(targetPath); + result = prime * result + Objects.hashCode(deviate); + result = prime * result + Objects.hashCode(reference); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + DeviationEffectiveStatementImpl other = (DeviationEffectiveStatementImpl) obj; + if (!Objects.equals(targetPath, other.targetPath)) { + return false; + } + if (!Objects.equals(deviate, other.deviate)) { + return false; + } + if (!Objects.equals(reference, other.reference)) { + return false; + } + return true; + } + + @Override + public String toString() { + return DeviationEffectiveStatementImpl.class.getSimpleName() + "[" + + "targetPath=" + targetPath + + ", deviate=" + deviate + + ", reference=" + reference + + "]"; + } +}