package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
-import java.util.Collection;
-import java.util.LinkedList;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
import java.util.List;
+import java.util.Objects;
+import javax.annotation.Nonnull;
+import java.util.Set;
import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.ActionDefinition;
import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
+import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
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.GroupingStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.CopyType;
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 GroupingEffectiveStatementImpl extends
AbstractEffectiveDocumentedDataNodeContainer<QName, GroupingStatement> implements GroupingDefinition {
private final QName qname;
private final SchemaPath path;
-
- private boolean addedByUses;
- private List<UnknownSchemaNode> unknownNodes;
+ private final boolean addedByUses;
+ private final Set<ActionDefinition> actions;
+ private final Set<NotificationDefinition> notifications;
+ private final List<UnknownSchemaNode> unknownNodes;
public GroupingEffectiveStatementImpl(
- StmtContext<QName, GroupingStatement, EffectiveStatement<QName, GroupingStatement>> ctx) {
+ final StmtContext<QName, GroupingStatement, EffectiveStatement<QName, GroupingStatement>> ctx) {
super(ctx);
qname = ctx.getStatementArgument();
- path = Utils.getSchemaPath(ctx);
-
- initCopyType(ctx);
- initSubstatementCollections();
- }
+ path = ctx.getSchemaPath().get();
- private void initCopyType(
- StmtContext<QName, GroupingStatement, EffectiveStatement<QName, GroupingStatement>> ctx) {
+ addedByUses = ctx.getCopyHistory().contains(CopyType.ADDED_BY_USES);
- List<TypeOfCopy> copyTypesFromOriginal = ctx.getCopyHistory();
-
- if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES)) {
- addedByUses = true;
- }
- }
-
- private void initSubstatementCollections() {
- Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
+ final ImmutableSet.Builder<ActionDefinition> actionsBuilder = ImmutableSet.builder();
+ final ImmutableSet.Builder<NotificationDefinition> notificationsBuilder = ImmutableSet.builder();
+ final ImmutableList.Builder<UnknownSchemaNode> b = ImmutableList.builder();
+ for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
+ if (effectiveStatement instanceof ActionDefinition) {
+ actionsBuilder.add((ActionDefinition) effectiveStatement);
+ }
- unknownNodes = new LinkedList<>();
+ if (effectiveStatement instanceof NotificationDefinition) {
+ notificationsBuilder.add((NotificationDefinition) effectiveStatement);
+ }
- for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
if (effectiveStatement instanceof UnknownSchemaNode) {
- UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
- unknownNodes.add(unknownNode);
+ b.add((UnknownSchemaNode) effectiveStatement);
}
}
+ this.actions = actionsBuilder.build();
+ this.notifications = notificationsBuilder.build();
+ unknownNodes = b.build();
}
+ @Nonnull
@Override
public QName getQName() {
return qname;
}
+ @Nonnull
@Override
public SchemaPath getPath() {
return path;
return addedByUses;
}
+ @Override
+ public Set<ActionDefinition> getActions() {
+ return actions;
+ }
+
+ @Nonnull
+ @Override
+ public Set<NotificationDefinition> getNotifications() {
+ return notifications;
+ }
+
@Override
public List<UnknownSchemaNode> getUnknownSchemaNodes() {
return unknownNodes;
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(qname);
+ result = prime * result + Objects.hashCode(path);
return result;
}
return false;
}
final GroupingEffectiveStatementImpl other = (GroupingEffectiveStatementImpl) 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(GroupingEffectiveStatementImpl.class.getSimpleName());
- sb.append("[");
- sb.append("qname=").append(qname);
- sb.append("]");
- return sb.toString();
+ return GroupingEffectiveStatementImpl.class.getSimpleName() + "[" + "qname=" + qname + "]";
}
-}
\ No newline at end of file
+}