X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=yang%2Fyang-parser-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fparser%2Fstmt%2Frfc6020%2Feffective%2FAugmentEffectiveStatementImpl.java;h=9b9401189b896ad7833b965709b69642ff550958;hb=104b5d943c96fcdd30a5cf7ea3d79e6a55082c60;hp=837f179180bf71c88e6d89939896ea24a4cb249e;hpb=e99bf7da4cf4f715e6d899a8c41a8df2853e3055;p=yangtools.git diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/AugmentEffectiveStatementImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/AugmentEffectiveStatementImpl.java index 837f179180..9b9401189b 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/AugmentEffectiveStatementImpl.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/AugmentEffectiveStatementImpl.java @@ -7,20 +7,20 @@ */ package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective; -import static com.google.common.base.Preconditions.checkNotNull; - import com.google.common.base.Optional; import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; import java.net.URI; -import java.util.Collection; import java.util.Date; -import java.util.Iterator; import java.util.List; import java.util.Objects; -import org.opendaylight.yangtools.yang.common.QName; +import java.util.Set; +import javax.annotation.Nonnull; import org.opendaylight.yangtools.yang.common.QNameModule; +import org.opendaylight.yangtools.yang.model.api.ActionDefinition; import org.opendaylight.yangtools.yang.model.api.AugmentationSchema; import org.opendaylight.yangtools.yang.model.api.NamespaceRevisionAware; +import org.opendaylight.yangtools.yang.model.api.NotificationDefinition; import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath; import org.opendaylight.yangtools.yang.model.api.SchemaPath; import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode; @@ -28,15 +28,16 @@ import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement; import org.opendaylight.yangtools.yang.model.api.stmt.AugmentStatement; import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier; import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext; -import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils; +import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils; public final class AugmentEffectiveStatementImpl extends AbstractEffectiveDocumentedDataNodeContainer implements - AugmentationSchema, NamespaceRevisionAware, Comparable { + AugmentationSchema, NamespaceRevisionAware { private final SchemaPath targetPath; private final URI namespace; private final Date revision; - private final int order; + private final Set actions; + private final Set notifications; private final List unknownNodes; private final RevisionAwareXPath whenCondition; private final AugmentationSchema copyOf; @@ -47,24 +48,31 @@ public final class AugmentEffectiveStatementImpl extends this.targetPath = ctx.getStatementArgument().asSchemaPath(); - QNameModule rootModuleQName = Utils.getRootModuleQName(ctx); + final QNameModule rootModuleQName = StmtContextUtils.getRootModuleQName(ctx); this.namespace = rootModuleQName.getNamespace(); this.revision = rootModuleQName.getRevision(); - this.order = ctx.getOrder(); - this.copyOf = ctx.getOriginalCtx() == null ? null : (AugmentationSchema) ctx.getOriginalCtx().buildEffective(); + this.copyOf = (AugmentationSchema) ctx.getOriginalCtx().map(StmtContext::buildEffective).orElse(null); - WhenEffectiveStatementImpl whenStmt = firstEffective(WhenEffectiveStatementImpl.class); - this.whenCondition = (whenStmt == null) ? null : whenStmt.argument(); + final WhenEffectiveStatementImpl whenStmt = firstEffective(WhenEffectiveStatementImpl.class); + this.whenCondition = whenStmt == null ? null : whenStmt.argument(); // initSubstatementCollections - Collection> effectiveSubstatements = effectiveSubstatements(); - ImmutableList.Builder listBuilder = new ImmutableList.Builder<>(); - for (EffectiveStatement effectiveStatement : effectiveSubstatements) { - if (effectiveStatement instanceof UnknownSchemaNode) { + final ImmutableSet.Builder actionsBuilder = ImmutableSet.builder(); + final ImmutableSet.Builder notificationsBuilder = ImmutableSet.builder(); + final ImmutableList.Builder listBuilder = new ImmutableList.Builder<>(); + for (final EffectiveStatement effectiveStatement : effectiveSubstatements()) { + if (effectiveStatement instanceof ActionDefinition) { + actionsBuilder.add((ActionDefinition) effectiveStatement); + } else if (effectiveStatement instanceof NotificationDefinition) { + notificationsBuilder.add((NotificationDefinition) effectiveStatement); + } else if (effectiveStatement instanceof UnknownSchemaNode) { listBuilder.add((UnknownSchemaNode) effectiveStatement); } } + + this.actions = actionsBuilder.build(); + this.notifications = notificationsBuilder.build(); this.unknownNodes = listBuilder.build(); } @@ -83,6 +91,7 @@ public final class AugmentEffectiveStatementImpl extends return whenCondition; } + @Nonnull @Override public List getUnknownSchemaNodes() { return unknownNodes; @@ -93,6 +102,16 @@ public final class AugmentEffectiveStatementImpl extends return namespace; } + @Override + public Set getActions() { + return actions; + } + + @Override + public Set getNotifications() { + return notifications; + } + @Override public Date getRevision() { return revision; @@ -119,7 +138,7 @@ public final class AugmentEffectiveStatementImpl extends if (getClass() != obj.getClass()) { return false; } - AugmentEffectiveStatementImpl other = (AugmentEffectiveStatementImpl) obj; + final AugmentEffectiveStatementImpl other = (AugmentEffectiveStatementImpl) obj; if (!Objects.equals(targetPath, other.targetPath)) { return false; } @@ -134,32 +153,7 @@ public final class AugmentEffectiveStatementImpl extends @Override public String toString() { - StringBuilder sb = new StringBuilder(AugmentEffectiveStatementImpl.class.getSimpleName()); - sb.append("["); - sb.append("targetPath=").append(targetPath); - sb.append(", when=").append(whenCondition); - sb.append("]"); - return sb.toString(); - } - - @Override - public int compareTo(final AugmentEffectiveStatementImpl o) { - checkNotNull(o); - Iterator thisIt = this.targetPath.getPathFromRoot().iterator(); - Iterator otherIt = o.getTargetPath().getPathFromRoot().iterator(); - while (thisIt.hasNext()) { - if (otherIt.hasNext()) { - int comp = thisIt.next().compareTo(otherIt.next()); - if (comp != 0) { - return comp; - } - } else { - return 1; - } - } - if (otherIt.hasNext()) { - return -1; - } - return this.order - o.order; + return AugmentEffectiveStatementImpl.class.getSimpleName() + "[" + "targetPath=" + targetPath + ", when=" + + whenCondition + "]"; } }