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%2FLeafListEffectiveStatementImpl.java;h=1963d6b79acbfd69783065b19933866312099d08;hb=e99bf7da4cf4f715e6d899a8c41a8df2853e3055;hp=77487441e4167aa4ddc4c638922362d7f6c3f529;hpb=c4dc5b33e7d24670b59cc81b65e15b37a3268608;p=yangtools.git diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/LeafListEffectiveStatementImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/LeafListEffectiveStatementImpl.java index 77487441e4..1963d6b79a 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/LeafListEffectiveStatementImpl.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/LeafListEffectiveStatementImpl.java @@ -1,4 +1,4 @@ -/** +/* * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the @@ -7,80 +7,40 @@ */ package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective; -import java.util.Collection; -import java.util.LinkedList; - -import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils; -import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement; -import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext; -import org.opendaylight.yangtools.yang.model.api.stmt.LeafListStatement; import com.google.common.base.Optional; -import com.google.common.collect.ImmutableList; -import java.util.List; +import java.util.Objects; import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition; import org.opendaylight.yangtools.yang.model.api.DerivableSchemaNode; import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode; -import org.opendaylight.yangtools.yang.model.api.SchemaPath; import org.opendaylight.yangtools.yang.model.api.TypeDefinition; -import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode; - -public class LeafListEffectiveStatementImpl extends AbstractEffectiveDocumentedNode implements LeafListSchemaNode, DerivableSchemaNode { - private final QName qname; - private final SchemaPath path; +import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement; +import org.opendaylight.yangtools.yang.model.api.stmt.LeafListStatement; +import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext; +import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.TypeUtils; - boolean augmenting; - boolean addedByUses; - LeafListSchemaNode original; - boolean configuration; - ConstraintDefinition constraintsDef; - TypeDefinition type; - boolean userOrdered; +public final class LeafListEffectiveStatementImpl extends AbstractEffectiveDataSchemaNode implements + LeafListSchemaNode, DerivableSchemaNode { - private ImmutableList unknownNodes; + private final LeafListSchemaNode original; + private final TypeDefinition type; + private final boolean userOrdered; + private static final String ORDER_BY_USER_KEYWORD = "user"; - public LeafListEffectiveStatementImpl(StmtContext> ctx) { + public LeafListEffectiveStatementImpl( + final StmtContext> ctx) { super(ctx); - this.qname = ctx.getStatementArgument(); - this.path = Utils.getSchemaPath(ctx); - //:TODO init other fields - - initSubstatementCollections(); - } - - private void initSubstatementCollections() { - Collection> effectiveSubstatements = effectiveSubstatements(); - - List unknownNodesInit = new LinkedList<>(); - - for (EffectiveStatement effectiveStatement : effectiveSubstatements) { - if (effectiveStatement instanceof UnknownSchemaNode) { - UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement; - unknownNodesInit.add(unknownNode); - } + this.original = ctx.getOriginalCtx() == null ? null : (LeafListSchemaNode) ctx.getOriginalCtx() + .buildEffective(); + + OrderedByEffectiveStatementImpl orderedByStmt = firstEffective(OrderedByEffectiveStatementImpl.class); + if (orderedByStmt != null && orderedByStmt.argument().equals(ORDER_BY_USER_KEYWORD)) { + this.userOrdered = true; + } else { + this.userOrdered = false; } - this.unknownNodes = ImmutableList.copyOf(unknownNodesInit); - } - - @Override - public QName getQName() { - return qname; - } - - @Override - public SchemaPath getPath() { - return path; - } - - @Override - public boolean isAugmenting() { - return augmenting; - } - - @Override - public boolean isAddedByUses() { - return addedByUses; + EffectiveStatement typeEffectiveSubstatement = firstEffectiveSubstatementOfType(TypeDefinition.class); + this.type = TypeUtils.getTypeFromEffectiveStatement(typeEffectiveSubstatement); } @Override @@ -88,16 +48,6 @@ public class LeafListEffectiveStatementImpl extends AbstractEffectiveDocumentedN return Optional.fromNullable(original); } - @Override - public boolean isConfiguration() { - return configuration; - } - - @Override - public ConstraintDefinition getConstraints() { - return constraintsDef; - } - @Override public TypeDefinition getType() { return type; @@ -108,17 +58,12 @@ public class LeafListEffectiveStatementImpl extends AbstractEffectiveDocumentedN return userOrdered; } - @Override - public List getUnknownSchemaNodes() { - return unknownNodes; - } - @Override public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((qname == null) ? 0 : qname.hashCode()); - result = prime * result + ((path == null) ? 0 : path.hashCode()); + result = prime * result + Objects.hashCode(getQName()); + result = prime * result + Objects.hashCode(getPath()); return result; } @@ -134,29 +79,15 @@ public class LeafListEffectiveStatementImpl extends AbstractEffectiveDocumentedN return false; } LeafListEffectiveStatementImpl other = (LeafListEffectiveStatementImpl) 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(LeafListEffectiveStatementImpl.class.getSimpleName()); sb.append("["); - sb.append(qname); + sb.append(getQName()); sb.append("]"); return sb.toString(); } -} \ No newline at end of file +}