Skip to content

Commit

Permalink
Eagerly initialize ZERO_NANOS constant
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoeller committed Jan 29, 2024
1 parent 0e5edc4 commit 43ecb0b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,14 @@
* Created using the {@code parse*} methods.
*
* @author Arjen Poutsma
* @author Juergen Hoeller
* @since 5.3
*/
final class BitsCronField extends CronField {

private static final long MASK = 0xFFFFFFFFFFFFFFFFL;


@Nullable
private static BitsCronField zeroNanos = null;
public static final BitsCronField ZERO_NANOS = forZeroNanos();

private static final long MASK = 0xFFFFFFFFFFFFFFFFL;

// we store at most 60 bits, for seconds and minutes, so a 64-bit long suffices
private long bits;
Expand All @@ -48,16 +46,14 @@ private BitsCronField(Type type) {
super(type);
}


/**
* Return a {@code BitsCronField} enabled for 0 nanoseconds.
*/
public static BitsCronField zeroNanos() {
if (zeroNanos == null) {
BitsCronField field = new BitsCronField(Type.NANO);
field.setBit(0);
zeroNanos = field;
}
return zeroNanos;
private static BitsCronField forZeroNanos() {
BitsCronField field = new BitsCronField(Type.NANO);
field.setBit(0);
return field;
}

/**
Expand Down Expand Up @@ -108,7 +104,6 @@ public static BitsCronField parseDaysOfWeek(String value) {
return result;
}


private static BitsCronField parseDate(String value, BitsCronField.Type type) {
if (value.equals("?")) {
value = "*";
Expand Down Expand Up @@ -174,6 +169,7 @@ private static ValueRange parseRange(String value, Type type) {
}
}


@Nullable
@Override
public <T extends Temporal & Comparable<? super T>> T nextOrSame(T temporal) {
Expand Down Expand Up @@ -217,7 +213,6 @@ private int nextSetBit(int fromIndex) {
else {
return -1;
}

}

private void setBits(ValueRange range) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

/**
* Single field in a cron pattern. Created using the {@code parse*} methods,
* main and only entry point is {@link #nextOrSame(Temporal)}.
* the main and only entry point is {@link #nextOrSame(Temporal)}.
*
* <p>Supports a Quartz day-of-month/week field with an L/# expression. Follows
* common cron conventions in every other respect, including 0-6 for SUN-SAT
Expand Down Expand Up @@ -60,7 +60,7 @@ protected CronField(Type type) {
* Return a {@code CronField} enabled for 0 nanoseconds.
*/
public static CronField zeroNanos() {
return BitsCronField.zeroNanos();
return BitsCronField.ZERO_NANOS;
}

/**
Expand Down Expand Up @@ -186,7 +186,6 @@ protected enum Type {
MONTH(ChronoField.MONTH_OF_YEAR, ChronoUnit.YEARS, ChronoField.DAY_OF_MONTH, ChronoField.HOUR_OF_DAY, ChronoField.MINUTE_OF_HOUR, ChronoField.SECOND_OF_MINUTE, ChronoField.NANO_OF_SECOND),
DAY_OF_WEEK(ChronoField.DAY_OF_WEEK, ChronoUnit.WEEKS, ChronoField.HOUR_OF_DAY, ChronoField.MINUTE_OF_HOUR, ChronoField.SECOND_OF_MINUTE, ChronoField.NANO_OF_SECOND);


private final ChronoField field;

private final ChronoUnit higherOrder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ public static boolean isQuartzDaysOfMonthField(String value) {
}

/**
* Parse the given value into a days of months {@code QuartzCronField}, the fourth entry of a cron expression.
* Expects a "L" or "W" in the given value.
* Parse the given value into a days of months {@code QuartzCronField},
* the fourth entry of a cron expression.
* <p>Expects a "L" or "W" in the given value.
*/
public static QuartzCronField parseDaysOfMonth(String value) {
int idx = value.lastIndexOf('L');
Expand Down

0 comments on commit 43ecb0b

Please sign in to comment.