public class ManualTimeProvider extends Object implements TimeProvider, Serializable
TimeProvider that provides time
that is constant; the time is changed exclusively by invoking appropriate methods.
This implementation is useful for testing, where non-real-time scenarios need to be checked.
Notice that the millisecond value may be negative - the class makes no checks in this regard.
| Modifier and Type | Field and Description |
|---|---|
protected AtomicLong |
time |
| Constructor and Description |
|---|
ManualTimeProvider()
Instantiates a new manual time provider that is initialized
to the current system time.
|
ManualTimeProvider(long startTime)
Instantiates a new manual time provider that is initialized
to the provided start time specified as milliseconds.
|
| Modifier and Type | Method and Description |
|---|---|
long |
getTimeInMillis()
Gets current time in milliseconds.
|
ManualTimeProvider |
setTimeInMillis(long millis)
Changes the time of this
TimeProvider to the new value given in milliseconds. |
ManualTimeProvider |
step(long incrementMillis)
Changes the time of this
TimeProvider by the specified increment
specified in milliseconds. |
ManualTimeProvider |
step(long increment,
TimeUnit unit)
Changes the time of this
TimeProvider by the specified increment. |
String |
toString() |
protected final AtomicLong time
public ManualTimeProvider()
public ManualTimeProvider(long startTime)
startTime - the start time given in millisecondspublic long getTimeInMillis()
TimeProvidergetTimeInMillis in interface TimeProviderpublic ManualTimeProvider setTimeInMillis(long millis)
TimeProvider to the new value given in milliseconds.millis - new time given in millisecondspublic ManualTimeProvider step(long incrementMillis)
TimeProvider by the specified increment
specified in milliseconds.
The increment may be negative.
incrementMillis - the increment given in millisecondspublic ManualTimeProvider step(long increment, TimeUnit unit)
TimeProvider by the specified increment.
The increment may be negative.
increment - the incrementunit - time unit of the incrementNullPointerException - if unit is nullCopyright © 2014 Boleslav Bobcik - Auderis. All rights reserved.