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 java.util.Collection;
11 import java.util.LinkedList;
13 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
14 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
15 import org.opendaylight.yangtools.yang.model.api.stmt.IdentityStatement;
16 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
17 import com.google.common.collect.ImmutableList;
18 import java.util.Collections;
19 import java.util.List;
21 import org.opendaylight.yangtools.yang.common.QName;
22 import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
23 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
24 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
26 public class IdentityEffectiveStatementImpl extends
27 AbstractEffectiveDocumentedNode<QName, IdentityStatement> implements
29 private final QName qname;
30 private final SchemaPath path;
31 IdentitySchemaNode baseIdentity;
32 private final Set<IdentitySchemaNode> derivedIdentities;
34 ImmutableList<UnknownSchemaNode> unknownNodes;
36 public IdentityEffectiveStatementImpl(
37 StmtContext<QName, IdentityStatement, EffectiveStatement<QName, IdentityStatement>> ctx) {
40 this.qname = ctx.getStatementArgument();
41 this.path = Utils.getSchemaPath(ctx);
43 initSubstatementCollections();
45 // :TODO init other fields
46 this.derivedIdentities = null;
49 private void initSubstatementCollections() {
50 Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
52 LinkedList<UnknownSchemaNode> unknownNodes = new LinkedList<UnknownSchemaNode>();
54 for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
55 if (effectiveStatement instanceof UnknownSchemaNode) {
56 UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
57 unknownNodes.add(unknownNode);
61 this.unknownNodes = ImmutableList.copyOf(unknownNodes);
65 public QName getQName() {
70 public IdentitySchemaNode getBaseIdentity() {
75 public Set<IdentitySchemaNode> getDerivedIdentities() {
76 return Collections.unmodifiableSet(derivedIdentities);
80 public SchemaPath getPath() {
85 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
90 public int hashCode() {
93 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
94 result = prime * result + ((path == null) ? 0 : path.hashCode());
99 public boolean equals(final Object obj) {
106 if (getClass() != obj.getClass()) {
109 IdentityEffectiveStatementImpl other = (IdentityEffectiveStatementImpl) obj;
111 if (other.qname != null) {
114 } else if (!qname.equals(other.qname)) {
118 if (other.path != null) {
121 } else if (!path.equals(other.path)) {
128 public String toString() {
129 StringBuilder sb = new StringBuilder(
130 IdentityEffectiveStatementImpl.class.getSimpleName());
132 sb.append("base=").append(baseIdentity);
133 sb.append(", qname=").append(qname);
135 return sb.toString();