Skip to content

Instantly share code, notes, and snippets.

@eisenjulian
Last active October 7, 2016 17:38
Show Gist options
  • Save eisenjulian/4a1423e42eb262bfcfc777751d24b20c to your computer and use it in GitHub Desktop.
Save eisenjulian/4a1423e42eb262bfcfc777751d24b20c to your computer and use it in GitHub Desktop.
final Optional<Pattern> customerNamePattern = filters.stream().filter(m -> "customerName".equals(m.get("t")))
.map(m -> m.get("_id_").toString().trim())
.findAny()
.map(pattern -> Pattern.compile(pattern, Pattern.CASE_INSENSITIVE));
final Optional<String> customerEmail = filters.stream().filter(m -> "customerEmail".equals(m.get("t")))
.map(m -> m.get("_id_").toString().trim())
.findAny();
final Predicate<Customer> customerFilter = c ->
customerEmail.map(email -> c.EMAIL.hasData() && email.equalsIgnoreCase(c.EMAIL.get())).orElse(true) &&
customerNamePattern.map(pattern -> pattern.matcher(c.getCompleteName()).find()).orElse(true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment