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.collect.ImmutableSet;
11 import java.util.Collections;
12 import java.util.HashSet;
13 import java.util.List;
14 import java.util.Objects;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
19 import org.opendaylight.yangtools.yang.model.api.stmt.IdentityStatement;
20 import org.opendaylight.yangtools.yang.parser.spi.meta.DerivedIdentitiesNamespace;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
23 public final class IdentityEffectiveStatementImpl extends AbstractEffectiveSchemaNode<IdentityStatement>
24 implements IdentitySchemaNode {
25 private IdentitySchemaNode baseIdentity;
26 private final Set<IdentitySchemaNode> derivedIdentities;
28 public IdentityEffectiveStatementImpl(
29 final StmtContext<QName, IdentityStatement, EffectiveStatement<QName, IdentityStatement>> ctx) {
32 // initDerivedIdentities
33 Set<IdentitySchemaNode> derivedIdentitiesInit = new HashSet<IdentitySchemaNode>();
34 List<StmtContext<?, ?, ?>> derivedIdentitiesCtxList = ctx.getFromNamespace(
35 DerivedIdentitiesNamespace.class, ctx.getStatementArgument());
36 if (derivedIdentitiesCtxList == null) {
37 this.derivedIdentities = ImmutableSet.of();
40 for (StmtContext<?, ?, ?> derivedIdentityCtx : derivedIdentitiesCtxList) {
41 IdentityEffectiveStatementImpl derivedIdentity = (IdentityEffectiveStatementImpl) derivedIdentityCtx
43 derivedIdentity.initBaseIdentity(this);
44 derivedIdentitiesInit.add(derivedIdentity);
46 this.derivedIdentities = ImmutableSet.copyOf(derivedIdentitiesInit);
49 private void initBaseIdentity(final IdentityEffectiveStatementImpl baseIdentity) {
50 this.baseIdentity = baseIdentity;
54 public IdentitySchemaNode getBaseIdentity() {
59 public Set<IdentitySchemaNode> getDerivedIdentities() {
60 return Collections.unmodifiableSet(derivedIdentities);
64 public int hashCode() {
67 result = prime * result + Objects.hashCode(getQName());
68 result = prime * result + Objects.hashCode(getPath());
73 public boolean equals(final Object obj) {
80 if (getClass() != obj.getClass()) {
83 IdentityEffectiveStatementImpl other = (IdentityEffectiveStatementImpl) obj;
84 return Objects.equals(getQName(), other.getQName()) && Objects.equals(getPath(), other.getPath());
88 public String toString() {
89 StringBuilder sb = new StringBuilder(
90 IdentityEffectiveStatementImpl.class.getSimpleName());
92 sb.append("base=").append(baseIdentity);
93 sb.append(", qname=").append(getQName());