Event Source: switch from wildcards to regexs 79/18279/1
authorRobert Varga <rovarga@cisco.com>
Tue, 14 Apr 2015 16:50:49 +0000 (18:50 +0200)
committerRobert Varga <rovarga@cisco.com>
Tue, 14 Apr 2015 16:50:49 +0000 (18:50 +0200)
The node match specifier is more useful (and natural) in a regular
expression. Switch the implementation to interpret the argument as a
pattern.

Change-Id: Iac9034095cee35dfc020747a5448ef486a6a63df
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/md-sal/messagebus-impl/src/main/java/org/opendaylight/controller/messagebus/app/impl/EventSourceTopic.java
opendaylight/md-sal/messagebus-impl/src/main/java/org/opendaylight/controller/messagebus/app/impl/EventSourceTopology.java
opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/app/impl/UtilTest.java

index 13e50b5ce57030b9a1a97864c02b2fe1613c33bd..c60562d3d4392dca7f5e1e3ca40da4e8bbe9961b 100644 (file)
@@ -39,10 +39,7 @@ public class EventSourceTopic implements DataChangeListener {
     public EventSourceTopic(final NotificationPattern notificationPattern, final String nodeIdPattern, final EventSourceService eventSource) {
         this.notificationPattern = Preconditions.checkNotNull(notificationPattern);
         this.sourceService = eventSource;
-
-        // FIXME: regex should be the language of nodeIdPattern
-        final String regex = Util.wildcardToRegex(nodeIdPattern);
-        this.nodeIdPattern = Pattern.compile(regex);
+        this.nodeIdPattern = Pattern.compile(nodeIdPattern);
 
         this.topicId = new TopicId(Util.getUUIDIdent());
     }
index 10b9ec83cde9080a5eb652ea69b65936973b0f60..b879eacda015b5d810ce535234dcbf1396f8d78c 100644 (file)
@@ -168,7 +168,7 @@ public class EventSourceTopology implements EventAggregatorService, EventSourceR
 
         final NotificationPattern notificationPattern = new NotificationPattern(input.getNotificationPattern());
         final String nodeIdPattern = input.getNodeIdPattern().getValue();
-        final Pattern nodeIdPatternRegex = Pattern.compile(Util.wildcardToRegex(nodeIdPattern));
+        final Pattern nodeIdPatternRegex = Pattern.compile(nodeIdPattern);
         final EventSourceTopic eventSourceTopic = new EventSourceTopic(notificationPattern, nodeIdPattern, eventSourceService);
 
         registerTopic(eventSourceTopic);
index a88c609a263317deb9ed4906893150f52390a219..7aebb8fbdd6ac14919c9b1c8d6d5ec8327559f5c 100644 (file)
@@ -25,30 +25,6 @@ import org.opendaylight.yangtools.yang.model.api.SchemaPath;
  */
 public class UtilTest {
 
-    @Test
-    public void testWildcardToRegex() throws Exception {
-        // empty wildcard string
-        createAndAssertRegex("", "^$");
-
-        // wildcard string is a char to be replaced
-        createAndAssertRegex("*", "^.*$");
-        createAndAssertRegex("?", "^.$");
-        final String relevantChars = "()[]$^.{}|\\";
-        for (final char c : relevantChars.toCharArray()) {
-            final char oneChar[] = {c};
-            final String wildcardStr = new String(oneChar);
-            final String expectedRegex = "^\\" + c + "$";
-            createAndAssertRegex(wildcardStr, expectedRegex);
-        }
-
-        // wildcard string consists of more chars
-        createAndAssertRegex("a", "^a$");
-        createAndAssertRegex("aBc", "^aBc$");
-        createAndAssertRegex("a1b2C34", "^a1b2C34$");
-        createAndAssertRegex("*?()[]$^.{}|\\X", "^.*.\\(\\)\\[\\]\\$\\^\\.\\{\\}\\|\\\\X$");
-        createAndAssertRegex("a*BB?37|42$", "^a.*BB.37\\|42\\$$");
-    }
-
     @Test
     public void testResultFor() throws Exception {
         {
@@ -105,10 +81,6 @@ public class UtilTest {
         }
     }
 
-    private static void createAndAssertRegex(final String wildcardStr, final String expectedRegex) {
-        assertEquals("Incorrect regex string.", expectedRegex, Util.wildcardToRegex(wildcardStr));
-    }
-
     private static List<SchemaPath> createSchemaPathList() {
         final QName qname1 = QName.create("urn:odl:xxx", "2015-01-01", "localName");
         final QName qname2 = QName.create("urn:odl:yyy", "2015-01-01", "localName");