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());
}
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);
*/
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 {
{
}
}
- 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");