Preserve augmentation order in module.
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / effective / ContainerEffectiveStatementImpl.java
index 7f73373a1dc30f8aebe24c8dc97bb4cb2f604028..764e80d81b56401409db48cd57ef2f8b0c90c24f 100644 (file)
@@ -1,4 +1,4 @@
-/**
+/*
  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
 
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.ImmutableList;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.Collection;
-import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.ContainerStatement;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 import com.google.common.base.Optional;
-import java.util.List;
-import java.util.Set;
+import java.util.Objects;
 import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
-import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.DerivableSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
-
-public class ContainerEffectiveStatementImpl extends
-        AbstractEffectiveDocumentedDataNodeContainer<QName, ContainerStatement>
-        implements ContainerSchemaNode, DerivableSchemaNode {
-
-    private final QName qname;
-    private final SchemaPath path;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ContainerStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 
-    private boolean presence;
-    boolean augmenting;
-    private boolean addedByUses;
-    private boolean configuration = true;
-    private ContainerSchemaNode original;
-    private ConstraintDefinition constraints;
+public final class ContainerEffectiveStatementImpl extends AbstractEffectiveContainerSchemaNode<ContainerStatement>
+        implements
+        DerivableSchemaNode {
 
-    private ImmutableSet<AugmentationSchema> augmentations;
-    private ImmutableList<UnknownSchemaNode> unknownNodes;
+    private final ContainerSchemaNode original;
 
     public ContainerEffectiveStatementImpl(
-            StmtContext<QName, ContainerStatement, EffectiveStatement<QName, ContainerStatement>> ctx) {
+            final StmtContext<QName, ContainerStatement, EffectiveStatement<QName, ContainerStatement>> ctx) {
         super(ctx);
-
-        qname = ctx.getStatementArgument();
-        path = Utils.getSchemaPath(ctx);
-        this.constraints = new EffectiveConstraintDefinitionImpl(this);
-
-        initCopyType(ctx);
-        initSubstatementCollectionsAndFields();
-    }
-
-    private void initCopyType(
-            StmtContext<QName, ContainerStatement, EffectiveStatement<QName, ContainerStatement>> ctx) {
-
-        List<TypeOfCopy> copyTypesFromOriginal = ctx.getCopyHistory();
-
-        if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_AUGMENTATION)) {
-            augmenting = true;
-        }
-        if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES)) {
-            addedByUses = true;
-        }
-        if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES_AUGMENTATION)) {
-            addedByUses = augmenting = true;
-        }
-
-        if (ctx.getOriginalCtx() != null) {
-            original = (ContainerSchemaNode) ctx.getOriginalCtx().buildEffective();
-        }
-    }
-
-    private void initSubstatementCollectionsAndFields() {
-        Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
-
-        List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
-        Set<AugmentationSchema> augmentationsInit = new HashSet<>();
-
-        boolean configurationInit = false;
-        for (EffectiveStatement<?, ?> effectiveSubstatement : effectiveSubstatements) {
-            if (effectiveSubstatement instanceof UnknownSchemaNode) {
-                UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveSubstatement;
-                unknownNodesInit.add(unknownNode);
-            }
-            if (effectiveSubstatement instanceof AugmentationSchema) {
-                AugmentationSchema augmentationSchema = (AugmentationSchema) effectiveSubstatement;
-                augmentationsInit.add(augmentationSchema);
-            }
-            if (effectiveSubstatement instanceof PresenceEffectiveStatementImpl) {
-                presence = true;
-            }
-            if (!configurationInit
-                    && effectiveSubstatement instanceof ConfigEffectiveStatementImpl) {
-                ConfigEffectiveStatementImpl configStmt = (ConfigEffectiveStatementImpl) effectiveSubstatement;
-                this.configuration = configStmt.argument();
-                configurationInit = true;
-            }
-        }
-
-        this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
-        this.augmentations = ImmutableSet.copyOf(augmentationsInit);
-    }
-
-    @Override
-    public QName getQName() {
-        return qname;
-    }
-
-    @Override
-    public SchemaPath getPath() {
-        return path;
-    }
-
-    @Override
-    public boolean isAugmenting() {
-        return augmenting;
-    }
-
-    @Override
-    public boolean isAddedByUses() {
-        return addedByUses;
+        this.original = ctx.getOriginalCtx() == null ? null : (ContainerSchemaNode) ctx.getOriginalCtx().buildEffective();
     }
 
     @Override
@@ -133,37 +33,12 @@ public class ContainerEffectiveStatementImpl extends
         return Optional.fromNullable(original);
     }
 
-    @Override
-    public boolean isConfiguration() {
-        return configuration;
-    }
-
-    @Override
-    public ConstraintDefinition getConstraints() {
-        return constraints;
-    }
-
-    @Override
-    public Set<AugmentationSchema> getAvailableAugmentations() {
-        return augmentations;
-    }
-
-    @Override
-    public boolean isPresenceContainer() {
-        return presence;
-    }
-
-    @Override
-    public List<UnknownSchemaNode> getUnknownSchemaNodes() {
-        return unknownNodes;
-    }
-
     @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());
+        result = prime * result + Objects.hashCode(getQName());
+        result = prime * result + Objects.hashCode(getPath());
         return result;
     }
 
@@ -179,25 +54,11 @@ public class ContainerEffectiveStatementImpl extends
             return false;
         }
         ContainerEffectiveStatementImpl other = (ContainerEffectiveStatementImpl) 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(getQName(), other.getQName()) && Objects.equals(getPath(), other.getPath());
     }
 
     @Override
     public String toString() {
-        return "container " + qname.getLocalName();
+        return "container " + getQName().getLocalName();
     }
-}
\ No newline at end of file
+}