2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
10 import com.google.common.base.Optional;
11 import java.util.Objects;
12 import org.opendaylight.yangtools.yang.common.QName;
13 import org.opendaylight.yangtools.yang.model.api.DerivableSchemaNode;
14 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
15 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
16 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
17 import org.opendaylight.yangtools.yang.model.api.stmt.LeafListStatement;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
19 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.TypeUtils;
21 public final class LeafListEffectiveStatementImpl extends AbstractEffectiveDataSchemaNode<LeafListStatement> implements
22 LeafListSchemaNode, DerivableSchemaNode {
24 private final LeafListSchemaNode original;
25 private final TypeDefinition<?> type;
26 private final boolean userOrdered;
27 private static final String ORDER_BY_USER_KEYWORD = "user";
29 public LeafListEffectiveStatementImpl(
30 final StmtContext<QName, LeafListStatement, EffectiveStatement<QName, LeafListStatement>> ctx) {
32 this.original = ctx.getOriginalCtx() == null ? null : (LeafListSchemaNode) ctx.getOriginalCtx()
35 OrderedByEffectiveStatementImpl orderedByStmt = firstEffective(OrderedByEffectiveStatementImpl.class);
36 if (orderedByStmt != null && orderedByStmt.argument().equals(ORDER_BY_USER_KEYWORD)) {
37 this.userOrdered = true;
39 this.userOrdered = false;
42 EffectiveStatement<?, ?> typeEffectiveSubstatement = firstEffectiveSubstatementOfType(TypeDefinition.class);
43 this.type = TypeUtils.getTypeFromEffectiveStatement(typeEffectiveSubstatement);
47 public Optional<LeafListSchemaNode> getOriginal() {
48 return Optional.fromNullable(original);
52 public TypeDefinition<?> getType() {
57 public boolean isUserOrdered() {
62 public int hashCode() {
65 result = prime * result + Objects.hashCode(getQName());
66 result = prime * result + Objects.hashCode(getPath());
71 public boolean equals(final Object obj) {
78 if (getClass() != obj.getClass()) {
81 LeafListEffectiveStatementImpl other = (LeafListEffectiveStatementImpl) obj;
82 return Objects.equals(getQName(), other.getQName()) && Objects.equals(getPath(), other.getPath());
86 public String toString() {
87 StringBuilder sb = new StringBuilder(LeafListEffectiveStatementImpl.class.getSimpleName());
89 sb.append(getQName());