/** * * @param calendar */ private void resetTimeToFirstValues(Calendar calendar) { final int currentHour = calendar.get(Calendar.HOUR_OF_DAY); final int currentMinute = calendar.get(Calendar.MINUTE); final int currentSecond = calendar.get(Calendar.SECOND); final int firstHour = this.hour.getFirst(); final int firstMinute = this.minute.getFirst(); final int firstSecond = this.second.getFirst(); if (currentHour != firstHour || currentMinute != firstMinute || currentSecond != firstSecond) { setTime(calendar, firstHour, firstMinute, firstSecond); } }
public Integer getFirstMatch(Calendar cal) { if (this.scheduleExpressionType == ScheduleExpressionType.WILDCARD) { return Calendar.SUNDAY; } SortedSet<Integer> eligibleDaysOfMonth = this.getEligibleDaysOfMonth(cal); if (eligibleDaysOfMonth.isEmpty()) { return null; } return eligibleDaysOfMonth.first(); }
this.second = new Second(schedule.getSecond()); this.minute = new Minute(schedule.getMinute()); this.hour = new Hour(schedule.getHour()); this.dayOfWeek = new DayOfWeek(schedule.getDayOfWeek()); this.dayOfMonth = new DayOfMonth(schedule.getDayOfMonth()); this.month = new Month(schedule.getMonth()); this.year = new Year(schedule.getYear()); String timezoneId = schedule.getTimezone(); if (timezoneId != null && !(timezoneId = timezoneId.trim()).isEmpty()) {
Integer nextSecond = this.second.getNextMatch(currentSecond); if (nextSecond == null) { return null; currentMinute++; Integer nextMinute = this.minute.getNextMatch(currentMinute < 60 ? currentMinute : 0); if (nextMinute == null) { return null; nextSecond = this.second.getNextMatch(0); currentHour++; Integer nextHour = this.hour.getNextMatch(currentHour < 24 ? currentHour : 0); if (nextHour == null) { return null; nextSecond = this.second.getNextMatch(0); nextMinute = this.minute.getNextMatch(0);
protected void processSingleValue(SingleValue singleValue) { String value = singleValue.getValue(); if (this.isRelativeValue(value)) { this.relativeValues.add(singleValue); } else { Integer val = this.parseInt(value); this.assertValid(val); this.absoluteValues.add(val); } }
protected void processIncrement(IncrementValue incr) { String startValue = incr.getStart(); Integer start = startValue.equals("*") ? 0 : this.parseInt(startValue); // make sure it's a valid value this.assertValid(start); Integer interval = this.parseInt(incr.getInterval()); this.absoluteValues.add(start); int next = start + interval; int maxValue = this.getMaxValue(); while (next <= maxValue) { this.absoluteValues.add(next); next = next + interval; } }
protected void assertValid(Integer value) throws IllegalArgumentException { if (value == null) { throw EjbLogger.EJB3_TIMER_LOGGER.couldNotParseScheduleExpression(this.origValue); } int max = this.getMaxValue(); int min = this.getMinValue(); if (value > max || value < min) { throw EjbLogger.EJB3_TIMER_LOGGER.invalidValuesRange(value, min, max); } }
@Override public boolean isRelativeValue(String value) { if (value == null) { throw EjbLogger.EJB3_TIMER_LOGGER.relativeValueIsNull(); } if (value.equalsIgnoreCase("last")) { return true; } if (this.isValidNegativeDayOfMonth(value)) { return true; } if (this.isDayOfWeekBased(value)) { return true; } return false; }
private Calendar computeNextMonth(Calendar nextCal) { Integer nextMonth = this.month.getNextMatch(nextCal); nextCal.set(Calendar.DAY_OF_WEEK, this.dayOfWeek.getFirst()); nextCal.set(Calendar.DAY_OF_MONTH, 1); resetTimeToFirstValues(nextCal);
private Calendar computeNextYear(Calendar nextCal) { Integer nextYear = this.year.getNextMatch(nextCal); if (nextYear == null || nextYear > Year.MAX_YEAR) { return null; } int currentYear = nextCal.get(Calendar.YEAR); // if the current year is a match, then nothing else to // do. Just return back the calendar if (currentYear == nextYear) { return nextCal; } // If the next year is lesser than the current year, then // we have no more timeouts for the calendar expression if (nextYear < currentYear) { return null; } // at this point we have chosen a year which is greater than the current // year. // set the chosen year nextCal.set(Calendar.YEAR, nextYear); // since we are moving to a different year (as compared to the current year), // we should reset all other calendar attribute expressions appropriately, to their first possible // values nextCal.set(Calendar.MONTH, this.month.getFirstMatch()); nextCal.set(Calendar.DAY_OF_MONTH, 1); resetTimeToFirstValues(nextCal); // recompute date nextCal = this.computeNextDate(nextCal); return nextCal; }
@Override protected Integer parseInt(String alias) { try { return super.parseInt(alias); } catch (NumberFormatException nfe) { if (MONTH_ALIAS != null) { String lowerCaseAlias = alias.toLowerCase(Locale.ENGLISH); return MONTH_ALIAS.get(lowerCaseAlias); } } return null; }
protected void processListValue(ListValue list) { for (String listItem : list.getValues()) { this.processListItem(listItem); } }
@Override protected void assertValid(Integer value) throws IllegalArgumentException { if (value != null && value == 0) { throw EjbLogger.EJB3_TIMER_LOGGER.invalidValueDayOfMonth(value); } super.assertValid(value); }
public int getFirst() { if (this.scheduleExpressionType == ScheduleExpressionType.WILDCARD) { return 0; } SortedSet<Integer> eligibleMinutes = this.getEligibleMinutes(); if (eligibleMinutes.isEmpty()) { throw EjbLogger.EJB3_TIMER_LOGGER.invalidExpressionMinutes(this.origValue); } return eligibleMinutes.first(); }
private Calendar computeNextDayOfWeek(Calendar nextCal) { Integer nextDayOfWeek = this.dayOfWeek.getNextMatch(nextCal);
private Calendar advanceTillMonthHasDate(Calendar cal, Integer date) { resetTimeToFirstValues(cal); // make sure the month can handle the date while (monthHasDate(cal, date) == false) { if (cal.get(Calendar.YEAR) > Year.MAX_YEAR) { return null; } // this month can't handle the date, so advance month to next month // and get the next suitable matching month cal.add(Calendar.MONTH, 1); cal = this.computeNextMonth(cal); if (cal == null) { return null; } date = this.dayOfMonth.getFirstMatch(cal); if (date == null) { return null; } } cal.set(Calendar.DAY_OF_MONTH, date); return cal; }
@Override protected Integer parseInt(String alias) { try { return super.parseInt(alias); } catch (NumberFormatException nfe) { if (DAY_OF_WEEK_ALIAS != null) { String lowerCaseAlias = alias.toLowerCase(Locale.ENGLISH); return DAY_OF_WEEK_ALIAS.get(lowerCaseAlias); } } return null; }
public Integer getNextMatch(Calendar currentCal) { if (this.scheduleExpressionType == ScheduleExpressionType.WILDCARD) { return currentCal.get(Calendar.DAY_OF_MONTH); } int currentDayOfMonth = currentCal.get(Calendar.DAY_OF_MONTH); SortedSet<Integer> eligibleDaysOfMonth = this.getEligibleDaysOfMonth(currentCal); if (eligibleDaysOfMonth.isEmpty()) { return null; } for (Integer hour : eligibleDaysOfMonth) { if (currentDayOfMonth == hour) { return currentDayOfMonth; } if (hour > currentDayOfMonth) { return hour; } } return eligibleDaysOfMonth.first(); }
@Override protected Integer parseInt(String alias) { try { return super.parseInt(alias); } catch (NumberFormatException nfe) { if (DAY_OF_MONTH_ALIAS != null) { String lowerCaseAlias = alias.toLowerCase(Locale.ENGLISH); return DAY_OF_MONTH_ALIAS.get(lowerCaseAlias); } } return null; } }