Class AdjustableClock

java.lang.Object
net.time4j.clock.AbstractClock
net.time4j.clock.AdjustableClock
All Implemented Interfaces:
TimeSource<Moment>

public final class AdjustableClock extends AbstractClock

Allows miscellaneous adjustments to any clock.

Note: This class is immutable as long as the underlying time source is immutable.

Since:
2.1
Author:
Meno Hochschild
  • Method Details

    • ofSystem

      public static AdjustableClock ofSystem()

      Yields an adjustable clock around the standard system clock.

      The clock can be adjusted using the with()-methods.

      Returns:
      adjustable clock wrapper
      Since:
      2.1
      See Also:
      SystemClock.INSTANCE
    • of

      public static AdjustableClock of(TimeSource<?> source)

      Creates a new adjustable clock for given time source.

      After construction, the clock can be adjusted using the with()-methods.

      Parameters:
      source - time source which shall be adjusted
      Returns:
      new adjustable clock wrapper
      Since:
      2.1
    • withPulse

      public AdjustableClock withPulse(TimeUnit pulse)

      Creates a pulsed clock which only displays the current time in given pulse unit.

      Parameters:
      pulse - new pulse
      Returns:
      adjusted clock with given pulse
      Since:
      2.1
    • withOffset

      public AdjustableClock withOffset(int offset, TimeUnit unit)

      Creates an adjusted clock which displays the current time with given time shift.

      Parameters:
      offset - amount of shift
      unit - unit of shift
      Returns:
      adjusted clock with given shift/offset
      Since:
      2.1
    • currentTime

      public Moment currentTime()
      Description copied from interface: TimeSource

      Yields the current time.

      Returns:
      current time in seconds (as UnixTime object or derivate)
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()

      For debugging purposes.

      Overrides:
      toString in class Object
      Returns:
      description of clock state