src/java.base/share/classes/java/time/Clock.java
changeset 57956 e0b8b019d2f5
parent 50473 bef0ed237504
child 58520 e036ee8bae56
equal deleted inserted replaced
57955:18863bf3501f 57956:e0b8b019d2f5
     1 /*
     1 /*
     2  * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
   477     /**
   477     /**
   478      * Implementation of a clock that always returns the latest time from
   478      * Implementation of a clock that always returns the latest time from
   479      * {@link System#currentTimeMillis()}.
   479      * {@link System#currentTimeMillis()}.
   480      */
   480      */
   481     static final class SystemClock extends Clock implements Serializable {
   481     static final class SystemClock extends Clock implements Serializable {
       
   482         @java.io.Serial
   482         private static final long serialVersionUID = 6740630888130243051L;
   483         private static final long serialVersionUID = 6740630888130243051L;
   483         private static final long OFFSET_SEED =
   484         private static final long OFFSET_SEED =
   484                 System.currentTimeMillis()/1000 - 1024; // initial offest
   485                 System.currentTimeMillis()/1000 - 1024; // initial offest
   485         static final SystemClock UTC = new SystemClock(ZoneOffset.UTC);
   486         static final SystemClock UTC = new SystemClock(ZoneOffset.UTC);
   486 
   487 
   570         }
   571         }
   571         @Override
   572         @Override
   572         public String toString() {
   573         public String toString() {
   573             return "SystemClock[" + zone + "]";
   574             return "SystemClock[" + zone + "]";
   574         }
   575         }
       
   576         @java.io.Serial
   575         private void readObject(ObjectInputStream is)
   577         private void readObject(ObjectInputStream is)
   576                 throws IOException, ClassNotFoundException {
   578                 throws IOException, ClassNotFoundException {
   577             // ensure that offset is initialized
   579             // ensure that offset is initialized
   578             is.defaultReadObject();
   580             is.defaultReadObject();
   579             offset = OFFSET_SEED;
   581             offset = OFFSET_SEED;
   584     /**
   586     /**
   585      * Implementation of a clock that always returns the same instant.
   587      * Implementation of a clock that always returns the same instant.
   586      * This is typically used for testing.
   588      * This is typically used for testing.
   587      */
   589      */
   588     static final class FixedClock extends Clock implements Serializable {
   590     static final class FixedClock extends Clock implements Serializable {
       
   591         @java.io.Serial
   589         private static final long serialVersionUID = 7430389292664866958L;
   592         private static final long serialVersionUID = 7430389292664866958L;
   590         private final Instant instant;
   593         private final Instant instant;
   591         private final ZoneId zone;
   594         private final ZoneId zone;
   592 
   595 
   593         FixedClock(Instant fixedInstant, ZoneId zone) {
   596         FixedClock(Instant fixedInstant, ZoneId zone) {
   634     //-----------------------------------------------------------------------
   637     //-----------------------------------------------------------------------
   635     /**
   638     /**
   636      * Implementation of a clock that adds an offset to an underlying clock.
   639      * Implementation of a clock that adds an offset to an underlying clock.
   637      */
   640      */
   638     static final class OffsetClock extends Clock implements Serializable {
   641     static final class OffsetClock extends Clock implements Serializable {
       
   642         @java.io.Serial
   639         private static final long serialVersionUID = 2007484719125426256L;
   643         private static final long serialVersionUID = 2007484719125426256L;
   640         private final Clock baseClock;
   644         private final Clock baseClock;
   641         private final Duration offset;
   645         private final Duration offset;
   642 
   646 
   643         OffsetClock(Clock baseClock, Duration offset) {
   647         OffsetClock(Clock baseClock, Duration offset) {
   684     //-----------------------------------------------------------------------
   688     //-----------------------------------------------------------------------
   685     /**
   689     /**
   686      * Implementation of a clock that adds an offset to an underlying clock.
   690      * Implementation of a clock that adds an offset to an underlying clock.
   687      */
   691      */
   688     static final class TickClock extends Clock implements Serializable {
   692     static final class TickClock extends Clock implements Serializable {
       
   693         @java.io.Serial
   689         private static final long serialVersionUID = 6504659149906368850L;
   694         private static final long serialVersionUID = 6504659149906368850L;
   690         private final Clock baseClock;
   695         private final Clock baseClock;
   691         private final long tickNanos;
   696         private final long tickNanos;
   692 
   697 
   693         TickClock(Clock baseClock, long tickNanos) {
   698         TickClock(Clock baseClock, long tickNanos) {