From: Robert Varga Date: Thu, 30 Sep 2021 14:02:06 +0000 (+0200) Subject: Add a few more utilities to EffectiveModelContext X-Git-Tag: v8.0.0~220 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=ca3189d0b22aa7fd30a055e7cdd1e604502e620f;p=yangtools.git Add a few more utilities to EffectiveModelContext Locating modules by name/namespace is useful, provide a simple bridge on top of SchemaContext.findModules(). JIRA: YANGTOOLS-1337 Change-Id: I08968d6aebb1569ab8990cd69352c56ddcfe5cc3 Signed-off-by: Robert Varga --- diff --git a/model/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/EffectiveModelContext.java b/model/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/EffectiveModelContext.java index fd57e659dd..ab71c68a7a 100644 --- a/model/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/EffectiveModelContext.java +++ b/model/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/EffectiveModelContext.java @@ -11,11 +11,14 @@ import static com.google.common.base.Verify.verifyNotNull; import static java.util.Objects.requireNonNull; import com.google.common.annotations.Beta; +import com.google.common.collect.Collections2; +import java.util.Collection; import java.util.Map; import java.util.Optional; import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.common.QNameModule; +import org.opendaylight.yangtools.yang.common.XMLNamespace; import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement; import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement; import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier; @@ -43,6 +46,29 @@ public interface EffectiveModelContext extends SchemaContext, SchemaTreeRoot { return findModuleStatement(moduleName.getModule()); } + /** + * Returns module instances (from the context) with a concrete name. Returned collection is required to have its + * iteration order guarantee that the latest revision is encountered first. + * + * @param name string with the module name + * @return set of module instances with specified name. + */ + default @NonNull Collection<@NonNull ModuleEffectiveStatement> findModuleStatements(final String name) { + return Collections2.transform(findModules(name), Module::asEffectiveStatement); + } + + /** + * Returns module instance (from the context) with concrete namespace. Returned collection is required to have its + * iteration order guarantee that the latest revision is encountered first. + * + * @param namespace XMLNamespace instance with specified namespace + * @return module instance which has namespace equal to the {@code namespace} or {@code null} in other cases + */ + default @NonNull Collection<@NonNull ModuleEffectiveStatement> findModuleStatements( + final XMLNamespace namespace) { + return Collections2.transform(findModules(namespace), Module::asEffectiveStatement); + } + default @NonNull ModuleEffectiveStatement getModuleStatement(final QNameModule moduleName) { return verifyNotNull(getModuleStatements().get(requireNonNull(moduleName))); }