| 1 | package org.amicofragile.time; |
| 2 | |
| 3 | import java.util.Date; |
| 4 | |
| 5 | /** |
| 6 | * {@link TimeSource} returning constant current time. |
| 7 | * @author Pietro Martinelli |
| 8 | * |
| 9 | */ |
| 10 | public class ConstantTimeSource implements TimeSource { |
| 11 | /** |
| 12 | * Holds constant current time to return. |
| 13 | */ |
| 14 | private final long currentTime; |
| 15 | /** |
| 16 | * Initializes a {@link TimeSource} who returns constant current time, specified by constructor parameter. |
| 17 | * @param current Constant current time |
| 18 | */ |
| 19 | public ConstantTimeSource(final long current) { |
| 20 | this.currentTime = current; |
| 21 | } |
| 22 | /** |
| 23 | * Initializes a {@link TimeSource} who returns constant current time, specified as {@link java.util.Date} by constructor parameter. |
| 24 | * @param current Constant current time |
| 25 | */ |
| 26 | public ConstantTimeSource(final Date now) { |
| 27 | this.currentTime = now.getTime(); |
| 28 | } |
| 29 | /** |
| 30 | * @see TimeSource#currentTimeInMillis() |
| 31 | * @return constructor-specified current time. |
| 32 | */ |
| 33 | @Override |
| 34 | public final long currentTimeInMillis() { |
| 35 | return this.currentTime; |
| 36 | } |
| 37 | } |