public final class ConditionalTimer<T> extends Object
inspect(..), and
the timing starts once a supplied value matches the predicate the timer is
initialized with. The duration can only be retrieved as long as the condition
was met at least on the last invocation of inspect(..), or
it returns Optional.empty().| Modifier and Type | Class and Description |
|---|---|
static class |
ConditionalTimer.WithCustomClockBuilder |
| Modifier and Type | Method and Description |
|---|---|
Optional<Duration> |
getDuration() |
void |
inspect(T value)
Perform inspection of a value to determine if timing should occur.
|
boolean |
longerThan(Duration threshold) |
boolean |
sameOrlessThan(Duration threshold) |
static <T> ConditionalTimer<T> |
timeWhen(Predicate<T> condition) |
static ConditionalTimer.WithCustomClockBuilder |
using(Clock clock) |
public static ConditionalTimer.WithCustomClockBuilder using(Clock clock)
public static <T> ConditionalTimer<T> timeWhen(Predicate<T> condition)
public final void inspect(T value)
public Optional<Duration> getDuration()
Optional.empty()
if the condition is currently not met.public boolean longerThan(Duration threshold)
false if condition is currently not met, true if the current duration
is longer than the given threshold, or false otherwise.Copyright © 2019 Digipost. All rights reserved.