protected void rangeCheck(int value, int field) throws ANTLRException { if( value<LOWER_BOUNDS[field] || UPPER_BOUNDS[field]<value ) { error(Messages.BaseParser_OutOfRange(value,LOWER_BOUNDS[field],UPPER_BOUNDS[field])); } }
protected long doRange(int start, int end, int step, int field) throws ANTLRException { rangeCheck(start, field); rangeCheck(end, field); if (step <= 0) error(Messages.BaseParser_MustBePositive(step)); if (start>end) error(Messages.BaseParser_StartEndReversed(end,start)); long bits = 0; for (int i = start; i <= end; i += step) { bits |= 1L << i; } return bits; }
/** * Given a bit mask, finds the first bit that's on, and return its index. */ private int first(CronTab c) { return ceil(c,0); }
/** * @since 1.615 */ private void set(String format, int line, Hash hash, String timezone) throws ANTLRException { CrontabLexer lexer = new CrontabLexer(new StringReader(format)); lexer.setLine(line); CrontabParser parser = new CrontabParser(lexer); parser.setHash(hash); spec = format; specTimezone = timezone; parser.startRule(this); if((dayOfWeek&(1<<7))!=0) { dayOfWeek |= 1; // copy bit 7 over to bit 0 dayOfWeek &= ~(1<<7); // clear bit 7 or CalendarField#ceil will return an invalid value 7 } }
void set(String format, Hash hash) throws ANTLRException { set(format,1,hash); }
/** * Checks if this crontab entry looks reasonable, * and if not, return an warning message. * * <p> * The point of this method is to catch syntactically correct * but semantically suspicious combinations, like * "* 0 * * *" */ public String checkSanity() { for (CronTab tab : tabs) { String s = tab.checkSanity(); if(s!=null) return s; } return null; }
private int floor(CronTab c, int n) { long bits = bits(c); while ((bits|(1L<<n))!=bits) { if (n==0) return -1; n--; } return n; }
/** * Returns true if the given calendar matches */ public synchronized boolean check(Calendar cal) { for (CronTab tab : tabs) { if(tab.check(cal)) return true; } return false; }
protected long doRange( int step, int field ) throws ANTLRException { return doRange( LOWER_BOUNDS[field], UPPER_BOUNDS[field], step, field ); }
private int last(CronTab c) { return floor(c,63); }
void clear(Calendar c) { setTo(c, min); }
/** * Creates a new {@link Trigger} that gets {@link #run() run} * periodically. This is useful when your trigger does * some polling work. */ protected Trigger(@Nonnull String cronTabSpec) throws ANTLRException { this.spec = cronTabSpec; this.tabs = CronTabList.create(cronTabSpec); }
/** * Creates a new {@link Trigger} without using cron. */ protected Trigger() { this.spec = ""; this.tabs = new CronTabList(Collections.<CronTab>emptyList()); }
public void setHash(Hash hash) { if (hash==null) hash = Hash.zero(); this.hash = hash; }
/** * Uses {@link Hash} to choose a random (but stable) value from within this field. * * @param step * Increments. For example, 15 if "H/15". Or {@link #NO_STEP} to indicate * the special constant for "H" without the step value. */ protected long doHash(int step, int field) throws ANTLRException { int u = UPPER_BOUNDS[field]; if (field==2) u = 28; // day of month can vary depending on month, so to make life simpler, just use [1,28] that's always safe if (field==4) u = 6; // Both 0 and 7 of day of week are Sunday. For better distribution, limit upper bound to 6 return doHash(LOWER_BOUNDS[field], u, step, field); }
private void set(String format, int line, Hash hash) throws ANTLRException { set(format, line, hash, null); }
/** * Given the value 'n' (which represents the current value), finds the smallest x such that: * 1) x matches the specified {@link CronTab} (as far as this field is concerned.) * 2) x>=n (inclusive) * * If there's no such bit, return -1. Note that if 'n' already matches the crontab, the same n will be returned. */ private int ceil(CronTab c, int n) { long bits = bits(c); while ((bits|(1L<<n))!=bits) { if (n>60) return -1; n++; } return n; }
protected Hash getHashForTokens() { return HASH_TOKENS ? hash : Hash.zero(); }
/** * @deprecated as of 1.448 * Use {@link #CronTab(String, int, Hash)} */ @Deprecated public CronTab(String format, int line) throws ANTLRException { set(format, line, null); }