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 static com.google.common.base.Preconditions.checkNotNull;
11 import java.util.Collection;
12 import java.util.LinkedList;
13 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
14 import org.opendaylight.yangtools.yang.model.api.stmt.AugmentStatement;
15 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
16 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
17 import com.google.common.base.Optional;
18 import com.google.common.collect.ImmutableList;
20 import java.util.Date;
21 import java.util.Iterator;
22 import java.util.List;
23 import org.opendaylight.yangtools.yang.common.QName;
24 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
25 import org.opendaylight.yangtools.yang.model.api.NamespaceRevisionAware;
26 import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
27 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
28 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
30 public class AugmentEffectiveStatementImpl
32 AbstractEffectiveDocumentedDataNodeContainer<SchemaNodeIdentifier, AugmentStatement>
33 implements AugmentationSchema, NamespaceRevisionAware,
34 Comparable<AugmentEffectiveStatementImpl> {
35 private final int order;
36 private final SchemaPath targetPath;
37 RevisionAwareXPath whenCondition;
41 ImmutableList<UnknownSchemaNode> unknownNodes;
42 private AugmentationSchema copyOf;
44 public AugmentEffectiveStatementImpl(
45 StmtContext<SchemaNodeIdentifier, AugmentStatement, EffectiveStatement<SchemaNodeIdentifier, AugmentStatement>> ctx) {
48 SchemaNodeIdentifier schemaNodeIdentifier = ctx.getStatementArgument();
49 this.targetPath = SchemaPath.create(
50 schemaNodeIdentifier.getPathFromRoot(),
51 schemaNodeIdentifier.isAbsolute());
53 // :TODO init other fields
55 // firstEffective(WhenEffectiveStatementImpl.class);
57 initSubstatementCollections();
60 private void initSubstatementCollections() {
61 Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
63 LinkedList<UnknownSchemaNode> unknownNodes = new LinkedList<UnknownSchemaNode>();
65 for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
66 if (effectiveStatement instanceof UnknownSchemaNode) {
67 UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
68 unknownNodes.add(unknownNode);
72 this.unknownNodes = ImmutableList.copyOf(unknownNodes);
75 public void setCopyOf(final AugmentationSchema build) {
80 public Optional<AugmentationSchema> getOriginalDefinition() {
81 return Optional.fromNullable(this.copyOf);
85 public SchemaPath getTargetPath() {
90 public RevisionAwareXPath getWhenCondition() {
95 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
100 public URI getNamespace() {
105 public Date getRevision() {
110 public int hashCode() {
111 final int prime = 17;
113 result = prime * result
114 + ((targetPath == null) ? 0 : targetPath.hashCode());
115 result = prime * result
116 + ((whenCondition == null) ? 0 : whenCondition.hashCode());
117 result = prime * result + getChildNodes().hashCode();
122 public boolean equals(final Object obj) {
129 if (getClass() != obj.getClass()) {
132 AugmentEffectiveStatementImpl other = (AugmentEffectiveStatementImpl) obj;
133 if (targetPath == null) {
134 if (other.targetPath != null) {
137 } else if (!targetPath.equals(other.targetPath)) {
140 if (whenCondition == null) {
141 if (other.whenCondition != null) {
144 } else if (!whenCondition.equals(other.whenCondition)) {
147 if (!getChildNodes().equals(other.getChildNodes())) {
154 public String toString() {
155 StringBuilder sb = new StringBuilder(
156 AugmentEffectiveStatementImpl.class.getSimpleName());
158 sb.append("targetPath=").append(targetPath);
159 sb.append(", when=").append(whenCondition);
161 return sb.toString();
165 public int compareTo(final AugmentEffectiveStatementImpl o) {
167 Iterator<QName> thisIt = this.targetPath.getPathFromRoot().iterator();
168 Iterator<QName> otherIt = o.getTargetPath().getPathFromRoot()
170 while (thisIt.hasNext()) {
171 if (otherIt.hasNext()) {
172 int comp = thisIt.next().compareTo(otherIt.next());
180 if (otherIt.hasNext()) {
183 return this.order - o.order;