public final class ControllableClock extends Clock implements TimeControllable, Serializable
Clock, typically intended for use in testing. A ControllableClock
may either be freely running (as e.g. the system clock) or freezed, and can in all cases be set
to a new point in time.| Modifier and Type | Method and Description |
|---|---|
default no.digipost.time.ClockSnapshot |
clockSnapshot()
Resolves a
ClockSnapshot. |
static ControllableClock |
control(Clock clock)
Create a controllable clock based on an existing clock.
|
<X extends Exception> |
doWithTimeAdjusted(Consumer<TimeControllable> adjustClock,
ThrowingConsumer<Instant,X> action)
Perform an action with the clock adjusted, and have the clock reset to it's original state
after the action has finished.
|
boolean |
equals(Object obj) |
static ControllableClock |
freezedAt(Instant instant)
Create a new controllable clock freezed at a given instant,
and with the
default time zone. |
static ControllableClock |
freezedAt(Instant instant,
ZoneId zone)
|
static ControllableClock |
freezedAt(LocalDateTime dateTime)
Create a new controllable clock freezed at the instant resolved from a given
LocalDateTime and the default time zone. |
static ControllableClock |
freezedAt(ZonedDateTime dateTime)
Create a new controllable clock freezed at the instant of a given
ZonedDateTime. |
<T,X extends Exception> |
getWithTimeAdjusted(Consumer<TimeControllable> adjustClock,
ThrowingFunction<Instant,T,X> resolveValue)
Resolve a value with the clock adjusted, and have the clock reset to it's original state
after the operation has finished.
|
ZoneId |
getZone() |
int |
hashCode() |
Instant |
instant() |
LocalDateTime |
localDateTime()
Gets the current
LocalDateTime resolved for the zone of the clock. |
void |
set(UnaryOperator<Clock> createNewClock)
Set a new clock to resolve the time from.
|
String |
toString() |
ControllableClock |
withZone(ZoneId zone) |
ZonedDateTime |
zonedDateTime()
Gets the current
ZonedDateTime resolved with the zone of the clock. |
fixed, millis, offset, system, systemDefaultZone, systemUTC, tick, tickMinutes, tickSecondsclone, finalize, getClass, notify, notifyAll, wait, wait, waitfreeze, freezeAt, freezeAt, freezeAt, freezeAt, freezeAt, set, set, set, set, set, setToSystemClock, setToSystemClock, timePasses, timePassespublic static ControllableClock freezedAt(LocalDateTime dateTime)
LocalDateTime and the default time zone.
The clock will not progress on its own, and will yield the instant
it is set to.dateTime - The date and time to set for the new freezed clock.ControllableClockpublic static ControllableClock freezedAt(ZonedDateTime dateTime)
ZonedDateTime.
The clock will not progress on its own, and will yield the instant
it is set to.dateTime - The date and time to set for the new freezed clock.ControllableClockpublic static ControllableClock freezedAt(Instant instant)
default time zone.
The clock will not progress on its own, and will yield the instant
it is set to.instant - The instant to set for the new freezed clock.ControllableClockpublic static ControllableClock freezedAt(Instant instant, ZoneId zone)
Instant, and with a given ZoneId.
The clock will not progress on its own, and will yield a set instant.instant - The instant to set for the new freezed clock.zone - The time zone of the new freezed clock.ControllableClockpublic static ControllableClock control(Clock clock)
ControllableClock will have the same behavior (freezed or progressing)
and time as the given clock, but may be mutated to yield another instant, or
be freezed. The given clock is of course not altered.clock - The clock to base the new ControllableClock instance on.ControllableClockpublic ControllableClock withZone(ZoneId zone)
public ZonedDateTime zonedDateTime()
ZonedDateTime resolved with the zone of the clock.public LocalDateTime localDateTime()
LocalDateTime resolved for the zone of the clock.public <X extends Exception> void doWithTimeAdjusted(Consumer<TimeControllable> adjustClock, ThrowingConsumer<Instant,X> action) throws X extends Exception
X - Exception the may be thrown from the given actionadjustClock - how to adjust the clock before running the actionaction - the action to perform, which is given an instant resolved from the adjusted clockX - if the given action throws an exceptionX extends Exceptionpublic <T,X extends Exception> T getWithTimeAdjusted(Consumer<TimeControllable> adjustClock, ThrowingFunction<Instant,T,X> resolveValue) throws X extends Exception
T - The returned typeX - Exception the may be thrown from the given functionadjustClock - how to adjust the clock before running the actionresolveValue - the operation which resolves the value, which is given an instant resolved from the adjusted clockresolveValue functionX - if the function throws an exception while resolving the value.X extends Exceptionpublic void set(UnaryOperator<Clock> createNewClock)
TimeControllableset in interface TimeControllablecreateNewClock - function which is given the current clock, which may
be used to create a new clock.public no.digipost.time.ClockSnapshot clockSnapshot()
ClockSnapshot.
The method is not part of the public API of Digg.Copyright © 2019 Digipost. All rights reserved.