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;
11 import com.google.common.base.Optional;
12 import com.google.common.collect.ImmutableList;
14 import java.util.Date;
15 import java.util.Iterator;
16 import java.util.List;
17 import java.util.Objects;
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;
27 * @deprecated Pre-Beryllium implementation, scheduled for removal.
30 final class AugmentationSchemaImpl extends AbstractDocumentedDataNodeContainer implements AugmentationSchema, NamespaceRevisionAware, Comparable<AugmentationSchemaImpl> {
31 private final int order;
32 private final SchemaPath targetPath;
33 RevisionAwareXPath whenCondition;
37 ImmutableList<UnknownSchemaNode> unknownNodes;
38 private AugmentationSchema copyOf;
40 public AugmentationSchemaImpl(final SchemaPath targetPath, final int order, final AugmentationSchemaBuilderImpl builder) {
42 this.targetPath = targetPath;
46 public void setCopyOf(final AugmentationSchema build) {
51 public Optional<AugmentationSchema> getOriginalDefinition() {
52 return Optional.fromNullable(this.copyOf);
56 public SchemaPath getTargetPath() {
61 public RevisionAwareXPath getWhenCondition() {
66 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
71 public URI getNamespace() {
76 public Date getRevision() {
81 public int hashCode() {
84 result = prime * result + Objects.hashCode(targetPath);
85 result = prime * result + Objects.hashCode(whenCondition);
86 result = prime * result + getChildNodes().hashCode();
91 public boolean equals(final Object obj) {
98 if (getClass() != obj.getClass()) {
101 AugmentationSchemaImpl other = (AugmentationSchemaImpl) obj;
102 if (targetPath == null) {
103 if (other.targetPath != null) {
106 } else if (!targetPath.equals(other.targetPath)) {
109 if (whenCondition == null) {
110 if (other.whenCondition != null) {
113 } else if (!whenCondition.equals(other.whenCondition)) {
116 if (!getChildNodes().equals(other.getChildNodes())) {
123 public String toString() {
124 StringBuilder sb = new StringBuilder(AugmentationSchemaImpl.class.getSimpleName());
126 sb.append("targetPath=").append(targetPath);
127 sb.append(", when=").append(whenCondition);
129 return sb.toString();
133 public int compareTo(final AugmentationSchemaImpl o) {
135 Iterator<QName> thisIt = this.targetPath.getPathFromRoot().iterator();
136 Iterator<QName> otherIt = o.getTargetPath().getPathFromRoot().iterator();
137 while (thisIt.hasNext()) {
138 if (otherIt.hasNext()) {
139 int comp = thisIt.next().compareTo(otherIt.next());
147 if (otherIt.hasNext()) {
150 return this.order - o.order;