Bug 3670 (part 1/5): Use of new statement parser in yang-maven-plugin
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / effective / CaseShorthandImpl.java
index 8554da34dfb3c8e4e2a7b5e9fb4f1a00168c976f..54d927f617b657cb5f4d717a348381d10d7cc6a1 100644 (file)
@@ -7,6 +7,10 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
 
+import com.google.common.collect.ImmutableList;
+import com.google.common.base.Optional;
+import org.opendaylight.yangtools.yang.model.api.SchemaNode;
+import org.opendaylight.yangtools.yang.model.api.DerivableSchemaNode;
 import com.google.common.collect.Iterables;
 import java.util.Collections;
 import java.util.Arrays;
@@ -25,12 +29,23 @@ import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
 
-public class CaseShorthandImpl implements ChoiceCaseNode {
+public class CaseShorthandImpl implements ChoiceCaseNode, DerivableSchemaNode {
 
     private final DataSchemaNode caseShorthandNode;
     private final QName qName;
     private final SchemaPath path;
 
+    private final String description;
+    private final String reference;
+    private final Status status;
+
+    private final boolean augmenting;
+    private final boolean addedByUses;
+    ConstraintDefinition constraints;
+    private ChoiceCaseNode original;
+
+    ImmutableList<UnknownSchemaNode> unknownNodes;
+
     public CaseShorthandImpl(DataSchemaNode caseShorthandNode) {
         this.caseShorthandNode = caseShorthandNode;
         this.qName = caseShorthandNode.getQName();
@@ -41,31 +56,40 @@ public class CaseShorthandImpl implements ChoiceCaseNode {
                 .create(Iterables.limit(pathFromRoot,
                         Iterables.size(pathFromRoot) - 1),
                         caseShorthandNodePath.isAbsolute());
+
+        this.description = caseShorthandNode.getDescription();
+        this.reference = caseShorthandNode.getReference();
+        this.status = caseShorthandNode.getStatus();
+
+        this.augmenting = caseShorthandNode.isAugmenting();
+        this.addedByUses = caseShorthandNode.isAddedByUses();
+        this.constraints = caseShorthandNode.getConstraints();
+        this.unknownNodes = ImmutableList.copyOf(caseShorthandNode.getUnknownSchemaNodes());
     }
 
     @Override
     public boolean isAugmenting() {
-        return caseShorthandNode.isAugmenting();
+        return augmenting;
     }
 
     @Override
     public boolean isAddedByUses() {
-        return caseShorthandNode.isAddedByUses();
+        return addedByUses;
     }
 
     @Override
     public boolean isConfiguration() {
-        return caseShorthandNode.isConfiguration();
+        return false;
     }
 
     @Override
     public ConstraintDefinition getConstraints() {
-        return caseShorthandNode.getConstraints();
+        return constraints;
     }
 
     @Override
     public QName getQName() {
-        return caseShorthandNode.getQName();
+        return qName;
     }
 
     @Override
@@ -75,22 +99,22 @@ public class CaseShorthandImpl implements ChoiceCaseNode {
 
     @Override
     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
-        return caseShorthandNode.getUnknownSchemaNodes();
+        return unknownNodes;
     }
 
     @Override
     public String getDescription() {
-        return caseShorthandNode.getDescription();
+        return description;
     }
 
     @Override
     public String getReference() {
-        return caseShorthandNode.getReference();
+        return reference;
     }
 
     @Override
     public Status getStatus() {
-        return caseShorthandNode.getStatus();
+        return status;
     }
 
     @Override
@@ -135,4 +159,59 @@ public class CaseShorthandImpl implements ChoiceCaseNode {
     public Set<AugmentationSchema> getAvailableAugmentations() {
         return Collections.emptySet();
     }
+
+    @Override
+    public Optional<? extends SchemaNode> getOriginal() {
+        return Optional.fromNullable(original);
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((qName == null) ? 0 : qName.hashCode());
+        result = prime * result + ((path == null) ? 0 : path.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(final Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        CaseShorthandImpl other = (CaseShorthandImpl) obj;
+        if (qName == null) {
+            if (other.qName != null) {
+                return false;
+            }
+        } else if (!qName.equals(other.qName)) {
+            return false;
+        }
+        if (path == null) {
+            if (other.path != null) {
+                return false;
+            }
+        } else if (!path.equals(other.path)) {
+            return false;
+        }
+        return true;
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder(
+                CaseShorthandImpl.class.getSimpleName());
+        sb.append("[");
+        sb.append("qname=");
+        sb.append(qName);
+        sb.append("]");
+        return sb.toString();
+    }
+
 }
\ No newline at end of file