Skip to content

Commit

Permalink
fix(code): Small code clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
yyvess committed Feb 16, 2024
1 parent a4bd9e9 commit c5adec3
Show file tree
Hide file tree
Showing 15 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/cronutils/descriptor/CronDescriptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public String describeDayOfWeek(final Map<CronFieldName, CronField> fields, fina
final String description = DescriptionStrategyFactory.daysOfWeekInstance(
resourceBundle,
fields.containsKey(CronFieldName.DAY_OF_WEEK) ? fields.get(CronFieldName.DAY_OF_WEEK).getExpression() : null,
definitions.containsKey(CronFieldName.DAY_OF_WEEK) ? definitions.get(CronFieldName.DAY_OF_WEEK) : null
definitions.getOrDefault(CronFieldName.DAY_OF_WEEK, null)
).describe();
return addExpressions(description, resourceBundle.getString("day"), resourceBundle.getString("days"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ private void registerFunctions() {
/**
* Contains CronFieldExpression instances for hours, minutes and seconds.
*/
class TimeFields {
static class TimeFields {
private final FieldExpression seconds;
private final FieldExpression minutes;
private final FieldExpression hours;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,7 @@ public void register(final FieldDefinition definition) {
* @return returns CronDefinition instance, never null
*/
public CronDefinition instance() {
final Set<CronConstraint> validations = new HashSet<>();
validations.addAll(cronConstraints);
final Set<CronConstraint> validations = new HashSet<>(cronConstraints);
final List<FieldDefinition> values = new ArrayList<>(fields.values());
values.sort(FieldDefinition.createFieldDefinitionComparator());
return new CronDefinition(values, validations, cronNicknames, matchDayOfWeekAndDayOfMonth);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.cronutils.model.definition;

public enum CronNicknames {
YEARLY, ANNUALLY, MONTHLY, WEEKLY, DAILY, MIDNIGHT, HOURLY, REBOOT;
YEARLY, ANNUALLY, MONTHLY, WEEKLY, DAILY, MIDNIGHT, HOURLY, REBOOT
}
2 changes: 1 addition & 1 deletion src/main/java/com/cronutils/model/field/CronFieldName.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public enum CronFieldName {
* effective bi-, tri- or quad-weekly schedules via proprietary cron expressions.
*/

private int order;
private final int order;

/**
* Constructor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public String asString() {
builder.append(expressions.get(j).asString());
builder.append(",");
}
if(expressions.size()>0){
if(!expressions.isEmpty()){
builder.append(expressions.get(expressions.size() - 1).asString());
}
return builder.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
public enum Weekdays {
MONDAY(1), TUESDAY(2), WEDNESDAY(3), THURSDAY(4), FRIDAY(5), SATURDAY(6), SUNDAY(7);

private int weekday;
private final int weekday;

Weekdays(int weekday) {
this.weekday = weekday;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
public class SpecialCharFieldValue extends FieldValue<SpecialChar> {

private static final long serialVersionUID = -2177180413324528746L;
private SpecialChar specialChar = SpecialChar.NONE;
private SpecialChar specialChar;

public SpecialCharFieldValue(final SpecialChar specialChar) {
Preconditions.checkNotNull(specialChar, "special char must not be null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ public Optional<Duration> timeFromLastExecution(ZonedDateTime date) {

@Override
public boolean isMatch(ZonedDateTime date) {
return executionTimes.parallelStream().map(e->e.isMatch(date)).filter(v-> v).count()>0;
return executionTimes.parallelStream().map(e -> e.isMatch(date)).anyMatch(v -> v);
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/cronutils/model/time/ExecutionTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public interface ExecutionTime {
* @param cron - Cron instance
* @return ExecutionTime instance
*/
public static ExecutionTime forCron(final Cron cron) {
static ExecutionTime forCron(final Cron cron) {
if (cron instanceof SingleCron) {
final Map<CronFieldName, CronField> fields = cron.retrieveFieldsAsMap();
final ExecutionTimeBuilder executionTimeBuilder = new ExecutionTimeBuilder(cron);
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/cronutils/Issue305Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void testIssue305(){
dates.add(nextExecution.get());
nextExecution = executionTime.nextExecution(nextExecution.get());
}
Set<Integer> years = dates.stream().map(d->d.getYear()).collect(Collectors.toSet());
Set<Integer> years = dates.stream().map(ZonedDateTime::getYear).collect(Collectors.toSet());
Set<Integer> expectedYears = new HashSet<>();
expectedYears.add(2015);
expectedYears.add(2017);
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/cronutils/Issue423Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void issue423() {
final CronParser parser = new CronParser(CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ));
final Cron cron = parser.parse("0 0 0-07,17-0 ? * SAT");
final CronDescriptor cd = CronDescriptor.instance(Locale.UK);
assertTrue(cd.describe(cron).length() > 0);
assertTrue(!cd.describe(cron).isEmpty());
// at time of test creation, the descriptor is
// "every hour between 0 and 7 and every hour between 17 and 0 at Saturday day"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class CronConverterTest {

// Fix the date to prevent test failure during the transition between Standard Time and Daylight Time.
Function<ZoneId, Calendar> calendarFactory = (zoneId) -> {
Calendar fixedDay = new GregorianCalendar(2020, 06, 01);
Calendar fixedDay = new GregorianCalendar(2020, Calendar.JULY, 01);
fixedDay.setTimeZone(TimeZone.getTimeZone(zoneId));
return fixedDay;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void testAnd() {
assertTrue(and.getExpressions().contains(testCronFieldExpression));
}

class TestFieldExpression extends FieldExpression {
static class TestFieldExpression extends FieldExpression {

private static final long serialVersionUID = 8101930390397976027L;

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/cronutils/parser/CronParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void testParseIncompleteEvery() {
private static void validateExpression(CronType cronType, String expression) {
CronDefinition cronDefinition = CronDefinitionBuilder.instanceDefinitionFor(cronType);
CronParser parser = new CronParser(cronDefinition);
System.out.println(String.format("Validating expression '%s' using %s definition", expression, cronType));
System.out.printf("Validating expression '%s' using %s definition%n", expression, cronType);
parser.parse(expression);
}

Expand Down

0 comments on commit c5adec3

Please sign in to comment.