BUG-7051: move isModuleIdentifierWithoutSpecifiedRevision 25/49525/1
authorRobert Varga <rovarga@cisco.com>
Sun, 18 Dec 2016 13:00:10 +0000 (14:00 +0100)
committerRobert Varga <rovarga@cisco.com>
Sun, 18 Dec 2016 13:00:10 +0000 (14:00 +0100)
UtilsisModuleIdentifierWithoutSpecifiedRevision() is used only
in NamespaceStorageSupport, move it to remove cross-package
dependency.

Change-Id: I7e6dbdc5f73f08289851f04e3092e63f0d40fa5a
Signed-off-by: Robert Varga <rovarga@cisco.com>
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/NamespaceStorageSupport.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/Utils.java

index 4c36df37062c192f7b2a50d714c0e9a382458d14..3111b55396adb40a34f01fdb9866d8fc1fb6b044 100644 (file)
@@ -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 <K, V, N extends IdentifierNamespace<K, V>> void onNamespaceElementAdded(final Class<N> type, final K key, final V value) {
+    protected <K, V, N extends IdentifierNamespace<K, V>> void onNamespaceElementAdded(final Class<N> type, final K key,
+            final V value) {
         // NOOP
     }
 
     @Nonnull
-    public final <K,V, KT extends K, N extends IdentifierNamespace<K, V>> V getFromNamespace(final Class<N> type, final KT key)
-            throws NamespaceNotAvailableException {
+    public final <K,V, KT extends K, N extends IdentifierNamespace<K, V>> V getFromNamespace(final Class<N> 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 <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromCurrentStmtCtxNamespace(final Class<N> type){
+    public final <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromCurrentStmtCtxNamespace(
+            final Class<N> type) {
         return (Map<K, V>) namespaces.get(type);
     }
 
-    public final <K,V, KT extends K, VT extends V,N extends IdentifierNamespace<K, V>> void addToNs(final Class<N> type, final KT key, final VT value)
-            throws NamespaceNotAvailableException {
+    public final <K,V, KT extends K, VT extends V,N extends IdentifierNamespace<K, V>> void addToNs(final Class<N> type,
+            final KT key, final VT value) throws NamespaceNotAvailableException {
         getBehaviourRegistry().getNamespaceBehaviour(type).addTo(this,key,value);
     }
 
     @SuppressWarnings({ "unchecked", "rawtypes" })
-    public final <K, N extends StatementNamespace<K, ?,?>> void addContextToNamespace(final Class<N> type, final K key, final StmtContext<?, ?, ?> value)
-            throws NamespaceNotAvailableException {
+    public final <K, N extends StatementNamespace<K, ?,?>> void addContextToNamespace(final Class<N> 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<ModuleIdentifier,V>)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 <K, V, N extends IdentifierNamespace<K, V>> V getRegardlessOfRevision(final ModuleIdentifier key,
             final Map<ModuleIdentifier, V> localNamespace) {
 
@@ -108,7 +120,8 @@ abstract class NamespaceStorageSupport implements NamespaceStorageNode {
     }
 
     @Override
-    public <K, V, N extends IdentifierNamespace<K, V>> void addToLocalStorage(final Class<N> type, final K key, final V value) {
+    public <K, V, N extends IdentifierNamespace<K, V>> void addToLocalStorage(final Class<N> type, final K key,
+            final V value) {
         @SuppressWarnings("unchecked")
         Map<K, V> localNamespace = (Map<K,V>) namespaces.get(type);
         if (localNamespace == null) {
index 86ffd0ae09fd5ac0cbb20d9579745acb37632a09..e591361b45858be106d0dd7b713e03c91d6c6eb1 100644 (file)
@@ -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.).