< prev index next >

src/java.base/share/classes/java/time/Clock.java

Print this page




 624             }
 625             return false;
 626         }
 627         @Override
 628         public int hashCode() {
 629             return instant.hashCode() ^ zone.hashCode();
 630         }
 631         @Override
 632         public String toString() {
 633             return "FixedClock[" + instant + "," + zone + "]";
 634         }
 635     }
 636 
 637     //-----------------------------------------------------------------------
 638     /**
 639      * Implementation of a clock that adds an offset to an underlying clock.
 640      */
 641     static final class OffsetClock extends Clock implements Serializable {
 642         @java.io.Serial
 643         private static final long serialVersionUID = 2007484719125426256L;

 644         private final Clock baseClock;
 645         private final Duration offset;
 646 
 647         OffsetClock(Clock baseClock, Duration offset) {
 648             this.baseClock = baseClock;
 649             this.offset = offset;
 650         }
 651         @Override
 652         public ZoneId getZone() {
 653             return baseClock.getZone();
 654         }
 655         @Override
 656         public Clock withZone(ZoneId zone) {
 657             if (zone.equals(baseClock.getZone())) {  // intentional NPE
 658                 return this;
 659             }
 660             return new OffsetClock(baseClock.withZone(zone), offset);
 661         }
 662         @Override
 663         public long millis() {


 675             }
 676             return false;
 677         }
 678         @Override
 679         public int hashCode() {
 680             return baseClock.hashCode() ^ offset.hashCode();
 681         }
 682         @Override
 683         public String toString() {
 684             return "OffsetClock[" + baseClock + "," + offset + "]";
 685         }
 686     }
 687 
 688     //-----------------------------------------------------------------------
 689     /**
 690      * Implementation of a clock that adds an offset to an underlying clock.
 691      */
 692     static final class TickClock extends Clock implements Serializable {
 693         @java.io.Serial
 694         private static final long serialVersionUID = 6504659149906368850L;

 695         private final Clock baseClock;
 696         private final long tickNanos;
 697 
 698         TickClock(Clock baseClock, long tickNanos) {
 699             this.baseClock = baseClock;
 700             this.tickNanos = tickNanos;
 701         }
 702         @Override
 703         public ZoneId getZone() {
 704             return baseClock.getZone();
 705         }
 706         @Override
 707         public Clock withZone(ZoneId zone) {
 708             if (zone.equals(baseClock.getZone())) {  // intentional NPE
 709                 return this;
 710             }
 711             return new TickClock(baseClock.withZone(zone), tickNanos);
 712         }
 713         @Override
 714         public long millis() {




 624             }
 625             return false;
 626         }
 627         @Override
 628         public int hashCode() {
 629             return instant.hashCode() ^ zone.hashCode();
 630         }
 631         @Override
 632         public String toString() {
 633             return "FixedClock[" + instant + "," + zone + "]";
 634         }
 635     }
 636 
 637     //-----------------------------------------------------------------------
 638     /**
 639      * Implementation of a clock that adds an offset to an underlying clock.
 640      */
 641     static final class OffsetClock extends Clock implements Serializable {
 642         @java.io.Serial
 643         private static final long serialVersionUID = 2007484719125426256L;
 644         @SuppressWarnings("serial") // Not statically typed as Serializable
 645         private final Clock baseClock;
 646         private final Duration offset;
 647 
 648         OffsetClock(Clock baseClock, Duration offset) {
 649             this.baseClock = baseClock;
 650             this.offset = offset;
 651         }
 652         @Override
 653         public ZoneId getZone() {
 654             return baseClock.getZone();
 655         }
 656         @Override
 657         public Clock withZone(ZoneId zone) {
 658             if (zone.equals(baseClock.getZone())) {  // intentional NPE
 659                 return this;
 660             }
 661             return new OffsetClock(baseClock.withZone(zone), offset);
 662         }
 663         @Override
 664         public long millis() {


 676             }
 677             return false;
 678         }
 679         @Override
 680         public int hashCode() {
 681             return baseClock.hashCode() ^ offset.hashCode();
 682         }
 683         @Override
 684         public String toString() {
 685             return "OffsetClock[" + baseClock + "," + offset + "]";
 686         }
 687     }
 688 
 689     //-----------------------------------------------------------------------
 690     /**
 691      * Implementation of a clock that adds an offset to an underlying clock.
 692      */
 693     static final class TickClock extends Clock implements Serializable {
 694         @java.io.Serial
 695         private static final long serialVersionUID = 6504659149906368850L;
 696         @SuppressWarnings("serial") // Not statically typed as Serializable
 697         private final Clock baseClock;
 698         private final long tickNanos;
 699 
 700         TickClock(Clock baseClock, long tickNanos) {
 701             this.baseClock = baseClock;
 702             this.tickNanos = tickNanos;
 703         }
 704         @Override
 705         public ZoneId getZone() {
 706             return baseClock.getZone();
 707         }
 708         @Override
 709         public Clock withZone(ZoneId zone) {
 710             if (zone.equals(baseClock.getZone())) {  // intentional NPE
 711                 return this;
 712             }
 713             return new TickClock(baseClock.withZone(zone), tickNanos);
 714         }
 715         @Override
 716         public long millis() {


< prev index next >