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 java.util.Objects;
19 import org.opendaylight.yangtools.yang.common.QName;
20 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
21 import org.opendaylight.yangtools.yang.model.api.NamespaceRevisionAware;
22 import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
23 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
24 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
25 import org.opendaylight.yangtools.yang.parser.builder.util.AbstractDocumentedDataNodeContainer;
27 final class AugmentationSchemaImpl extends AbstractDocumentedDataNodeContainer implements AugmentationSchema, NamespaceRevisionAware, Comparable<AugmentationSchemaImpl> {
28 private final int order;
29 private final SchemaPath targetPath;
30 RevisionAwareXPath whenCondition;
34 ImmutableList<UnknownSchemaNode> unknownNodes;
35 private AugmentationSchema copyOf;
37 public AugmentationSchemaImpl(final SchemaPath targetPath, final int order, final AugmentationSchemaBuilderImpl builder) {
39 this.targetPath = targetPath;
43 public void setCopyOf(final AugmentationSchema build) {
48 public Optional<AugmentationSchema> getOriginalDefinition() {
49 return Optional.fromNullable(this.copyOf);
53 public SchemaPath getTargetPath() {
58 public RevisionAwareXPath getWhenCondition() {
63 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
68 public URI getNamespace() {
73 public Date getRevision() {
78 public int hashCode() {
81 result = prime * result + Objects.hashCode(targetPath);
82 result = prime * result + Objects.hashCode(whenCondition);
83 result = prime * result + getChildNodes().hashCode();
88 public boolean equals(final Object obj) {
95 if (getClass() != obj.getClass()) {
98 AugmentationSchemaImpl other = (AugmentationSchemaImpl) obj;
99 if (targetPath == null) {
100 if (other.targetPath != null) {
103 } else if (!targetPath.equals(other.targetPath)) {
106 if (whenCondition == null) {
107 if (other.whenCondition != null) {
110 } else if (!whenCondition.equals(other.whenCondition)) {
113 if (!getChildNodes().equals(other.getChildNodes())) {
120 public String toString() {
121 StringBuilder sb = new StringBuilder(AugmentationSchemaImpl.class.getSimpleName());
123 sb.append("targetPath=").append(targetPath);
124 sb.append(", when=").append(whenCondition);
126 return sb.toString();
130 public int compareTo(final AugmentationSchemaImpl o) {
132 Iterator<QName> thisIt = this.targetPath.getPathFromRoot().iterator();
133 Iterator<QName> otherIt = o.getTargetPath().getPathFromRoot().iterator();
134 while (thisIt.hasNext()) {
135 if (otherIt.hasNext()) {
136 int comp = thisIt.next().compareTo(otherIt.next());
144 if (otherIt.hasNext()) {
147 return this.order - o.order;