A Clock implementation that is constructed with a seed timestamp and always reports that same timestamp. @since 0.7.0
| 26 | * @since 0.7.0 |
| 27 | */ |
| 28 | public class FixedClock implements Clock { |
| 29 | |
| 30 | private final Date now; |
| 31 | |
| 32 | /** |
| 33 | * Creates a new fixed clock using <code>new {@link Date Date}()</code> as the seed timestamp. All calls to |
| 34 | * {@link #now now()} will always return this seed Date. |
| 35 | */ |
| 36 | public FixedClock() { |
| 37 | this(new Date()); |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Creates a new fixed clock using the specified seed timestamp. All calls to |
| 42 | * {@link #now now()} will always return this seed Date. |
| 43 | * |
| 44 | * @param now the specified Date to always return from all calls to {@link #now now()}. |
| 45 | */ |
| 46 | public FixedClock(Date now) { |
| 47 | this.now = now; |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Creates a new fixed clock using the specified seed timestamp. All calls to |
| 52 | * {@link #now now()} will always return this seed Date. |
| 53 | * |
| 54 | * @param timeInMillis the specified Date in milliseconds to always return from all calls to {@link #now now()}. |
| 55 | */ |
| 56 | public FixedClock(long timeInMillis) { |
| 57 | this(new Date(timeInMillis)); |
| 58 | } |
| 59 | |
| 60 | @Override |
| 61 | public Date now() { |
| 62 | return this.now; |
| 63 | } |
| 64 | } |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…