From 56794e0e6d94cd3d3378e9bce63f3b66a9319906 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Sun, 18 Dec 2016 14:00:10 +0100 Subject: [PATCH] BUG-7051: move isModuleIdentifierWithoutSpecifiedRevision UtilsisModuleIdentifierWithoutSpecifiedRevision() is used only in NamespaceStorageSupport, move it to remove cross-package dependency. Change-Id: I7e6dbdc5f73f08289851f04e3092e63f0d40fa5a Signed-off-by: Robert Varga --- .../stmt/reactor/NamespaceStorageSupport.java | 35 +++++++++++++------ .../yang/parser/stmt/rfc6020/Utils.java | 6 ---- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/NamespaceStorageSupport.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/NamespaceStorageSupport.java index 4c36df3706..3111b55396 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/NamespaceStorageSupport.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/NamespaceStorageSupport.java @@ -8,11 +8,13 @@ package org.opendaylight.yangtools.yang.parser.stmt.reactor; import com.google.common.collect.ImmutableMap; +import java.util.Date; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; import java.util.Set; import javax.annotation.Nonnull; +import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil; import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier; import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace; import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour; @@ -20,7 +22,6 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.Namesp import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceNotAvailableException; import org.opendaylight.yangtools.yang.parser.spi.meta.StatementNamespace; import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext; -import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils; abstract class NamespaceStorageSupport implements NamespaceStorageNode { @@ -35,13 +36,14 @@ abstract class NamespaceStorageSupport implements NamespaceStorageNode { // NOOP } - protected > void onNamespaceElementAdded(final Class type, final K key, final V value) { + protected > void onNamespaceElementAdded(final Class type, final K key, + final V value) { // NOOP } @Nonnull - public final > V getFromNamespace(final Class type, final KT key) - throws NamespaceNotAvailableException { + public final > V getFromNamespace(final Class type, + final KT key) throws NamespaceNotAvailableException { return getBehaviourRegistry().getNamespaceBehaviour(type).getFrom(this,key); } @@ -50,18 +52,19 @@ abstract class NamespaceStorageSupport implements NamespaceStorageNode { } @SuppressWarnings("unchecked") - public final > Map getAllFromCurrentStmtCtxNamespace(final Class type){ + public final > Map getAllFromCurrentStmtCtxNamespace( + final Class type) { return (Map) namespaces.get(type); } - public final > void addToNs(final Class type, final KT key, final VT value) - throws NamespaceNotAvailableException { + public final > void addToNs(final Class type, + final KT key, final VT value) throws NamespaceNotAvailableException { getBehaviourRegistry().getNamespaceBehaviour(type).addTo(this,key,value); } @SuppressWarnings({ "unchecked", "rawtypes" }) - public final > void addContextToNamespace(final Class type, final K key, final StmtContext value) - throws NamespaceNotAvailableException { + public final > void addContextToNamespace(final Class type, final K key, + final StmtContext value) throws NamespaceNotAvailableException { getBehaviourRegistry().getNamespaceBehaviour((Class)type).addTo(this, key, value); } @@ -75,13 +78,22 @@ abstract class NamespaceStorageSupport implements NamespaceStorageNode { potential = localNamespace.get(key); } - if (potential == null && Utils.isModuleIdentifierWithoutSpecifiedRevision(key)) { + if (potential == null && isModuleIdentifierWithoutSpecifiedRevision(key)) { potential = getRegardlessOfRevision((ModuleIdentifier)key,(Map)localNamespace); } return potential; } + private static boolean isModuleIdentifierWithoutSpecifiedRevision(final Object obj) { + if (!(obj instanceof ModuleIdentifier)) { + return false; + } + + final Date rev = ((ModuleIdentifier) obj).getRevision(); + return rev == SimpleDateFormatUtil.DEFAULT_DATE_IMP || rev == SimpleDateFormatUtil.DEFAULT_BELONGS_TO_DATE; + } + private static > V getRegardlessOfRevision(final ModuleIdentifier key, final Map localNamespace) { @@ -108,7 +120,8 @@ abstract class NamespaceStorageSupport implements NamespaceStorageNode { } @Override - public > void addToLocalStorage(final Class type, final K key, final V value) { + public > void addToLocalStorage(final Class type, final K key, + final V value) { @SuppressWarnings("unchecked") Map localNamespace = (Map) namespaces.get(type); if (localNamespace == null) { diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/Utils.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/Utils.java index 86ffd0ae09..e591361b45 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/Utils.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/Utils.java @@ -569,12 +569,6 @@ public final class Utils { return revision; } - public static boolean isModuleIdentifierWithoutSpecifiedRevision(final Object o) { - return (o instanceof ModuleIdentifier) - && (((ModuleIdentifier) o).getRevision() == SimpleDateFormatUtil.DEFAULT_DATE_IMP || ((ModuleIdentifier) o) - .getRevision() == SimpleDateFormatUtil.DEFAULT_BELONGS_TO_DATE); - } - /** * Replaces illegal characters of QName by the name of the character (e.g. * '?' is replaced by "QuestionMark" etc.). -- 2.36.6