Package no.digipost.time
Class ConditionalTimer<T>
java.lang.Object
no.digipost.time.ConditionalTimer<T>
A util for timing the duration a type of value meets a set condition. The value
is supplied periodically to the timer with
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().-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionfinal voidPerform inspection of a value to determine if timing should occur.booleanlongerThan(Duration threshold) booleansameOrlessThan(Duration threshold) static <T> ConditionalTimer<T>
-
Method Details
-
using
-
timeWhen
-
inspect
Perform inspection of a value to determine if timing should occur. -
getDuration
- Returns:
- the duration of the currently ongoing met condition, or
Optional.empty()if the condition is currently not met.
-
longerThan
- Returns:
falseif condition is currently not met,trueif the currentdurationis longer than the given threshold, orfalseotherwise.
-
sameOrlessThan
- Returns:
trueif condition is currently not met or the currentdurationis less than the given threshold, orfalseotherwise.
-