com.h3c.util

## Class Clock

- java.lang.Object
- - com.h3c.util.Clock

-     public final class Clock
      extends Object

  Simple facade for obtaining current time and date. The clock source can be the default `System.currentTimeMillis()` or for testing purposes, it can be an internal source whose time can be manipulated.

  Use of this facade allows applications sensitive to time-related context to be easily unit tested under simulated and accelerated time-lines.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static interface` | `Clock.WarpingTimeSource` Facade for implementing a time source capable of being warped with respect to real time.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static void` | `assertRealTimeSource()` Sets the time-source to one backed by `System.currentTimeMillis()` and asserts that no other time-source has been previously set.
    `static void` | `assertTestTimeSource()` Sets the time-source to one capable of being warped relative to the `System.currentTimeMillis()` and asserts that no other time-source has been previously set.
    `static long` | `currentTimeMillis()` Get the current time in milliseconds since start of epoch.
    `static Date` | `date()` Get the date corresponding to the current time of the source.
    `static Clock.WarpingTimeSource` | `source()` Get the current time source, which may be capable of time-warping

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### assertRealTimeSource

          public static void assertRealTimeSource()
                                           throws IllegalStateException

      Sets the time-source to one backed by `System.currentTimeMillis()` and asserts that no other time-source has been previously set.

      Calling this method multiple times has no side effects.

      Throws:
        `IllegalStateException` - if a time-source, other than has been previously latched

    - #### assertTestTimeSource

          public static void assertTestTimeSource()

      Sets the time-source to one capable of being warped relative to the `System.currentTimeMillis()` and asserts that no other time-source has been previously set.

      Calling this method multiple times has no side effects.

      Throws:
        `IllegalStateException` - if a time-source, other than this one has been previously latches

    - #### source

          public static Clock.WarpingTimeSource source()

      Get the current time source, which may be capable of time-warping
      Returns:
        current time source

    - #### currentTimeMillis

          public static long currentTimeMillis()

      Get the current time in milliseconds since start of epoch.
      Returns:
        number of milliseconds elapsed since start of epoch
      See Also:
        `System.currentTimeMillis()`

    - #### date

          public static Date date()

      Get the date corresponding to the current time of the source.
      Returns:
        number of milliseconds elapsed since start of epoch
      See Also:
        `System.currentTimeMillis()`, `Date.Date(long)`

Copyright © 2014. All Rights Reserved.