Eliminate ModuleIdentifier 26/65026/5
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 2 Nov 2017 08:46:17 +0000 (09:46 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 3 Nov 2017 15:46:02 +0000 (16:46 +0100)
It has been superseded by SourceIdentifier and its concrete subclasses.

Change-Id: I88ae6bd8fae103198ad3caa7957de32f9bbed8e5
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/ModuleIdentifier.java [deleted file]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/FilteringSchemaContextProxy.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/ModuleIdentifierImpl.java [deleted file]
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/SchemaContextUtil.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/SubmoduleStatementImpl.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug6961Test.java

diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/ModuleIdentifier.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/ModuleIdentifier.java
deleted file mode 100644 (file)
index e31e1df..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (c) 2013 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.model.api;
-
-import java.util.Optional;
-import org.opendaylight.yangtools.yang.common.Revision;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-
-/**
- * Module identifier. This "identifier" is deprecated and is to be removed in 2.0.0.
- * @author Robert Varga
- *
- * @deprecated Use {@link SourceIdentifier} instead.
- */
-@Deprecated
-public interface ModuleIdentifier {
-    /**
-     * Returns the name of the module which is specified as argument of YANG
-     * {@link Module <b><font color="#FF0000">module</font></b>} keyword.
-     *
-     * @return string with the name of the module
-     */
-    String getName();
-
-    /**
-     * Returns the revision date for the module.
-     *
-     * @return date of the module revision which is specified as argument of
-     *         YANG {@link Module <b><font color="#339900">revison</font></b>}
-     *         keyword
-     */
-    Optional<Revision> getRevision();
-}
index f51462b354d8273af0c1fe4794daae6932fb81d4..3e3a0f22c57eb2655d41077bc31073da0ca7b4d6 100644 (file)
@@ -11,7 +11,6 @@ package org.opendaylight.yangtools.yang.model.util;
 import com.google.common.base.Preconditions;
 import com.google.common.base.Strings;
 import com.google.common.collect.Collections2;
-import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet.Builder;
 import com.google.common.collect.ImmutableSetMultimap;
 import com.google.common.collect.Lists;
@@ -32,7 +31,6 @@ import java.util.function.Function;
 import javax.annotation.concurrent.Immutable;
 import org.opendaylight.yangtools.yang.common.Revision;
 import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
 import org.opendaylight.yangtools.yang.model.api.ModuleImport;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
@@ -65,18 +63,16 @@ public final class FilteringSchemaContextProxy extends AbstractSchemaContext {
         final SetMultimap<String, Module> nameMap = Multimaps.newSetMultimap(new TreeMap<>(),
             AbstractSchemaContext::createModuleSet);
 
-        ImmutableMap.Builder<ModuleIdentifier, String> identifiersToSourcesBuilder = ImmutableMap.builder();
-
-        //preparing map to get all modules with one name but difference in revision
+        // preparing map to get all modules with one name but difference in revision
         final TreeMultimap<String, Module> nameToModulesAll = getStringModuleTreeMultimap();
 
         nameToModulesAll.putAll(getStringModuleMap(delegate));
 
-        //in case there is a particular dependancy to view filteredModules/yang models
-        //dependancy is checked for module name and imports
+        // in case there is a particular dependancy to view filteredModules/yang models dependancy is checked
+        // for module name and imports
         processForRootModules(delegate, rootModules, filteredModulesBuilder);
 
-        //adding additional modules
+        // adding additional modules
         processForAdditionalModules(delegate, additionalModuleIds, filteredModulesBuilder);
 
         filteredModulesBuilder.addAll(getImportedModules(
diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/ModuleIdentifierImpl.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/ModuleIdentifierImpl.java
deleted file mode 100644 (file)
index 1f8b375..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Copyright (c) 2013 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.model.util;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import com.google.common.annotations.Beta;
-import java.util.Optional;
-import org.opendaylight.yangtools.yang.common.Revision;
-import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
-
-/**
- * ModuleIdentifier that can be used for indexing/searching by name.
- * Name is only non-null attribute.
- * Equality check on namespace and revision is only triggered if they are non-null
- *
- * @deprecated This class will be removed with {@link ModuleIdentifier}
- */
-@Deprecated
-@Beta
-public final class ModuleIdentifierImpl implements ModuleIdentifier {
-    private final Revision revision;
-    private final String name;
-
-    private ModuleIdentifierImpl(final String name, final Optional<Revision> revision) {
-        this.name = checkNotNull(name);
-        this.revision = revision.orElse(null);
-    }
-
-    public static ModuleIdentifier create(final String name, final Optional<Revision> revision) {
-        return new ModuleIdentifierImpl(name, revision);
-    }
-
-    @Override
-    public Optional<Revision> getRevision() {
-        return Optional.ofNullable(revision);
-    }
-
-    @Override
-    public String getName() {
-        return name;
-    }
-
-    @Override
-    public String toString() {
-        return "ModuleIdentifierImpl{"
-            + "name='" + name + '\''
-            + ", revision=" + revision
-            + '}';
-    }
-
-    @Override
-    public boolean equals(final Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (!(obj instanceof ModuleIdentifier)) {
-            return false;
-        }
-
-        ModuleIdentifier other = (ModuleIdentifier) obj;
-
-        if (!name.equals(other.getName())) {
-            return false;
-        }
-
-        // only fail if this revision is non-null
-        if (getRevision() != null && !getRevision().equals(other.getRevision())) {
-            return false;
-        }
-
-        return true;
-    }
-
-    @Override
-    public int hashCode() {
-        return name.hashCode();
-    }
-}
index 06ae0d090faf05c41b0a53e9deb303af5bdfd622..628a1c8be42633b3dae02c4dc587cde4b6e71e8c 100644 (file)
@@ -32,7 +32,6 @@ import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
 import org.opendaylight.yangtools.yang.model.api.ModuleImport;
 import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
 import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
@@ -43,6 +42,8 @@ import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.TypedSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
+import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
+import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -290,8 +291,8 @@ public final class SchemaContextUtil {
      * @param context SchemaContext to be examined
      * @return Set of ModuleIdentifiers.
      */
-    public static Set<ModuleIdentifier> getConstituentModuleIdentifiers(final SchemaContext context) {
-        final Set<ModuleIdentifier> ret = new HashSet<>();
+    public static Set<SourceIdentifier> getConstituentModuleIdentifiers(final SchemaContext context) {
+        final Set<SourceIdentifier> ret = new HashSet<>();
 
         for (Module module : context.getModules()) {
             ret.add(moduleToIdentifier(module));
@@ -304,8 +305,8 @@ public final class SchemaContextUtil {
         return ret;
     }
 
-    private static ModuleIdentifier moduleToIdentifier(final Module module) {
-        return ModuleIdentifierImpl.create(module.getName(), module.getRevision());
+    private static SourceIdentifier moduleToIdentifier(final Module module) {
+        return RevisionSourceIdentifier.create(module.getName(), module.getRevision());
     }
 
     private static SchemaNode findNodeInModule(final Module module, final Iterable<QName> path) {
index 866eb99e13dc1f64ce34b1913b9aa21e3e6676b9..0e1f1ae43a7f4eec91c048a1ef7a0fcb52e7eb7c 100644 (file)
@@ -10,10 +10,7 @@ package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
 import static org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils.findFirstDeclaredSubstatement;
 import static org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils.firstAttributeOf;
 
-import java.util.Optional;
 import javax.annotation.Nonnull;
-import org.opendaylight.yangtools.yang.common.Revision;
-import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.BelongsToStatement;
@@ -22,7 +19,6 @@ import org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.YangVersionStatement;
 import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.model.util.ModuleIdentifierImpl;
 import org.opendaylight.yangtools.yang.parser.spi.SubmoduleNamespace;
 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
@@ -124,12 +120,6 @@ public class SubmoduleStatementImpl extends AbstractRootStatement<SubmoduleState
             stmt.addToNs(BelongsToPrefixToModuleName.class, prefix, belongsToModuleName);
         }
 
-        private static ModuleIdentifier getSubmoduleIdentifier(
-                final Mutable<String, SubmoduleStatement, EffectiveStatement<String, SubmoduleStatement>> stmt) {
-            final Optional<Revision> maybeDate = StmtContextUtils.getLatestRevision(stmt.declaredSubstatements());
-            return ModuleIdentifierImpl.create(stmt.getStatementArgument(), maybeDate);
-        }
-
         @Override
         protected SubstatementValidator getSubstatementValidator() {
             return SUBSTATEMENT_VALIDATOR;
index 15b6829219003f0c667588b8431f13741289396c..779711da765ebc1eb9abf11e8a4440462941f8d3 100644 (file)
@@ -16,9 +16,9 @@ import java.util.Optional;
 import java.util.Set;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.Revision;
-import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.util.ModuleIdentifierImpl;
+import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
+import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
 import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
 import org.opendaylight.yangtools.yang.model.util.SimpleSchemaContext;
 
@@ -27,21 +27,21 @@ public class Bug6961Test {
     @Test
     public void testBug6961SchemaContext() throws Exception {
         final Optional<Revision> revision = Revision.ofNullable("2016-01-01");
-        final ModuleIdentifier foo = ModuleIdentifierImpl.create("foo", revision);
-        final ModuleIdentifier sub1Foo = ModuleIdentifierImpl.create("sub1-foo", revision);
-        final ModuleIdentifier sub2Foo = ModuleIdentifierImpl.create("sub2-foo", revision);
-        final ModuleIdentifier bar = ModuleIdentifierImpl.create("bar", revision);
-        final ModuleIdentifier sub1Bar = ModuleIdentifierImpl.create("sub1-bar", revision);
-        final ModuleIdentifier baz = ModuleIdentifierImpl.create("baz", revision);
-        final Set<ModuleIdentifier> testSet = ImmutableSet.of(foo, sub1Foo, sub2Foo, bar, sub1Bar, baz);
+        final SourceIdentifier foo = RevisionSourceIdentifier.create("foo", revision);
+        final SourceIdentifier sub1Foo = RevisionSourceIdentifier.create("sub1-foo", revision);
+        final SourceIdentifier sub2Foo = RevisionSourceIdentifier.create("sub2-foo", revision);
+        final SourceIdentifier bar = RevisionSourceIdentifier.create("bar", revision);
+        final SourceIdentifier sub1Bar = RevisionSourceIdentifier.create("sub1-bar", revision);
+        final SourceIdentifier baz = RevisionSourceIdentifier.create("baz", revision);
+        final Set<SourceIdentifier> testSet = ImmutableSet.of(foo, sub1Foo, sub2Foo, bar, sub1Bar, baz);
         final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6961/");
         assertNotNull(context);
-        final Set<ModuleIdentifier> allModuleIdentifiers = SchemaContextUtil.getConstituentModuleIdentifiers(context);
+        final Set<SourceIdentifier> allModuleIdentifiers = SchemaContextUtil.getConstituentModuleIdentifiers(context);
         assertNotNull(allModuleIdentifiers);
         assertEquals(6, allModuleIdentifiers.size());
         final SchemaContext schemaContext = SimpleSchemaContext.forModules(context.getModules());
         assertNotNull(schemaContext);
-        final Set<ModuleIdentifier> allModuleIdentifiersResolved = SchemaContextUtil.getConstituentModuleIdentifiers(
+        final Set<SourceIdentifier> allModuleIdentifiersResolved = SchemaContextUtil.getConstituentModuleIdentifiers(
             schemaContext);
         assertNotNull(allModuleIdentifiersResolved);
         assertEquals(6, allModuleIdentifiersResolved.size());