BUG-865: deprecate pre-Beryllium parser elements
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / builder / impl / AugmentationSchemaImpl.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.parser.builder.impl;
9
10 import static com.google.common.base.Preconditions.checkNotNull;
11 import com.google.common.base.Optional;
12 import com.google.common.collect.ImmutableList;
13 import java.net.URI;
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;
25
26 /**
27  * @deprecated Pre-Beryllium implementation, scheduled for removal.
28  */
29 @Deprecated
30 final class AugmentationSchemaImpl extends AbstractDocumentedDataNodeContainer implements AugmentationSchema, NamespaceRevisionAware, Comparable<AugmentationSchemaImpl> {
31     private final int order;
32     private final SchemaPath targetPath;
33     RevisionAwareXPath whenCondition;
34
35     URI namespace;
36     Date revision;
37     ImmutableList<UnknownSchemaNode> unknownNodes;
38     private AugmentationSchema copyOf;
39
40     public AugmentationSchemaImpl(final SchemaPath targetPath, final int order, final AugmentationSchemaBuilderImpl builder) {
41         super(builder);
42         this.targetPath = targetPath;
43         this.order = order;
44     }
45
46     public void setCopyOf(final AugmentationSchema build) {
47         this.copyOf = build;
48     }
49
50     @Override
51     public Optional<AugmentationSchema> getOriginalDefinition() {
52         return Optional.fromNullable(this.copyOf);
53     }
54
55     @Override
56     public SchemaPath getTargetPath() {
57         return targetPath;
58     }
59
60     @Override
61     public RevisionAwareXPath getWhenCondition() {
62         return whenCondition;
63     }
64
65     @Override
66     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
67         return unknownNodes;
68     }
69
70     @Override
71     public URI getNamespace() {
72         return namespace;
73     }
74
75     @Override
76     public Date getRevision() {
77         return revision;
78     }
79
80     @Override
81     public int hashCode() {
82         final int prime = 17;
83         int result = 1;
84         result = prime * result + Objects.hashCode(targetPath);
85         result = prime * result + Objects.hashCode(whenCondition);
86         result = prime * result + getChildNodes().hashCode();
87         return result;
88     }
89
90     @Override
91     public boolean equals(final Object obj) {
92         if (this == obj) {
93             return true;
94         }
95         if (obj == null) {
96             return false;
97         }
98         if (getClass() != obj.getClass()) {
99             return false;
100         }
101         AugmentationSchemaImpl other = (AugmentationSchemaImpl) obj;
102         if (targetPath == null) {
103             if (other.targetPath != null) {
104                 return false;
105             }
106         } else if (!targetPath.equals(other.targetPath)) {
107             return false;
108         }
109         if (whenCondition == null) {
110             if (other.whenCondition != null) {
111                 return false;
112             }
113         } else if (!whenCondition.equals(other.whenCondition)) {
114             return false;
115         }
116         if (!getChildNodes().equals(other.getChildNodes())) {
117             return false;
118         }
119         return true;
120     }
121
122     @Override
123     public String toString() {
124         StringBuilder sb = new StringBuilder(AugmentationSchemaImpl.class.getSimpleName());
125         sb.append("[");
126         sb.append("targetPath=").append(targetPath);
127         sb.append(", when=").append(whenCondition);
128         sb.append("]");
129         return sb.toString();
130     }
131
132     @Override
133     public int compareTo(final AugmentationSchemaImpl o) {
134         checkNotNull(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());
140                 if (comp != 0) {
141                     return comp;
142                 }
143             } else {
144                 return 1;
145             }
146         }
147         if (otherIt.hasNext()) {
148             return -1;
149         }
150         return this.order - o.order;
151     }
152 }