BUG-7052: remove AbstractEffectiveSchemaContext 42/58542/2
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 8 Jun 2017 17:16:46 +0000 (19:16 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 8 Jun 2017 23:45:09 +0000 (01:45 +0200)
This is essentially a copy of AbstractSchemaContext, so reduce
code duplication by removing it.

Change-Id: I736017a379c4796a7afed6933525b354f1f852bc
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/AbstractEffectiveSchemaContext.java [deleted file]
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/EffectiveSchemaContext.java

diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/AbstractEffectiveSchemaContext.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/AbstractEffectiveSchemaContext.java
deleted file mode 100644 (file)
index 1d6e811..0000000
+++ /dev/null
@@ -1,254 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
-
-import com.google.common.base.Optional;
-import com.google.common.base.Supplier;
-import com.google.common.collect.SetMultimap;
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.NavigableSet;
-import java.util.Set;
-import java.util.TreeSet;
-import javax.annotation.Nonnull;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
-import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition;
-import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
-import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
-import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
-import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.opendaylight.yangtools.yang.model.api.Status;
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.UsesNode;
-
-abstract class AbstractEffectiveSchemaContext implements SchemaContext {
-    protected static final Comparator<Module> REVISION_COMPARATOR = (o1, o2) -> {
-        if (o2.getRevision() == null) {
-            return -1;
-        }
-
-        return o2.getRevision().compareTo(o1.getRevision());
-    };
-
-    protected static final Supplier<NavigableSet<Module>> MODULE_SET_SUPPLIER = () -> new TreeSet<>(REVISION_COMPARATOR);
-
-    /**
-     * @return yang sources where key is ModuleIdentifier
-     */
-    protected abstract Map<ModuleIdentifier, String> getIdentifiersToSources();
-
-    /**
-     * @return Map of modules where key is namespace
-     */
-    protected abstract SetMultimap<URI, Module> getNamespaceToModules();
-
-    /**
-     * @return Map of modules where key is name of module
-     */
-    protected abstract SetMultimap<String, Module> getNameToModules();
-
-    @Override
-    public Set<DataSchemaNode> getDataDefinitions() {
-        final Set<DataSchemaNode> dataDefs = new HashSet<>();
-        for (Module m : getModules()) {
-            dataDefs.addAll(m.getChildNodes());
-        }
-        return dataDefs;
-    }
-
-    @Override
-    public Set<NotificationDefinition> getNotifications() {
-        final Set<NotificationDefinition> notifications = new HashSet<>();
-        for (Module m : getModules()) {
-            notifications.addAll(m.getNotifications());
-        }
-        return notifications;
-    }
-
-    @Override
-    public Set<RpcDefinition> getOperations() {
-        final Set<RpcDefinition> rpcs = new HashSet<>();
-        for (Module m : getModules()) {
-            rpcs.addAll(m.getRpcs());
-        }
-        return rpcs;
-    }
-
-    @Override
-    public Set<ExtensionDefinition> getExtensions() {
-        final Set<ExtensionDefinition> extensions = new HashSet<>();
-        for (Module m : getModules()) {
-            extensions.addAll(m.getExtensionSchemaNodes());
-        }
-        return extensions;
-    }
-
-    @Override
-    public Module findModuleByName(final String name, final Date revision) {
-        for (final Module module : getNameToModules().get(name)) {
-            if (revision == null || revision.equals(module.getRevision())) {
-                return module;
-            }
-        }
-
-        return null;
-    }
-
-    @Override
-    public Set<Module> findModuleByNamespace(final URI namespace) {
-        final Set<Module> ret = getNamespaceToModules().get(namespace);
-        return ret == null ? Collections.emptySet() : ret;
-    }
-
-    @Override
-    public Module findModuleByNamespaceAndRevision(final URI namespace,
-            final Date revision) {
-        if (namespace == null) {
-            return null;
-        }
-        for (Module module : findModuleByNamespace(namespace)) {
-            if (revision == null || revision.equals(module.getRevision())) {
-                return module;
-            }
-        }
-        return null;
-    }
-
-    @Override
-    public boolean isAugmenting() {
-        return false;
-    }
-
-    @Override
-    public boolean isAddedByUses() {
-        return false;
-    }
-
-    @Override
-    public boolean isConfiguration() {
-        return false;
-    }
-
-    @Override
-    public ConstraintDefinition getConstraints() {
-        return null;
-    }
-
-    @Nonnull
-    @Override
-    public QName getQName() {
-        return SchemaContext.NAME;
-    }
-
-    @Nonnull
-    @Override
-    public SchemaPath getPath() {
-        return SchemaPath.ROOT;
-    }
-
-    @Override
-    public String getDescription() {
-        return null;
-    }
-
-    @Override
-    public String getReference() {
-        return null;
-    }
-
-    @Nonnull
-    @Override
-    public Status getStatus() {
-        return Status.CURRENT;
-    }
-
-    @Nonnull
-    @Override
-    public List<UnknownSchemaNode> getUnknownSchemaNodes() {
-        final List<UnknownSchemaNode> result = new ArrayList<>();
-        for (Module module : getModules()) {
-            result.addAll(module.getUnknownSchemaNodes());
-        }
-        return Collections.unmodifiableList(result);
-    }
-
-    @Override
-    public Set<TypeDefinition<?>> getTypeDefinitions() {
-        final Set<TypeDefinition<?>> result = new LinkedHashSet<>();
-        for (Module module : getModules()) {
-            result.addAll(module.getTypeDefinitions());
-        }
-        return Collections.unmodifiableSet(result);
-    }
-
-    @Override
-    public Set<DataSchemaNode> getChildNodes() {
-        final Set<DataSchemaNode> result = new LinkedHashSet<>();
-        for (Module module : getModules()) {
-            result.addAll(module.getChildNodes());
-        }
-        return Collections.unmodifiableSet(result);
-    }
-
-    @Override
-    public Set<GroupingDefinition> getGroupings() {
-        final Set<GroupingDefinition> result = new LinkedHashSet<>();
-        for (Module module : getModules()) {
-            result.addAll(module.getGroupings());
-        }
-        return Collections.unmodifiableSet(result);
-    }
-
-    @Override
-    public DataSchemaNode getDataChildByName(final QName name) {
-        for (Module module : getModules()) {
-            final DataSchemaNode result = module.getDataChildByName(name);
-            if (result != null) {
-                return result;
-            }
-        }
-        return null;
-    }
-
-    @Override
-    public Set<UsesNode> getUses() {
-        return Collections.emptySet();
-    }
-
-    @Override
-    public boolean isPresenceContainer() {
-        return false;
-    }
-
-    @Override
-    public Set<AugmentationSchema> getAvailableAugmentations() {
-        return Collections.emptySet();
-    }
-
-    @Override
-    public Optional<String> getModuleSource(
-            final ModuleIdentifier moduleIdentifier) {
-        String maybeSource = getIdentifiersToSources().get(moduleIdentifier);
-        return Optional.fromNullable(maybeSource);
-    }
-
-}
index bf8463df0c4615ede2948b957c1b5631e228ca5b..d4246099a240b0eb9d61698f53b61c8f2224a4e8 100644 (file)
@@ -25,10 +25,11 @@ import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.util.AbstractSchemaContext;
 import org.opendaylight.yangtools.yang.model.util.ModuleIdentifierImpl;
 import org.opendaylight.yangtools.yang.parser.util.ModuleDependencySort;
 
-public final class EffectiveSchemaContext extends AbstractEffectiveSchemaContext {
+public final class EffectiveSchemaContext extends AbstractSchemaContext {
 
     private final SetMultimap<URI, Module> namespaceToModules;
     private final SetMultimap<String, Module> nameToModules;