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.LeafSchemaNode;
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.LeafStatement;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
19 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.TypeUtils;
21 public final class LeafEffectiveStatementImpl extends AbstractEffectiveDataSchemaNode<LeafStatement> implements
22 LeafSchemaNode, DerivableSchemaNode {
23 private final LeafSchemaNode original;
24 private final TypeDefinition<?> type;
25 private final String defaultStr;
26 private final String unitsStr;
28 public LeafEffectiveStatementImpl(final StmtContext<QName, LeafStatement, EffectiveStatement<QName, LeafStatement>> ctx) {
30 this.original = ctx.getOriginalCtx() == null ? null : (LeafSchemaNode) ctx.getOriginalCtx().buildEffective();
32 DefaultEffectiveStatementImpl defaultStmt = firstEffective(DefaultEffectiveStatementImpl.class);
33 this.defaultStr = (defaultStmt == null) ? null : defaultStmt.argument();
35 UnitsEffectiveStatementImpl unitsStmt = firstEffective(UnitsEffectiveStatementImpl.class);
36 this.unitsStr = (unitsStmt == null) ? null : unitsStmt.argument();
38 EffectiveStatement<?,?> typeEffectiveSubstatement = firstEffectiveSubstatementOfType(TypeDefinition.class);
39 this.type = TypeUtils.getTypeFromEffectiveStatement(typeEffectiveSubstatement);
43 public Optional<LeafSchemaNode> getOriginal() {
44 return Optional.fromNullable(original);
48 public TypeDefinition<?> getType() {
53 public String getDefault() {
58 public String getUnits() {
63 public int hashCode() {
66 result = prime * result + Objects.hashCode(getQName());
67 result = prime * result + Objects.hashCode(getPath());
72 public boolean equals(final Object obj) {
79 if (getClass() != obj.getClass()) {
82 LeafEffectiveStatementImpl other = (LeafEffectiveStatementImpl) obj;
83 return Objects.equals(getQName(), other.getQName()) && Objects.equals(getPath(), other.getPath());
87 public String toString() {
88 StringBuilder sb = new StringBuilder(LeafEffectiveStatementImpl.class.getSimpleName());
90 sb.append("qname=").append(getQName());
91 sb.append(", path=").append(getPath());