2 * Copyright (c) 2013 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.builder.impl;
10 import static com.google.common.base.Preconditions.checkNotNull;
12 import com.google.common.base.Optional;
13 import com.google.common.collect.ImmutableList;
15 import java.util.Date;
16 import java.util.Iterator;
17 import java.util.List;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
20 import org.opendaylight.yangtools.yang.model.api.NamespaceRevisionAware;
21 import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
22 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
23 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
24 import org.opendaylight.yangtools.yang.parser.builder.util.AbstractDocumentedDataNodeContainer;
26 final class AugmentationSchemaImpl extends AbstractDocumentedDataNodeContainer implements AugmentationSchema, NamespaceRevisionAware, Comparable<AugmentationSchemaImpl> {
27 private final int order;
28 private final SchemaPath targetPath;
29 RevisionAwareXPath whenCondition;
33 ImmutableList<UnknownSchemaNode> unknownNodes;
34 private AugmentationSchema copyOf;
36 public AugmentationSchemaImpl(final SchemaPath targetPath, final int order, final AugmentationSchemaBuilderImpl builder) {
38 this.targetPath = targetPath;
42 public void setCopyOf(final AugmentationSchema build) {
47 public Optional<AugmentationSchema> getOriginalDefinition() {
48 return Optional.fromNullable(this.copyOf);
52 public SchemaPath getTargetPath() {
57 public RevisionAwareXPath getWhenCondition() {
62 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
67 public URI getNamespace() {
72 public Date getRevision() {
77 public int hashCode() {
80 result = prime * result + ((targetPath == null) ? 0 : targetPath.hashCode());
81 result = prime * result + ((whenCondition == null) ? 0 : whenCondition.hashCode());
82 result = prime * result + getChildNodes().hashCode();
87 public boolean equals(final Object obj) {
94 if (getClass() != obj.getClass()) {
97 AugmentationSchemaImpl other = (AugmentationSchemaImpl) obj;
98 if (targetPath == null) {
99 if (other.targetPath != null) {
102 } else if (!targetPath.equals(other.targetPath)) {
105 if (whenCondition == null) {
106 if (other.whenCondition != null) {
109 } else if (!whenCondition.equals(other.whenCondition)) {
112 if (!getChildNodes().equals(other.getChildNodes())) {
119 public String toString() {
120 StringBuilder sb = new StringBuilder(AugmentationSchemaImpl.class.getSimpleName());
122 sb.append("targetPath=").append(targetPath);
123 sb.append(", when=").append(whenCondition);
125 return sb.toString();
129 public int compareTo(final AugmentationSchemaImpl o) {
131 Iterator<QName> thisIt = this.targetPath.getPathFromRoot().iterator();
132 Iterator<QName> otherIt = o.getTargetPath().getPathFromRoot().iterator();
133 while (thisIt.hasNext()) {
134 if (otherIt.hasNext()) {
135 int comp = thisIt.next().compareTo(otherIt.next());
143 if (otherIt.hasNext()) {
146 return this.order - o.order;