Add AbstractEffectiveDocumentedNodeWithoutStatus
[yangtools.git] / yang / yang-parser-rfc7950 / src / main / java / org / opendaylight / yangtools / yang / parser / rfc7950 / stmt / deviation / DeviationEffectiveStatementImpl.java
index 55fd25db6077ef93f419691f3095555dffea8678..63951ecf4157044807112bfcf64627da7ecd5018 100644 (file)
@@ -11,7 +11,6 @@ import com.google.common.collect.ImmutableList;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Objects;
-import java.util.Optional;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.concepts.Immutable;
 import org.opendaylight.yangtools.yang.model.api.DeviateDefinition;
@@ -19,32 +18,24 @@ import org.opendaylight.yangtools.yang.model.api.Deviation;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.DeviationEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.DeviationStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
-import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.DeclaredEffectiveStatementBase;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractEffectiveDocumentedNodeWithoutStatus;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 
 final class DeviationEffectiveStatementImpl
-        extends DeclaredEffectiveStatementBase<SchemaNodeIdentifier, DeviationStatement>
+        extends AbstractEffectiveDocumentedNodeWithoutStatus<SchemaNodeIdentifier, DeviationStatement>
         implements Deviation, DeviationEffectiveStatement, Immutable {
     private final SchemaPath targetPath;
-    private final String description;
-    private final String reference;
     private final @NonNull ImmutableList<UnknownSchemaNode> unknownSchemaNodes;
     private final ImmutableList<DeviateDefinition> deviateDefinitions;
 
     DeviationEffectiveStatementImpl(final StmtContext<SchemaNodeIdentifier, DeviationStatement, ?> ctx) {
         super(ctx);
         this.targetPath = ctx.getStatementArgument().asSchemaPath();
-
         this.deviateDefinitions = ImmutableList.copyOf(allSubstatementsOfType(DeviateDefinition.class));
 
-        description = findFirstEffectiveSubstatementArgument(DescriptionEffectiveStatement.class).orElse(null);
-        reference = findFirstEffectiveSubstatementArgument(ReferenceEffectiveStatement.class).orElse(null);
-
         List<UnknownSchemaNode> unknownSchemaNodesInit = new ArrayList<>();
         for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
             if (effectiveStatement instanceof UnknownSchemaNode) {
@@ -64,16 +55,6 @@ final class DeviationEffectiveStatementImpl
         return deviateDefinitions;
     }
 
-    @Override
-    public Optional<String> getDescription() {
-        return Optional.ofNullable(description);
-    }
-
-    @Override
-    public Optional<String> getReference() {
-        return Optional.ofNullable(reference);
-    }
-
     @Override
     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
         return unknownSchemaNodes;
@@ -81,7 +62,7 @@ final class DeviationEffectiveStatementImpl
 
     @Override
     public int hashCode() {
-        return Objects.hash(targetPath, deviateDefinitions, description, reference);
+        return Objects.hash(targetPath, deviateDefinitions, nullableDescription(), nullableReference());
     }
 
     @Override
@@ -95,7 +76,8 @@ final class DeviationEffectiveStatementImpl
         final DeviationEffectiveStatementImpl other = (DeviationEffectiveStatementImpl) obj;
         return Objects.equals(targetPath, other.targetPath)
                 && Objects.equals(deviateDefinitions, other.deviateDefinitions)
-                && Objects.equals(description, other.description) && Objects.equals(reference, other.reference);
+                && Objects.equals(nullableDescription(),  other.nullableDescription())
+                && Objects.equals(nullableReference(), other.nullableReference());
     }
 
     @Override
@@ -103,8 +85,8 @@ final class DeviationEffectiveStatementImpl
         return DeviationEffectiveStatementImpl.class.getSimpleName() + "["
                 + "targetPath=" + targetPath
                 + ", deviates=" + deviateDefinitions
-                + ", description=" + description
-                + ", reference=" + reference
+                + ", description=" + nullableDescription()
+                + ", reference=" + nullableReference()
                 + "]";
     }
 }