-/**
+/*
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.Set;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
import org.opendaylight.yangtools.yang.parser.spi.GroupingNamespace;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
-public class UsesEffectiveStatementImpl extends EffectiveStatementBase<QName, UsesStatement> implements UsesNode {
- private SchemaPath groupingPath;
- private boolean addedByUses;
- ImmutableMap<SchemaPath, SchemaNode> refines;
- ImmutableSet<AugmentationSchema> augmentations;
- ImmutableList<UnknownSchemaNode> unknownNodes;
+public final class UsesEffectiveStatementImpl extends DeclaredEffectiveStatementBase<QName, UsesStatement> implements UsesNode {
+ private final SchemaPath groupingPath;
+ private final boolean addedByUses;
+ private final Map<SchemaPath, SchemaNode> refines;
+ private final Set<AugmentationSchema> augmentations;
+ private final List<UnknownSchemaNode> unknownNodes;
- public UsesEffectiveStatementImpl(StmtContext<QName, UsesStatement, EffectiveStatement<QName, UsesStatement>> ctx) {
+ public UsesEffectiveStatementImpl(
+ final StmtContext<QName, UsesStatement, EffectiveStatement<QName, UsesStatement>> ctx) {
super(ctx);
- initGroupingPath(ctx);
- initCopyType(ctx);
- initSubstatementCollections();
- }
-
- private void initGroupingPath(StmtContext<QName, UsesStatement, EffectiveStatement<QName, UsesStatement>> ctx) {
+ // initGroupingPath
StmtContext<?, GroupingStatement, EffectiveStatement<QName, GroupingStatement>> grpCtx = ctx.getFromNamespace(
GroupingNamespace.class, ctx.getStatementArgument());
- this.groupingPath = Utils.getSchemaPath(grpCtx);
- }
+ this.groupingPath = grpCtx.getSchemaPath().get();
- private void initSubstatementCollections() {
- Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
+ // initCopyType
+ List<TypeOfCopy> copyTypesFromOriginal = ctx.getCopyHistory();
+ if (copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES)) {
+ addedByUses = true;
+ } else {
+ addedByUses = false;
+ }
+ // initSubstatementCollections
+ Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
Set<AugmentationSchema> augmentationsInit = new HashSet<>();
Map<SchemaPath, SchemaNode> refinesInit = new HashMap<>();
-
for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
if (effectiveStatement instanceof UnknownSchemaNode) {
UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
if (effectiveStatement instanceof RefineEffectiveStatementImpl) {
RefineEffectiveStatementImpl refineStmt = (RefineEffectiveStatementImpl) effectiveStatement;
SchemaNodeIdentifier identifier = refineStmt.argument();
- refinesInit.put(Utils.SchemaNodeIdentifierToSchemaPath(identifier), refineStmt.getRefineTargetNode());
+ refinesInit.put(identifier.asSchemaPath(), refineStmt.getRefineTargetNode());
}
}
-
this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
this.augmentations = ImmutableSet.copyOf(augmentationsInit);
this.refines = ImmutableMap.copyOf(refinesInit);
}
- private void initCopyType(
- StmtContext<QName, UsesStatement, EffectiveStatement<QName, UsesStatement>> ctx) {
-
- List<TypeOfCopy> copyTypesFromOriginal = ctx.getCopyHistory();
- if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES)) {
- addedByUses = true;
- }
- }
-
@Override
public SchemaPath getGroupingPath() {
return groupingPath;
return addedByUses;
}
- void setAddedByUses(final boolean addedByUses) {
- this.addedByUses = addedByUses;
- }
-
@Override
public Map<SchemaPath, SchemaNode> getRefines() {
return refines;
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + ((groupingPath == null) ? 0 : groupingPath.hashCode());
- result = prime * result + ((augmentations == null) ? 0 : augmentations.hashCode());
+ result = prime * result + Objects.hashCode(groupingPath);
+ result = prime * result + Objects.hashCode(augmentations);
return result;
}
return false;
}
final UsesEffectiveStatementImpl other = (UsesEffectiveStatementImpl) obj;
- if (groupingPath == null) {
- if (other.groupingPath != null) {
- return false;
- }
- } else if (!groupingPath.equals(other.groupingPath)) {
- return false;
- }
- if (augmentations == null) {
- if (other.augmentations != null) {
- return false;
- }
- } else if (!augmentations.equals(other.augmentations)) {
- return false;
- }
- return true;
+ return Objects.equals(groupingPath, other.groupingPath) && Objects.equals(augmentations, other.augmentations);
}
@Override
public String toString() {
- StringBuilder sb = new StringBuilder(UsesEffectiveStatementImpl.class.getSimpleName());
- sb.append("[groupingPath=");
- sb.append(groupingPath);
- sb.append("]");
- return sb.toString();
+ return UsesEffectiveStatementImpl.class.getSimpleName() + "[groupingPath=" +
+ groupingPath +
+ "]";
}
-}
\ No newline at end of file
+}