31
31
*/
32
32
package org .jresearch .threetenbp .gwt .emu .java .time ;
33
33
34
- import static org .jresearch .threetenbp .gwt .emu .java .time .LocalTime .NANOS_PER_MINUTE ;
35
- import static org .jresearch .threetenbp .gwt .emu .java .time .LocalTime .NANOS_PER_SECOND ;
34
+ import static org .jresearch .threetenbp .gwt .emu .java .time .LocalTime .*;
36
35
37
36
import java .io .Serializable ;
38
- import org .jresearch .threetenbp .gwt .emu .java .time .Clock ;
39
- import org .jresearch .threetenbp .gwt .emu .java .time .DateTimeException ;
40
- import org .jresearch .threetenbp .gwt .emu .java .time .Duration ;
41
- import org .jresearch .threetenbp .gwt .emu .java .time .Instant ;
42
- import org .jresearch .threetenbp .gwt .emu .java .time .ZoneId ;
43
- import org .jresearch .threetenbp .gwt .emu .java .time .ZoneOffset ;
44
37
import java .util .Objects ;
45
38
import java .util .TimeZone ;
46
39
@@ -116,7 +109,7 @@ public abstract class Clock {
116
109
* @return a clock that uses the best available system clock in the UTC zone, not null
117
110
*/
118
111
public static Clock systemUTC () {
119
- return new SystemClock ( ZoneOffset . UTC ) ;
112
+ return SystemClock . CLOCK_UTC ;
120
113
}
121
114
122
115
/**
@@ -159,9 +152,19 @@ public static Clock systemDefaultZone() {
159
152
*/
160
153
public static Clock system (ZoneId zone ) {
161
154
Objects .requireNonNull (zone , "zone" );
155
+ if (zone == ZoneOffset .UTC ) {
156
+ return SystemClock .CLOCK_UTC ;
157
+ }
162
158
return new SystemClock (zone );
163
159
}
164
160
161
+ //-------------------------------------------------------------------------
162
+ /**
163
+ * @since 9
164
+ */
165
+ public static Clock tickMillis (ZoneId zone ) {
166
+ return new TickClock (system (zone ), NANOS_PER_MILLI );
167
+ }
165
168
//-------------------------------------------------------------------------
166
169
/**
167
170
* Obtains a clock that returns the current instant ticking in whole seconds
@@ -403,6 +406,7 @@ public int hashCode() {
403
406
*/
404
407
static final class SystemClock extends Clock implements Serializable {
405
408
private static final long serialVersionUID = 6740630888130243051L ;
409
+ static final SystemClock CLOCK_UTC = new SystemClock (ZoneOffset .UTC );
406
410
private final ZoneId zone ;
407
411
408
412
SystemClock (ZoneId zone ) {
@@ -414,8 +418,8 @@ public ZoneId getZone() {
414
418
}
415
419
@ Override
416
420
public Clock withZone (ZoneId zone ) {
417
- //GWT specific
418
- Objects .requireNonNull (zone );
421
+ //GWT specific
422
+ Objects .requireNonNull (zone );
419
423
if (zone .equals (this .zone )) { // intentional NPE
420
424
return this ;
421
425
}
@@ -452,7 +456,7 @@ public String toString() {
452
456
* This is typically used for testing.
453
457
*/
454
458
static final class FixedClock extends Clock implements Serializable {
455
- private static final long serialVersionUID = 7430389292664866958L ;
459
+ private static final long serialVersionUID = 7430389292664866958L ;
456
460
private final Instant instant ;
457
461
private final ZoneId zone ;
458
462
@@ -466,8 +470,8 @@ public ZoneId getZone() {
466
470
}
467
471
@ Override
468
472
public Clock withZone (ZoneId zone ) {
469
- //GWT specific
470
- Objects .requireNonNull (zone );
473
+ //GWT specific
474
+ Objects .requireNonNull (zone );
471
475
if (zone .equals (this .zone )) { // intentional NPE
472
476
return this ;
473
477
}
@@ -504,7 +508,7 @@ public String toString() {
504
508
* Implementation of a clock that adds an offset to an underlying clock.
505
509
*/
506
510
static final class OffsetClock extends Clock implements Serializable {
507
- private static final long serialVersionUID = 2007484719125426256L ;
511
+ private static final long serialVersionUID = 2007484719125426256L ;
508
512
private final Clock baseClock ;
509
513
private final Duration offset ;
510
514
@@ -518,8 +522,8 @@ public ZoneId getZone() {
518
522
}
519
523
@ Override
520
524
public Clock withZone (ZoneId zone ) {
521
- //GWT specific
522
- Objects .requireNonNull (zone );
525
+ //GWT specific
526
+ Objects .requireNonNull (zone );
523
527
if (zone .equals (baseClock .getZone ())) { // intentional NPE
524
528
return this ;
525
529
}
@@ -570,8 +574,8 @@ public ZoneId getZone() {
570
574
}
571
575
@ Override
572
576
public Clock withZone (ZoneId zone ) {
573
- //GWT specific
574
- Objects .requireNonNull (zone );
577
+ //GWT specific
578
+ Objects .requireNonNull (zone );
575
579
if (zone .equals (baseClock .getZone ())) { // intentional NPE
576
580
return this ;
577
581
}
0 commit comments