Class Clock.TimeSourceClock

  • All Implemented Interfaces:
    java.io.Serializable
    Enclosing class:
    Clock

    private static final class Clock.TimeSourceClock
    extends Clock
    implements java.io.Serializable
    Implementation of a clock based on a time-source.
    • Field Detail

      • serialVersionUID

        private static final long serialVersionUID
        A serialization identifier for this class.
        See Also:
        Constant Field Values
      • timeSource

        private final TimeSource timeSource
        The time-source being used.
      • zone

        private final TimeZone zone
        The time-zone being used.
    • Constructor Detail

      • TimeSourceClock

        private TimeSourceClock​(TimeSource timeSource,
                                TimeZone zone)
        Restricted constructor.
    • Method Detail

      • getSource

        public TimeSource getSource()
        Gets the time-source being used to create dates and times.

        The standard implementation of Clock uses a time-source to provide the current instant. This method returns that time-source.

        Non-standard implementations may choose to use another means to obtain instants, dates and times, thus this method is allowed to throw UnsupportedOperationException.

        Overrides:
        getSource in class Clock
        Returns:
        the time-source being used to obtain instants, never null
      • withSource

        public Clock withSource​(TimeSource timeSource)
        Returns a copy of this clock with a different time-source.

        The standard implementation of Clock uses a time-source to provide the current instant. This method allows that time-source to be changed.

        Non-standard implementations may choose to use another means to obtain instants, dates and times, thus this method is allowed to throw UnsupportedOperationException.

        Overrides:
        withSource in class Clock
        Parameters:
        timeSource - the time-source to change to, not null
        Returns:
        the new clock with the altered time-source, never null
      • getZone

        public TimeZone getZone()
        Gets the time-zone being used to create dates and times.

        The standard implementation of Clock uses a time-zone to interpret the current instant. This method returns that time-zone.

        Non-standard implementations may choose to use another means to interpret instants, dates and times, thus this method is allowed to throw UnsupportedOperationException.

        Overrides:
        getZone in class Clock
        Returns:
        the time-zone being used to interpret instants, never null
      • withZone

        public Clock withZone​(TimeZone zone)
        Returns a copy of this clock with a different time-zone.

        The standard implementation of Clock uses a time-zone to interpret the current instant. This method allows that time-zone to be changed.

        Non-standard implementations may choose to use another means to interpret instants, dates and times, thus this method is allowed to throw UnsupportedOperationException.

        Overrides:
        withZone in class Clock
        Parameters:
        zone - the time-zone to change to, not null
        Returns:
        the new clock with the altered time-zone, never null
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • hashCode

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

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object