@Test public void metadataCanBeUpdated() throws ScriptException { MqttTopicFilter filter = MqttTopicFilterFactory.toFilter("Sensor/Temperature/House/+"); assertTrue(filter.filter(TEST_STR_1)); assertFalse(filter.filter(TEST_STR_2)); filter = MqttTopicFilterFactory.toFilter("Sensor/+/House/#"); assertTrue(filter.filter(TEST_STR_1)); assertFalse(filter.filter(TEST_STR_2)); filter = MqttTopicFilterFactory.toFilter("Sensor/#"); assertTrue(filter.filter(TEST_STR_1)); assertTrue(filter.filter(TEST_STR_2)); assertTrue(filter.filter(TEST_STR_3)); filter = MqttTopicFilterFactory.toFilter("Sensor/Temperature/#"); assertTrue(filter.filter(TEST_STR_1)); assertTrue(filter.filter(TEST_STR_2)); assertFalse(filter.filter(TEST_STR_3)); }
public static MqttTopicFilter toFilter(String topicFilter) { if (topicFilter == null || topicFilter.isEmpty()) { throw new IllegalArgumentException("Topic filter can't be empty!"); } return filters.computeIfAbsent(topicFilter, filter -> { if (filter.contains("+") || filter.contains("#")) { String regex = filter .replace("\\", "\\\\") .replace("+", "[^/]+") .replace("/#", "($|/.*)"); log.debug("Converting [{}] to [{}]", filter, regex); return new RegexTopicFilter(regex); } else { return new EqualsTopicFilter(filter); } }); }
MqttTopicFilterFactory { public static MqttTopicFilter toFilter(String topicFilter) { if (topicFilter == null || topicFilter.isEmpty()) { throw new IllegalArgumentException("Topic filter can't be empty!"); } return filters.computeIfAbsent(topicFilter, filter -> { if (filter.contains("+") || filter.contains("#")) { String regex = filter .replace("\\", "\\\\") .replace("+", "[^/]+") .replace("/#", "($|/.*)"); log.debug("Converting [{}] to [{}]", filter, regex); return new RegexTopicFilter(regex); } else { return new EqualsTopicFilter(filter); } }); } }
MqttTopicFilterFactory { public static MqttTopicFilter toFilter(String topicFilter) { if (topicFilter == null || topicFilter.isEmpty()) { throw new IllegalArgumentException("Topic filter can't be empty!"); } return filters.computeIfAbsent(topicFilter, filter -> { if (filter.contains("+") || filter.contains("#")) { String regex = filter .replace("\\", "\\\\") .replace("+", "[^/]+") .replace("/#", "($|/.*)"); log.debug("Converting [{}] to [{}]", filter, regex); return new RegexTopicFilter(regex); } else { return new EqualsTopicFilter(filter); } }); }  }
MqttTopicFilterFactory { public static MqttTopicFilter toFilter(String topicFilter) { if (topicFilter == null || topicFilter.isEmpty()) { throw new IllegalArgumentException("Topic filter can't be empty!"); } return filters.computeIfAbsent(topicFilter, filter -> { if (filter.contains("+") || filter.contains("#")) { String regex = filter .replace("\\", "\\\\") .replace("+", "[^/]+") .replace("/#", "($|/.*)"); log.debug("Converting [{}] to [{}]", filter, regex); return new RegexTopicFilter(regex); } else { return new EqualsTopicFilter(filter); } }); }  static MqttTopicFilter toFilter(String topicFilter); static MqttTopicFilter getDefaultTelemetryFilter(); static MqttTopicFilter getDefaultAttributesFilter(); }
MqttTopicFilterFactory { public static MqttTopicFilter toFilter(String topicFilter) { if (topicFilter == null || topicFilter.isEmpty()) { throw new IllegalArgumentException("Topic filter can't be empty!"); } return filters.computeIfAbsent(topicFilter, filter -> { if (filter.contains("+") || filter.contains("#")) { String regex = filter .replace("\\", "\\\\") .replace("+", "[^/]+") .replace("/#", "($|/.*)"); log.debug("Converting [{}] to [{}]", filter, regex); return new RegexTopicFilter(regex); } else { return new EqualsTopicFilter(filter); } }); }  static MqttTopicFilter toFilter(String topicFilter); static MqttTopicFilter getDefaultTelemetryFilter(); static MqttTopicFilter getDefaultAttributesFilter();  }