@Test public void testCheckDuration() { final Rule rule = Rule.builder().withMaxDuration(Duration.minutes(10)).build(); final Notification future = Notification.builder().withCreatedAt(ZonedDateTime.parse("2015-07-31T23:31:35Z")).build(); final Notification future2 = Notification.builder().withCreatedAt(ZonedDateTime.parse("2015-07-31T23:21:36Z")).build(); final Notification present = Notification.builder().withCreatedAt(ZonedDateTime.parse("2015-07-31T23:21:35Z")).build(); final Notification past = Notification.builder().withCreatedAt(ZonedDateTime.parse("2015-07-31T23:11:35Z")).build(); final Notification past2 = Notification.builder().withCreatedAt(ZonedDateTime.parse("2015-07-31T23:11:34Z")).build(); final Matcher matcher = new Matcher(rule, notification); assertThat(matcher.checkDuration(future)).isFalse(); assertThat(matcher.checkDuration(future2)).isFalse(); assertThat(matcher.checkDuration(present)).isTrue(); assertThat(matcher.checkDuration(past)).isTrue(); assertThat(matcher.checkDuration(past2)).isFalse(); }
public boolean checkDuration(final Notification notification) { if (!rule.getMaxDuration().isPresent()) { return true; } if (maxDuration > 0 && firstMillis > 0) { final long delta = firstMillis - notification.getCreatedAt().toInstant().toEpochMilli(); if (delta >= 0 && delta <= maxDuration) { return true; } } return false; }
Matcher implements Predicate<Notification>, Comparable<Matcher> { public boolean checkDuration(final Notification notification) { if (!rule.getMaxDuration().isPresent()) { return true; } if (maxDuration > 0 && firstMillis > 0) { final long delta = firstMillis - notification.getCreatedAt().toInstant().toEpochMilli(); if (delta >= 0 && delta <= maxDuration) { return true; } } return false; } }
Matcher implements Predicate<Notification>, Comparable<Matcher> { public boolean checkDuration(final Notification notification) { if (!rule.getMaxDuration().isPresent()) { return true; } if (maxDuration > 0 && firstMillis > 0) { final long delta = firstMillis - notification.getCreatedAt().toInstant().toEpochMilli(); if (delta >= 0 && delta <= maxDuration) { return true; } } return false; } Matcher(final Rule rule, final Notification notification); }
Matcher implements Predicate<Notification>, Comparable<Matcher> { public boolean checkDuration(final Notification notification) { if (!rule.getMaxDuration().isPresent()) { return true; } if (maxDuration > 0 && firstMillis > 0) { final long delta = firstMillis - notification.getCreatedAt().toInstant().toEpochMilli(); if (delta >= 0 && delta <= maxDuration) { return true; } } return false; } Matcher(final Rule rule, final Notification notification); boolean checkMatch(final Notification notification); boolean isFull(); boolean checkCategory(final Notification notification); boolean checkDuration(final Notification notification); @Override boolean test(final Notification notification); Notification getNotification(); @Override boolean equals(final Object obj); @Override int hashCode(); @Override String toString(); @Override int compareTo(final Matcher that); }
Matcher implements Predicate<Notification>, Comparable<Matcher> { public boolean checkDuration(final Notification notification) { if (!rule.getMaxDuration().isPresent()) { return true; } if (maxDuration > 0 && firstMillis > 0) { final long delta = firstMillis - notification.getCreatedAt().toInstant().toEpochMilli(); if (delta >= 0 && delta <= maxDuration) { return true; } } return false; } Matcher(final Rule rule, final Notification notification); boolean checkMatch(final Notification notification); boolean isFull(); boolean checkCategory(final Notification notification); boolean checkDuration(final Notification notification); @Override boolean test(final Notification notification); Notification getNotification(); @Override boolean equals(final Object obj); @Override int hashCode(); @Override String toString(); @Override int compareTo(final Matcher that);  }