AbstractEffectiveModule should retain statement order 89/87089/1
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 22 Jan 2020 16:14:26 +0000 (17:14 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 23 Jan 2020 05:55:27 +0000 (06:55 +0100)
AbstractEffectiveModule is using HashSet for its temporary storage,
which makes statement order dependent on hashCode() rather than
declaration order.

Make sure we use LinkedHashSet, thus not losing the order.

Change-Id: Ie46c28c051f861c1aabc34f7aa5e4293f7d38cea
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/rfc6241-parser-support/src/test/java/org/opendaylight/yangtools/rfc6241/parser/NetconfTest.java
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/AbstractEffectiveModule.java

index dfc633849f25346075506c144723fdb0e9d4f5df..597fea56d81dc8b30b0b841843a8b5ccfd89a1fd 100644 (file)
@@ -14,6 +14,7 @@ import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 
 import java.io.IOException;
+import java.util.Collection;
 import java.util.Iterator;
 import java.util.Optional;
 import org.junit.AfterClass;
@@ -63,10 +64,17 @@ public class NetconfTest {
                 .buildEffective();
 
         final Module module = context.findModule(NetconfConstants.RFC6241_MODULE).get();
-        final Iterator<RpcDefinition> it = module.getRpcs().iterator();
+        final Collection<? extends RpcDefinition> rpcs = module.getRpcs();
+        assertEquals(13, rpcs.size());
+        final Iterator<? extends RpcDefinition> it = module.getRpcs().iterator();
+        // get-config
+        assertExtension(true, it.next());
         assertExtension(false, it.next());
         assertExtension(false, it.next());
-        assertExtension(true, it.next());
+        assertExtension(false, it.next());
+        assertExtension(false, it.next());
+        assertExtension(false, it.next());
+        // get
         assertExtension(true, it.next());
         it.forEachRemaining(def -> assertExtension(false, def));
     }
index 055188be4e45d478916d8e92689f99619d2fc2f8..f12301403e8b8eb6c52451106093b4ef79e1905b 100644 (file)
@@ -15,7 +15,6 @@ import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
 import java.net.URI;
 import java.util.ArrayList;
-import java.util.HashSet;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Optional;
@@ -91,16 +90,16 @@ public abstract class AbstractEffectiveModule<D extends DeclaredStatement<String
                 .orElse(null);
 
         final Set<AugmentationSchemaNode> augmentationsInit = new LinkedHashSet<>();
-        final Set<ModuleImport> importsInit = new HashSet<>();
-        final Set<NotificationDefinition> notificationsInit = new HashSet<>();
-        final Set<RpcDefinition> rpcsInit = new HashSet<>();
-        final Set<Deviation> deviationsInit = new HashSet<>();
-        final Set<IdentitySchemaNode> identitiesInit = new HashSet<>();
-        final Set<FeatureDefinition> featuresInit = new HashSet<>();
+        final Set<ModuleImport> importsInit = new LinkedHashSet<>();
+        final Set<NotificationDefinition> notificationsInit = new LinkedHashSet<>();
+        final Set<RpcDefinition> rpcsInit = new LinkedHashSet<>();
+        final Set<Deviation> deviationsInit = new LinkedHashSet<>();
+        final Set<IdentitySchemaNode> identitiesInit = new LinkedHashSet<>();
+        final Set<FeatureDefinition> featuresInit = new LinkedHashSet<>();
         final List<ExtensionDefinition> extensionNodesInit = new ArrayList<>();
 
-        final Set<GroupingDefinition> mutableGroupings = new HashSet<>();
-        final Set<UsesNode> mutableUses = new HashSet<>();
+        final Set<GroupingDefinition> mutableGroupings = new LinkedHashSet<>();
+        final Set<UsesNode> mutableUses = new LinkedHashSet<>();
         final Set<TypeDefinition<?>> mutableTypeDefinitions = new LinkedHashSet<>();
         final Set<DataSchemaNode> mutablePublicChildNodes = new LinkedHashSet<>();