Bug 4412: New yang parser effective statements cleanup
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / effective / CaseShorthandImpl.java
index aaa78c178eb4ab7db5bc2efe9a9fe228e48e14b6..ce54d65427ca47f3ccf9521e09e5a714ed4d4129 100644 (file)
@@ -8,8 +8,8 @@
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
 
 import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Iterables;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
@@ -35,29 +35,18 @@ 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;
+    private final ConstraintDefinition constraints;
+    private final List<UnknownSchemaNode> unknownNodes;
 
-    public CaseShorthandImpl(DataSchemaNode caseShorthandNode) {
+    public CaseShorthandImpl(final DataSchemaNode caseShorthandNode) {
         this.caseShorthandNode = caseShorthandNode;
         this.qName = caseShorthandNode.getQName();
-
-        SchemaPath caseShorthandNodePath = caseShorthandNode.getPath();
-        Iterable<QName> pathFromRoot = caseShorthandNodePath.getPathFromRoot();
-        this.path = SchemaPath
-                .create(Iterables.limit(pathFromRoot,
-                        Iterables.size(pathFromRoot) - 1),
-                        caseShorthandNodePath.isAbsolute());
-
+        this.path = Preconditions.checkNotNull(caseShorthandNode.getPath().getParent());
         this.description = caseShorthandNode.getDescription();
         this.reference = caseShorthandNode.getReference();
         this.status = caseShorthandNode.getStatus();
@@ -134,7 +123,7 @@ public class CaseShorthandImpl implements ChoiceCaseNode, DerivableSchemaNode {
     }
 
     @Override
-    public DataSchemaNode getDataChildByName(QName name) {
+    public DataSchemaNode getDataChildByName(final QName name) {
         if (qName.equals(name)) {
             return caseShorthandNode;
         } else {
@@ -143,7 +132,7 @@ public class CaseShorthandImpl implements ChoiceCaseNode, DerivableSchemaNode {
     }
 
     @Override
-    public DataSchemaNode getDataChildByName(String name) {
+    public DataSchemaNode getDataChildByName(final String name) {
         if (qName.getLocalName().equals(name)) {
             return caseShorthandNode;
         } else {
@@ -163,7 +152,7 @@ public class CaseShorthandImpl implements ChoiceCaseNode, DerivableSchemaNode {
 
     @Override
     public Optional<? extends SchemaNode> getOriginal() {
-        return Optional.fromNullable(original);
+        return Optional.absent();
     }
 
     @Override
@@ -187,32 +176,16 @@ public class CaseShorthandImpl implements ChoiceCaseNode, DerivableSchemaNode {
             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;
+        return Objects.equals(qName, other.qName) && Objects.equals(path, other.path);
     }
 
     @Override
     public String toString() {
-        StringBuilder sb = new StringBuilder(
-                CaseShorthandImpl.class.getSimpleName());
+        StringBuilder sb = new StringBuilder(CaseShorthandImpl.class.getSimpleName());
         sb.append("[");
         sb.append("qname=");
         sb.append(qName);
         sb.append("]");
         return sb.toString();
     }
-
 }