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%2FSubmoduleEffectiveStatementImpl.java;h=dc3af809c769606b4cf19caeffabb80a734243a2;hb=b704d772ac1fb2bb55a5f817d2173274a7f83fab;hp=380bcb10ccb3c9c2073b3be0da9c907ff937e3af;hpb=84df4e154123c967fa22ac10bf6edf6f0e7a4e64;p=yangtools.git diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/SubmoduleEffectiveStatementImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/SubmoduleEffectiveStatementImpl.java index 380bcb10cc..dc3af809c7 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/SubmoduleEffectiveStatementImpl.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/SubmoduleEffectiveStatementImpl.java @@ -1,4 +1,4 @@ -/** +/* * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the @@ -7,250 +7,46 @@ */ package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective; -import java.net.URI; -import java.util.Collection; -import java.util.Date; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; - -import org.opendaylight.yangtools.concepts.Immutable; +import static org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils.firstAttributeOf; +import java.util.Objects; import org.opendaylight.yangtools.yang.common.QNameModule; -import org.opendaylight.yangtools.yang.model.api.AugmentationSchema; -import org.opendaylight.yangtools.yang.model.api.Deviation; -import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition; -import org.opendaylight.yangtools.yang.model.api.FeatureDefinition; -import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode; -import org.opendaylight.yangtools.yang.model.api.Module; -import org.opendaylight.yangtools.yang.model.api.ModuleImport; -import org.opendaylight.yangtools.yang.model.api.NotificationDefinition; -import org.opendaylight.yangtools.yang.model.api.RpcDefinition; -import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode; +import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil; import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement; import org.opendaylight.yangtools.yang.model.api.stmt.BelongsToStatement; import org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleStatement; -import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleImpl; import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToModuleQName; -import static org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils.firstAttributeOf; - -public class SubmoduleEffectiveStatementImpl extends - AbstractEffectiveDocumentedDataNodeContainer implements Module, Immutable { +public final class SubmoduleEffectiveStatementImpl extends AbstractEffectiveModule { private final QNameModule qNameModule; - private final String name; - private String sourcePath; - private String prefix; - private String yangVersion; - private String organization; - private String contact; - private ImmutableSet imports; - private ImmutableSet submodules; - private ImmutableSet features; - private ImmutableSet notifications; - private ImmutableSet augmentations; - private ImmutableSet rpcs; - private ImmutableSet deviations; - private ImmutableList extensionNodes; - private ImmutableSet identities; - private ImmutableList unknownNodes; - private String source; - public SubmoduleEffectiveStatementImpl(StmtContext ctx) { + public SubmoduleEffectiveStatementImpl( + final StmtContext> ctx) { super(ctx); - name = argument(); - String belongsToModuleName = firstAttributeOf(ctx.declaredSubstatements(), BelongsToStatement.class); - final QNameModule belongsToModule = ctx.getFromNamespace(ModuleNameToModuleQName.class, belongsToModuleName); - qNameModule = QNameModule.create(belongsToModule.getNamespace(), belongsToModule.getRevision()); - - for (EffectiveStatement effectiveStatement : effectiveSubstatements()) { - if (effectiveStatement instanceof PrefixEffectiveStatementImpl) { - prefix = ((PrefixEffectiveStatementImpl) effectiveStatement).argument(); - } - if (effectiveStatement instanceof YangVersionEffectiveStatementImpl) { - yangVersion = ((YangVersionEffectiveStatementImpl) effectiveStatement).argument(); - } - if (effectiveStatement instanceof OrganizationEffectiveStatementImpl) { - organization = ((OrganizationEffectiveStatementImpl) effectiveStatement).argument(); - } - if (effectiveStatement instanceof ContactEffectiveStatementImpl) { - contact = ((ContactEffectiveStatementImpl) effectiveStatement).argument(); - } - } - - source = ctx.getStatementSource().name(); - - initSubstatementCollections(); - } - - private void initSubstatementCollections() { - Collection> effectiveSubstatements = effectiveSubstatements(); - - List unknownNodesInit = new LinkedList<>(); - Set augmentationsInit = new HashSet<>(); - Set importsInit = new HashSet<>(); - Set submodulesInit = new HashSet<>(); - Set notificationsInit = new HashSet<>(); - Set rpcsInit = new HashSet<>(); - Set deviationsInit = new HashSet<>(); - Set identitiesInit = new HashSet<>(); - Set featuresInit = new HashSet<>(); - List extensionNodesInit = new LinkedList<>(); - - for (EffectiveStatement effectiveStatement : effectiveSubstatements) { - if (effectiveStatement instanceof UnknownSchemaNode) { - unknownNodesInit.add((UnknownSchemaNode) effectiveStatement); - } - if (effectiveStatement instanceof AugmentationSchema) { - augmentationsInit.add((AugmentationSchema) effectiveStatement); - } - if (effectiveStatement instanceof ModuleImport) { - importsInit.add((ModuleImport) effectiveStatement); - } - if (effectiveStatement instanceof Module) { - submodulesInit.add((Module) effectiveStatement); - } - if (effectiveStatement instanceof NotificationDefinition) { - notificationsInit.add((NotificationDefinition) effectiveStatement); - } - if (effectiveStatement instanceof RpcDefinition) { - rpcsInit.add((RpcDefinition) effectiveStatement); - } - if (effectiveStatement instanceof Deviation) { - deviationsInit.add((Deviation) effectiveStatement); - } - if (effectiveStatement instanceof IdentitySchemaNode) { - identitiesInit.add((IdentitySchemaNode) effectiveStatement); - } - if (effectiveStatement instanceof FeatureDefinition) { - featuresInit.add((FeatureDefinition) effectiveStatement); - } - if (effectiveStatement instanceof ExtensionDefinition) { - extensionNodesInit.add((ExtensionDefinition) effectiveStatement); - } - } - - this.unknownNodes = ImmutableList.copyOf(unknownNodesInit); - this.augmentations = ImmutableSet.copyOf(augmentationsInit); - this.imports = ImmutableSet.copyOf(importsInit); - this.submodules = ImmutableSet.copyOf(submodulesInit); - this.notifications = ImmutableSet.copyOf(notificationsInit); - this.rpcs = ImmutableSet.copyOf(rpcsInit); - this.deviations = ImmutableSet.copyOf(deviationsInit); - this.identities = ImmutableSet.copyOf(identitiesInit); - this.features = ImmutableSet.copyOf(featuresInit); - this.extensionNodes = ImmutableList.copyOf(extensionNodesInit); - } - - @Override - public String getModuleSourcePath() { - return sourcePath; - } - - @Override - public URI getNamespace() { - return qNameModule.getNamespace(); - } - - @Override - public String getName() { - return name; - } - - @Override - public Date getRevision() { - return qNameModule.getRevision(); - } - - @Override - public String getPrefix() { - return prefix; - } - - @Override - public String getYangVersion() { - return yangVersion; - } - - @Override - public String getOrganization() { - return organization; - } - - @Override - public String getContact() { - return contact; - } - - @Override - public Set getImports() { - return imports; - } - - @Override - public Set getSubmodules() { - return submodules; - } - - @Override - public Set getFeatures() { - return features; - } - - @Override - public Set getNotifications() { - return notifications; - } - - @Override - public Set getAugmentations() { - return augmentations; - } + final QNameModule belongsToModuleQName = ctx.getFromNamespace(ModuleNameToModuleQName.class, + belongsToModuleName); + RevisionEffectiveStatementImpl submoduleRevision = firstEffective(RevisionEffectiveStatementImpl.class); - @Override - public Set getRpcs() { - return rpcs; + this.qNameModule = (submoduleRevision == null ? + QNameModule.create(belongsToModuleQName.getNamespace(), SimpleDateFormatUtil.DEFAULT_DATE_REV) : + QNameModule.create(belongsToModuleQName.getNamespace(), submoduleRevision.argument())).intern(); } @Override - public Set getDeviations() { - return deviations; - } - - @Override - public List getExtensionSchemaNodes() { - return extensionNodes; - } - - @Override - public Set getIdentities() { - return identities; - } - - @Override - public List getUnknownSchemaNodes() { - return unknownNodes; - } - - @Override - public String getSource() { - return source; + public QNameModule getQNameModule() { + return qNameModule; } @Override public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((name == null) ? 0 : name.hashCode()); - result = prime * result + ((yangVersion == null) ? 0 : yangVersion.hashCode()); - result = prime * result + qNameModule.hashCode(); + result = prime * result + Objects.hashCode(getName()); + result = prime * result + Objects.hashCode(getYangVersion()); + result = prime * result + Objects.hashCode(qNameModule); return result; } @@ -266,41 +62,16 @@ public class SubmoduleEffectiveStatementImpl extends return false; } SubmoduleEffectiveStatementImpl other = (SubmoduleEffectiveStatementImpl) obj; - if (name == null) { - if (other.name != null) { - return false; - } - } else if (!name.equals(other.name)) { + if (!Objects.equals(getName(), other.getName())) { return false; } if (!qNameModule.equals(other.qNameModule)) { return false; } - if (yangVersion == null) { - if (other.yangVersion != null) { - return false; - } - } else if (!yangVersion.equals(other.yangVersion)) { + if (!Objects.equals(getYangVersion(), other.getYangVersion())) { return false; } return true; } - @Override - public String toString() { - StringBuilder sb = new StringBuilder(ModuleImpl.class.getSimpleName()); - sb.append("["); - sb.append("name=").append(name); - sb.append(", namespace=").append(getNamespace()); - sb.append(", revision=").append(getRevision()); - sb.append(", prefix=").append(prefix); - sb.append(", yangVersion=").append(yangVersion); - sb.append("]"); - return sb.toString(); - } - - @Override - public QNameModule getQNameModule() { - return qNameModule; - } }