From ce411dfc8c67f7595f11ac6472019f9c3f30a9f8 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Wed, 22 Jan 2020 17:14:26 +0100 Subject: [PATCH] AbstractEffectiveModule should retain statement order 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 --- .../yangtools/rfc6241/parser/NetconfTest.java | 12 ++++++++++-- .../rfc7950/stmt/AbstractEffectiveModule.java | 17 ++++++++--------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/yang/rfc6241-parser-support/src/test/java/org/opendaylight/yangtools/rfc6241/parser/NetconfTest.java b/yang/rfc6241-parser-support/src/test/java/org/opendaylight/yangtools/rfc6241/parser/NetconfTest.java index dfc633849f..597fea56d8 100644 --- a/yang/rfc6241-parser-support/src/test/java/org/opendaylight/yangtools/rfc6241/parser/NetconfTest.java +++ b/yang/rfc6241-parser-support/src/test/java/org/opendaylight/yangtools/rfc6241/parser/NetconfTest.java @@ -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 it = module.getRpcs().iterator(); + final Collection rpcs = module.getRpcs(); + assertEquals(13, rpcs.size()); + final Iterator 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)); } diff --git a/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/AbstractEffectiveModule.java b/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/AbstractEffectiveModule.java index 055188be4e..f12301403e 100644 --- a/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/AbstractEffectiveModule.java +++ b/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/AbstractEffectiveModule.java @@ -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 augmentationsInit = new LinkedHashSet<>(); - final Set importsInit = new HashSet<>(); - final Set notificationsInit = new HashSet<>(); - final Set rpcsInit = new HashSet<>(); - final Set deviationsInit = new HashSet<>(); - final Set identitiesInit = new HashSet<>(); - final Set featuresInit = new HashSet<>(); + final Set importsInit = new LinkedHashSet<>(); + final Set notificationsInit = new LinkedHashSet<>(); + final Set rpcsInit = new LinkedHashSet<>(); + final Set deviationsInit = new LinkedHashSet<>(); + final Set identitiesInit = new LinkedHashSet<>(); + final Set featuresInit = new LinkedHashSet<>(); final List extensionNodesInit = new ArrayList<>(); - final Set mutableGroupings = new HashSet<>(); - final Set mutableUses = new HashSet<>(); + final Set mutableGroupings = new LinkedHashSet<>(); + final Set mutableUses = new LinkedHashSet<>(); final Set> mutableTypeDefinitions = new LinkedHashSet<>(); final Set mutablePublicChildNodes = new LinkedHashSet<>(); -- 2.36.6