BUG-1281: share filters between instances 03/9403/4
authorRobert Varga <rovarga@cisco.com>
Mon, 28 Jul 2014 19:53:51 +0000 (21:53 +0200)
committerRobert Varga <rovarga@cisco.com>
Sun, 3 Aug 2014 13:23:49 +0000 (15:23 +0200)
The filters are invariants, so lets share them accross instances and not
instantiate them each time we need them.

Change-Id: Ib632efe758c22bd782fca0536c2fe7e9c6e831c3
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.java

index ce73132269001e01b8336e415b25cd6e22250268..91e24541994487089be96a7ce3586d09320c4a32 100644 (file)
@@ -366,6 +366,13 @@ public class ControllerContext implements SchemaContextListener {
         return findModuleByNameAndRevision(Draft02.RestConfModule.IETF_RESTCONF_QNAME);
     }
 
         return findModuleByNameAndRevision(Draft02.RestConfModule.IETF_RESTCONF_QNAME);
     }
 
+    private static final Predicate<GroupingDefinition> ERRORS_GROUPING_FILTER = new Predicate<GroupingDefinition>() {
+        @Override
+        public boolean apply(final GroupingDefinition g) {
+            return Draft02.RestConfModule.ERRORS_GROUPING_SCHEMA_NODE.equals(g.getQName().getLocalName());
+        }
+    };
+
     public DataSchemaNode getRestconfModuleErrorsSchemaNode() {
         Module restconfModule = getRestconfModule();
         if (restconfModule == null) {
     public DataSchemaNode getRestconfModuleErrorsSchemaNode() {
         Module restconfModule = getRestconfModule();
         if (restconfModule == null) {
@@ -374,14 +381,7 @@ public class ControllerContext implements SchemaContextListener {
 
         Set<GroupingDefinition> groupings = restconfModule.getGroupings();
 
 
         Set<GroupingDefinition> groupings = restconfModule.getGroupings();
 
-        final Predicate<GroupingDefinition> filter = new Predicate<GroupingDefinition>() {
-            @Override
-            public boolean apply(final GroupingDefinition g) {
-                return Objects.equal(g.getQName().getLocalName(), Draft02.RestConfModule.ERRORS_GROUPING_SCHEMA_NODE);
-            }
-        };
-
-        Iterable<GroupingDefinition> filteredGroups = Iterables.filter(groupings, filter);
+        Iterable<GroupingDefinition> filteredGroups = Iterables.filter(groupings, ERRORS_GROUPING_FILTER);
 
         final GroupingDefinition restconfGrouping = Iterables.getFirst(filteredGroups, null);
 
 
         final GroupingDefinition restconfGrouping = Iterables.getFirst(filteredGroups, null);
 
@@ -390,6 +390,13 @@ public class ControllerContext implements SchemaContextListener {
         return Iterables.getFirst(instanceDataChildrenByName, null);
     }
 
         return Iterables.getFirst(instanceDataChildrenByName, null);
     }
 
+    private static final Predicate<GroupingDefinition> GROUPING_FILTER = new Predicate<GroupingDefinition>() {
+        @Override
+        public boolean apply(final GroupingDefinition g) {
+            return Draft02.RestConfModule.RESTCONF_GROUPING_SCHEMA_NODE.equals(g.getQName().getLocalName());
+        }
+    };
+
     public DataSchemaNode getRestconfModuleRestConfSchemaNode(final Module inRestconfModule, final String schemaNodeName) {
         Module restconfModule = inRestconfModule;
         if (restconfModule == null) {
     public DataSchemaNode getRestconfModuleRestConfSchemaNode(final Module inRestconfModule, final String schemaNodeName) {
         Module restconfModule = inRestconfModule;
         if (restconfModule == null) {
@@ -401,16 +408,7 @@ public class ControllerContext implements SchemaContextListener {
         }
 
         Set<GroupingDefinition> groupings = restconfModule.getGroupings();
         }
 
         Set<GroupingDefinition> groupings = restconfModule.getGroupings();
-
-        final Predicate<GroupingDefinition> filter = new Predicate<GroupingDefinition>() {
-            @Override
-            public boolean apply(final GroupingDefinition g) {
-                return Objects.equal(g.getQName().getLocalName(), Draft02.RestConfModule.RESTCONF_GROUPING_SCHEMA_NODE);
-            }
-        };
-
-        Iterable<GroupingDefinition> filteredGroups = Iterables.filter(groupings, filter);
-
+        Iterable<GroupingDefinition> filteredGroups = Iterables.filter(groupings, GROUPING_FILTER);
         final GroupingDefinition restconfGrouping = Iterables.getFirst(filteredGroups, null);
 
         List<DataSchemaNode> instanceDataChildrenByName = this.findInstanceDataChildrenByName(restconfGrouping,
         final GroupingDefinition restconfGrouping = Iterables.getFirst(filteredGroups, null);
 
         List<DataSchemaNode> instanceDataChildrenByName = this.findInstanceDataChildrenByName(restconfGrouping,
@@ -701,6 +699,13 @@ public class ControllerContext implements SchemaContextListener {
         return instantiatedDataNodeContainers;
     }
 
         return instantiatedDataNodeContainers;
     }
 
+    private static final Function<ChoiceNode, Set<ChoiceCaseNode>> CHOICE_FUNCTION = new Function<ChoiceNode, Set<ChoiceCaseNode>>() {
+        @Override
+        public Set<ChoiceCaseNode> apply(final ChoiceNode node) {
+            return node.getCases();
+        }
+    };
+
     private void collectInstanceDataNodeContainers(final List<DataSchemaNode> potentialSchemaNodes,
             final DataNodeContainer container, final String name) {
 
     private void collectInstanceDataNodeContainers(final List<DataSchemaNode> potentialSchemaNodes,
             final DataNodeContainer container, final String name) {
 
@@ -721,17 +726,8 @@ public class ControllerContext implements SchemaContextListener {
             }
         }
 
             }
         }
 
-        Iterable<ChoiceNode> choiceNodes = Iterables.<ChoiceNode> filter(container.getChildNodes(), ChoiceNode.class);
-
-        final Function<ChoiceNode, Set<ChoiceCaseNode>> choiceFunction = new Function<ChoiceNode, Set<ChoiceCaseNode>>() {
-            @Override
-            public Set<ChoiceCaseNode> apply(final ChoiceNode node) {
-                return node.getCases();
-            }
-        };
-
-        Iterable<Set<ChoiceCaseNode>> map = Iterables.<ChoiceNode, Set<ChoiceCaseNode>> transform(choiceNodes,
-                choiceFunction);
+        Iterable<ChoiceNode> choiceNodes = Iterables.filter(container.getChildNodes(), ChoiceNode.class);
+        Iterable<Set<ChoiceCaseNode>> map = Iterables.transform(choiceNodes, CHOICE_FUNCTION);
 
         final Iterable<ChoiceCaseNode> allCases = Iterables.<ChoiceCaseNode> concat(map);
         for (final ChoiceCaseNode caze : allCases) {
 
         final Iterable<ChoiceCaseNode> allCases = Iterables.<ChoiceCaseNode> concat(map);
         for (final ChoiceCaseNode caze : allCases) {