*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
-import java.util.LinkedList;
+import com.google.common.collect.ImmutableList;
+import java.util.ArrayList;
import java.util.List;
-
+import java.util.Objects;
import org.opendaylight.yangtools.concepts.Immutable;
import org.opendaylight.yangtools.yang.model.api.Deviation;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import com.google.common.collect.ImmutableList;
-
-public class DeviationEffectiveStatementImpl extends EffectiveStatementBase<SchemaNodeIdentifier, DeviationStatement>
+public class DeviationEffectiveStatementImpl extends DeclaredEffectiveStatementBase<SchemaNodeIdentifier, DeviationStatement>
implements Deviation, Immutable {
+ private final SchemaPath targetPath;
+ private final Deviate deviate;
+ private final String reference;
+ private final List<UnknownSchemaNode> unknownSchemaNodes;
- private SchemaPath targetPath;
- private Deviate deviate;
- private String reference;
- private ImmutableList<UnknownSchemaNode> unknownSchemaNodes;
-
- public DeviationEffectiveStatementImpl(StmtContext<SchemaNodeIdentifier, DeviationStatement, ?> ctx) {
+ public DeviationEffectiveStatementImpl(final StmtContext<SchemaNodeIdentifier, DeviationStatement, ?> ctx) {
super(ctx);
+ this.targetPath = ctx.getStatementArgument().asSchemaPath();
- List<UnknownSchemaNode> unknownSchemaNodesInit = new LinkedList<>();
+ DeviateEffectiveStatementImpl deviateStmt = firstEffective(DeviateEffectiveStatementImpl.class);
+ this.deviate = (deviateStmt == null) ? null : deviateStmt.argument();
- targetPath = SchemaPath.create(ctx.getStatementArgument().getPathFromRoot(), ctx.getStatementArgument()
- .isAbsolute());
+ ReferenceEffectiveStatementImpl referenceStmt = firstEffective(ReferenceEffectiveStatementImpl.class);
+ this.reference = (referenceStmt == null) ? null : referenceStmt.argument();
+ List<UnknownSchemaNode> unknownSchemaNodesInit = new ArrayList<>();
for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
- if (effectiveStatement instanceof DeviateEffectiveStatementImpl) {
- deviate = ((DeviateEffectiveStatementImpl) effectiveStatement).argument();
- }
- if (effectiveStatement instanceof ReferenceEffectiveStatementImpl) {
- reference = ((ReferenceEffectiveStatementImpl) effectiveStatement).argument();
- }
if (effectiveStatement instanceof UnknownSchemaNode) {
unknownSchemaNodesInit.add((UnknownSchemaNode) effectiveStatement);
}
}
-
unknownSchemaNodes = ImmutableList.copyOf(unknownSchemaNodesInit);
}
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + ((targetPath == null) ? 0 : targetPath.hashCode());
- result = prime * result + ((deviate == null) ? 0 : deviate.hashCode());
- result = prime * result + ((reference == null) ? 0 : reference.hashCode());
+ result = prime * result + Objects.hashCode(targetPath);
+ result = prime * result + Objects.hashCode(deviate);
+ result = prime * result + Objects.hashCode(reference);
return result;
}
@Override
- public boolean equals(Object obj) {
+ public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
return false;
}
DeviationEffectiveStatementImpl other = (DeviationEffectiveStatementImpl) obj;
- if (targetPath == null) {
- if (other.targetPath != null) {
- return false;
- }
- } else if (!targetPath.equals(other.targetPath)) {
+ if (!Objects.equals(targetPath, other.targetPath)) {
return false;
}
- if (deviate == null) {
- if (other.deviate != null) {
- return false;
- }
- } else if (!deviate.equals(other.deviate)) {
+ if (!Objects.equals(deviate, other.deviate)) {
return false;
}
- if (reference == null) {
- if (other.reference != null) {
- return false;
- }
- } else if (!reference.equals(other.reference)) {
+ if (!Objects.equals(reference, other.reference)) {
return false;
}
return true;
@Override
public String toString() {
- StringBuilder sb = new StringBuilder(DeviationEffectiveStatementImpl.class.getSimpleName());
- sb.append("[");
- sb.append("targetPath=").append(targetPath);
- sb.append(", deviate=").append(deviate);
- sb.append(", reference=").append(reference);
- sb.append("]");
- return sb.toString();
+ return DeviationEffectiveStatementImpl.class.getSimpleName() + "[" +
+ "targetPath=" + targetPath +
+ ", deviate=" + deviate +
+ ", reference=" + reference +
+ "]";
}
-}
\ No newline at end of file
+}