@Test public void testPredicateSearch() { InMemoryMessageStore<String, OptionalFields, OptionalFields._Field > store = new InMemoryMessageStore<>(); store.put(UUID.randomUUID().toString(), OptionalFields.builder() .setStringValue("foo") .setIntegerValue(12) .build()); store.put(UUID.randomUUID().toString(), OptionalFields.builder() .setStringValue("bar") .setIntegerValue(123) .build()); store.put(UUID.randomUUID().toString(), OptionalFields.builder() .setStringValue("baz") .setIntegerValue(1234) .build()); PredicateFilterMessageStoreSearcher<Pattern, String, OptionalFields, OptionalFields._Field> sut = new PredicateFilterMessageStoreSearcher<>(store, ((key, message, query) -> query.matcher(message.getStringValue()).matches())); List<OptionalFields> result1 = sut.search(Pattern.compile("f.*")); assertThat(result1, hasItems(OptionalFields.builder() .setStringValue("foo") .setIntegerValue(12) .build())); assertThat(result1, hasSize(1)); List<OptionalFields> result2 = sut.search(Pattern.compile("ba.*")); assertThat(result2, hasItems(OptionalFields.builder() .setStringValue("bar") .setIntegerValue(123) .build(), OptionalFields.builder() .setStringValue("baz") .setIntegerValue(1234) .build())); assertThat(result2, hasSize(2)); }
@Nonnull @Override public List<M> search(@Nonnull Q query) { return stream(query).collect(Collectors.toList()); }
PredicateFilterMessageStoreSearcher implements MessageSearcher<Q, M, F> { @Nonnull @Override public List<M> search(@Nonnull Q query) { return stream(query).collect(Collectors.toList()); } }
PredicateFilterMessageStoreSearcher implements MessageSearcher<Q, M, F> { @Nonnull @Override public List<M> search(@Nonnull Q query) { return stream(query).collect(Collectors.toList()); } @SuppressWarnings("unchecked")  PredicateFilterMessageStoreSearcher(MessageReadOnlyStore<K, M, F> store,
                                               PredicateFilter<Q, K, M, F> predicate); }
PredicateFilterMessageStoreSearcher implements MessageSearcher<Q, M, F> { @Nonnull @Override public List<M> search(@Nonnull Q query) { return stream(query).collect(Collectors.toList()); } @SuppressWarnings("unchecked")  PredicateFilterMessageStoreSearcher(MessageReadOnlyStore<K, M, F> store,
                                               PredicateFilter<Q, K, M, F> predicate); @Nonnull @Override List<M> search(@Nonnull Q query); @Nonnull @Override Stream<M> stream(@Nonnull Q query); }
PredicateFilterMessageStoreSearcher implements MessageSearcher<Q, M, F> { @Nonnull @Override public List<M> search(@Nonnull Q query) { return stream(query).collect(Collectors.toList()); } @SuppressWarnings("unchecked")  PredicateFilterMessageStoreSearcher(MessageReadOnlyStore<K, M, F> store,
                                               PredicateFilter<Q, K, M, F> predicate); @Nonnull @Override List<M> search(@Nonnull Q query); @Nonnull @Override Stream<M> stream(@Nonnull Q query);  }