1
1
/*
2
- * Copyright 2002-2023 the original author or authors.
2
+ * Copyright 2002-2024 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
33
33
*/
34
34
final class BitsCronField extends CronField {
35
35
36
- private static final long MASK = 0xFFFFFFFFFFFFFFFFL ;
37
-
38
-
39
- @ Nullable
40
- private static BitsCronField zeroNanos = null ;
36
+ public static BitsCronField ZERO_NANOS = forZeroNanos ();
41
37
38
+ private static final long MASK = 0xFFFFFFFFFFFFFFFFL ;
42
39
43
40
// we store at most 60 bits, for seconds and minutes, so a 64-bit long suffices
44
41
private long bits ;
@@ -48,16 +45,14 @@ private BitsCronField(Type type) {
48
45
super (type );
49
46
}
50
47
48
+
51
49
/**
52
50
* Return a {@code BitsCronField} enabled for 0 nanoseconds.
53
51
*/
54
- public static BitsCronField zeroNanos () {
55
- if (zeroNanos == null ) {
56
- BitsCronField field = new BitsCronField (Type .NANO );
57
- field .setBit (0 );
58
- zeroNanos = field ;
59
- }
60
- return zeroNanos ;
52
+ private static BitsCronField forZeroNanos () {
53
+ BitsCronField field = new BitsCronField (Type .NANO );
54
+ field .setBit (0 );
55
+ return field ;
61
56
}
62
57
63
58
/**
@@ -108,7 +103,6 @@ public static BitsCronField parseDaysOfWeek(String value) {
108
103
return result ;
109
104
}
110
105
111
-
112
106
private static BitsCronField parseDate (String value , BitsCronField .Type type ) {
113
107
if (value .equals ("?" )) {
114
108
value = "*" ;
@@ -174,6 +168,7 @@ private static ValueRange parseRange(String value, Type type) {
174
168
}
175
169
}
176
170
171
+
177
172
@ Nullable
178
173
@ Override
179
174
public <T extends Temporal & Comparable <? super T >> T nextOrSame (T temporal ) {
@@ -217,7 +212,6 @@ private int nextSetBit(int fromIndex) {
217
212
else {
218
213
return -1 ;
219
214
}
220
-
221
215
}
222
216
223
217
private void setBits (ValueRange range ) {
@@ -247,23 +241,19 @@ private void setBit(int index) {
247
241
}
248
242
249
243
private void clearBit (int index ) {
250
- this .bits &= ~(1L << index );
244
+ this .bits &= ~(1L << index );
251
245
}
252
246
247
+
253
248
@ Override
254
- public int hashCode () {
255
- return Long .hashCode (this .bits );
249
+ public boolean equals (Object other ) {
250
+ return (this == other || (other instanceof BitsCronField that &&
251
+ type () == that .type () && this .bits == that .bits ));
256
252
}
257
253
258
254
@ Override
259
- public boolean equals (@ Nullable Object o ) {
260
- if (this == o ) {
261
- return true ;
262
- }
263
- if (!(o instanceof BitsCronField other )) {
264
- return false ;
265
- }
266
- return type () == other .type () && this .bits == other .bits ;
255
+ public int hashCode () {
256
+ return Long .hashCode (this .bits );
267
257
}
268
258
269
259
@ Override
0 commit comments