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.Optional;
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;
import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.NamespaceStorageNode;
+import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.Registry;
+import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceKeyCriterion;
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.spi.source.SourceException;
abstract class NamespaceStorageSupport implements NamespaceStorageNode {
public abstract NamespaceStorageNode getParentNamespaceStorage();
/**
+ * Return the registry of a source context.
+ *
* @return registry of source context
*/
- public abstract NamespaceBehaviour.Registry getBehaviourRegistry();
+ public abstract Registry getBehaviourRegistry();
protected void checkLocalNamespaceAllowed(final Class<? extends IdentifierNamespace<?, ?>> type) {
// NOOP
}
+ /**
+ * Occurs when an item is added to model namespace.
+ *
+ * @throws SourceException instance of SourceException
+ */
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,
+ 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);
+ return getBehaviourRegistry().getNamespaceBehaviour(type).getFrom(this, key);
+ }
+
+ public final <K, V, N extends IdentifierNamespace<K, V>> Optional<Entry<K, V>> getFromNamespace(
+ final Class<N> type, final NamespaceKeyCriterion<K> criterion) {
+ return getBehaviourRegistry().getNamespaceBehaviour(type).getFrom(this, criterion);
}
- public final <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromNamespace(final Class<N> type){
+ public final <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromNamespace(final Class<N> type) {
return getBehaviourRegistry().getNamespaceBehaviour(type).getAllFrom(this);
}
@SuppressWarnings("unchecked")
@Override
public <K, V, N extends IdentifierNamespace<K, V>> V getFromLocalStorage(final Class<N> type, final K key) {
- final Map<K, V> localNamespace = (Map<K,V>) namespaces.get(type);
+ final Map<K, V> localNamespace = (Map<K, V>) namespaces.get(type);
V potential = null;
if (localNamespace != null) {
}
if (potential == null && isModuleIdentifierWithoutSpecifiedRevision(key)) {
- potential = getRegardlessOfRevision((ModuleIdentifier)key,(Map<ModuleIdentifier,V>)localNamespace);
+ 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;
+ return obj instanceof ModuleIdentifier
+ && ((ModuleIdentifier) obj).getRevision() == SimpleDateFormatUtil.DEFAULT_DATE_IMP;
}
private static <K, V, N extends IdentifierNamespace<K, V>> V getRegardlessOfRevision(final ModuleIdentifier key,