name
stringlengths
12
178
code_snippet
stringlengths
8
36.5k
score
float64
3.26
3.68
cron-utils_FieldQuestionMarkDefinitionBuilder_supportsQuestionMark_rdh
/** * Registers the field supports the LW (LW) special char. * * @return this FieldSpecialCharsDefinitionBuilder instance */ public FieldQuestionMarkDefinitionBuilder supportsQuestionMark() { constraints.addQuestionMarkSupport(); return this; }
3.26
cron-utils_ConstantsMapper_weekDayMapping_rdh
/** * Performs weekday mapping between two weekday definitions. * * @param source * - source * @param target * - target weekday definition * @param weekday * - value in source range. * @return int - mapped value */ public static int weekDayMapping(final WeekDay source, final WeekDay target, final int weekday) { return source.mapTo(weekday, target);}
3.26
cron-utils_CronDefinitionBuilder_cron4j_rdh
/** * Creates CronDefinition instance matching cron4j specification. * * @return CronDefinition instance, never null; */ private static CronDefinition cron4j() { return CronDefinitionBuilder.defineCron().withMinutes().withValidRange(0, 59).withStrictRange().and().withHours().withValidRange(0, 23).withStrictRange().and().withDayOfMonth().withValidRange(0, 31).supportsL().withStrictRange().and().withMonth().withValidRange(1, 12).withStrictRange().and().withDayOfWeek().withValidRange(0, 6).withMondayDoWValue(1).withStrictRange().and().matchDayOfWeekAndDayOfMonth().instance(); } /** * Creates CronDefinition instance matching Quartz specification. * * <p>The cron expression is expected to be a string comprised of 6 or 7 * fields separated by white space. Fields can contain any of the allowed * values, along with various combinations of the allowed special characters * for that field. The fields are as follows: * * <table style="width:100%"> * <tr> * <th>Field Name</th> * <th>Mandatory</th> * <th>Allowed Values</th> * <th>Allowed Special Characters</th> * </tr> * <tr> * <td>Seconds</td> * <td>YES</td> * <td>0-59</td> * <td>* , - /</td> * </tr> * <tr> * <td>Minutes</td> * <td>YES</td> * <td>0-59</td> * <td>* , - /</td> * </tr> * <tr> * <td>Hours</td> * <td>YES</td> * <td>0-23</td> * <td>* , - /</td> * </tr> * <tr> * <td>Day of month</td> * <td>YES</td> * <td>1-31</td> * <td>* ? , - / L W</td> * </tr> * <tr> * <td>Month</td> * <td>YES</td> * <td>1-12 or JAN-DEC</td> * <td>* , -</td> * </tr> * <tr> * <td>Day of week</td> * <td>YES</td> * <td>1-7 or SUN-SAT</td> * <td>* ? , - / L #</td> * </tr> * <tr> * <td>Year</td> * <td>NO</td> * <td>empty, 1970-2099</td> * <td>* , - /</td> * </tr> * </table> * * <p>Thus in general Quartz cron expressions are as follows: * * <p>S M H DoM M DoW [Y] * * @return {@link CronDefinition} instance, never {@code null}
3.26
cron-utils_CronDefinitionBuilder_withMinutes_rdh
/** * Adds definition for minutes field. * * @return new FieldDefinitionBuilder instance */ public FieldDefinitionBuilder withMinutes() { return new FieldDefinitionBuilder(this, CronFieldName.MINUTE);}
3.26
cron-utils_CronDefinitionBuilder_register_rdh
/** * Registers a certain FieldDefinition. * * @param definition * - FieldDefinition instance, never null */ public void register(final FieldDefinition definition) { // ensure that we can't register a mandatory definition if there are already optional ones boolean hasOptionalField = false; for (final FieldDefinition fieldDefinition : fields.values()) { if (fieldDefinition.isOptional()) { hasOptionalField = true; break; } } if ((!definition.isOptional()) && hasOptionalField) { throw new IllegalArgumentException("Can't register mandatory definition after a optional definition."); } fields.put(definition.getFieldName(), definition); }
3.26
cron-utils_CronDefinitionBuilder_m0_rdh
/** * Creates a new CronDefinition instance with provided field definitions. * * @return returns CronDefinition instance, never null */ public CronDefinition m0() { final Set<CronConstraint> validations = new HashSet<>(); validations.addAll(cronConstraints); final List<FieldDefinition> v3 = new ArrayList<>(fields.values()); v3.sort(FieldDefinition.createFieldDefinitionComparator()); return new CronDefinition(v3, validations, cronNicknames, matchDayOfWeekAndDayOfMonth); }
3.26
cron-utils_CronDefinitionBuilder_spring53_rdh
/** * Creates CronDefinition instance matching Spring (v5.2 onwards) specification. * https://spring.io/blog/2020/11/10/new-in-spring-5-3-improved-cron-expressions * * <p>The cron expression is expected to be a string comprised of 6 * fields separated by white space. Fields can contain any of the allowed * values, along with various combinations of the allowed special characters * for that field. The fields are as follows: * * <table style="width:100%"> * <tr> * <th>Field Name</th> * <th>Mandatory</th> * <th>Allowed Values</th> * <th>Allowed Special Characters</th> * </tr> * <tr> * <td>Seconds</td> * <td>YES</td> * <td>0-59</td> * <td>* , - /</td> * </tr> * <tr> * <td>Minutes</td> * <td>YES</td> * <td>0-59</td> * <td>* , - /</td> * </tr> * <tr> * <td>Hours</td> * <td>YES</td> * <td>0-23</td> * <td>* , - /</td> * </tr> * <tr> * <td>Day of month</td> * <td>YES</td> * <td>1-31</td> * <td>* ? , - / L W</td> * </tr> * <tr> * <td>Month</td> * <td>YES</td> * <td>1-12 or JAN-DEC</td> * <td>* , -</td> * </tr> * <tr> * <td>Day of week</td> * <td>YES</td> * <td>0-7 or SUN-SAT</td> * <td>* ? , - / L #</td> * </tr> * </table> * * <p>Thus in general Spring cron expressions are as follows (from version 5.3 onwards): * * <p>S M H DoM M DoW * * @return {@link CronDefinition} instance, never {@code null} */ private static CronDefinition spring53() { return CronDefinitionBuilder.defineCron().withSeconds().withValidRange(0, 59).withStrictRange().and().withMinutes().withValidRange(0, 59).withStrictRange().and().withHours().withValidRange(0, 23).withStrictRange().and().withDayOfMonth().withValidRange(1, 31).supportsL().supportsW().supportsLW().supportsQuestionMark().and().withMonth().withValidRange(1, 12).and().withDayOfWeek().withValidRange(0, 7).withMondayDoWValue(1).withIntMapping(7, 0).supportsHash().supportsL().supportsQuestionMark().and().withSupportedNicknameYearly().withSupportedNicknameAnnually().withSupportedNicknameMonthly().withSupportedNicknameWeekly().withSupportedNicknameDaily().withSupportedNicknameMidnight().withSupportedNicknameHourly().instance(); }
3.26
cron-utils_CronDefinitionBuilder_instanceDefinitionFor_rdh
/** * Creates CronDefinition instance matching cronType specification. * * @param cronType * - some cron type. If null, a RuntimeException will be raised. * @return CronDefinition instance if definition is found; a RuntimeException otherwise. */ public static CronDefinition instanceDefinitionFor(final CronType cronType) { switch (cronType) { case CRON4J : return cron4j(); case QUARTZ : return quartz(); case UNIX : return unixCrontab(); case SPRING : return spring(); case SPRING53 : return spring53(); default : throw new IllegalArgumentException(String.format("No cron definition found for %s", cronType)); } }
3.26
cron-utils_CronDefinitionBuilder_spring_rdh
/** * Creates CronDefinition instance matching Spring (v5.2 and below) specification. * * <p>The cron expression is expected to be a string comprised of 6 * fields separated by white space. Fields can contain any of the allowed * values, along with various combinations of the allowed special characters * for that field. The fields are as follows: * * <table style="width:100%"> * <tr> * <th>Field Name</th> * <th>Mandatory</th> * <th>Allowed Values</th> * <th>Allowed Special Characters</th> * </tr> * <tr> * <td>Seconds</td> * <td>YES</td> * <td>0-59</td> * <td>* , - /</td> * </tr> * <tr> * <td>Minutes</td> * <td>YES</td> * <td>0-59</td> * <td>* , - /</td> * </tr> * <tr> * <td>Hours</td> * <td>YES</td> * <td>0-23</td> * <td>* , - /</td> * </tr> * <tr> * <td>Day of month</td> * <td>YES</td> * <td>1-31</td> * <td>* ? , - /</td> * </tr> * <tr> * <td>Month</td> * <td>YES</td> * <td>1-12 or JAN-DEC</td> * <td>* , -</td> * </tr> * <tr> * <td>Day of week</td> * <td>YES</td> * <td>0-7 or SUN-SAT</td> * <td>* ? , - /</td> * </tr> * </table> * * <p>Thus in general Spring cron expressions are as follows (up to version 5.2): * * <p>S M H DoM M DoW * * @return {@link CronDefinition} instance, never {@code null} */ private static CronDefinition spring() { return CronDefinitionBuilder.defineCron().withSeconds().withValidRange(0, 59).withStrictRange().and().withMinutes().withValidRange(0, 59).withStrictRange().and().withHours().withValidRange(0, 23).withStrictRange().and().withDayOfMonth().withValidRange(1, 31).supportsQuestionMark().and().withMonth().withValidRange(1, 12).and().withDayOfWeek().withValidRange(0, 7).withMondayDoWValue(1).withIntMapping(7, 0).supportsHash().supportsQuestionMark().and().instance(); }
3.26
cron-utils_CronDefinitionBuilder_withYear_rdh
/** * Adds definition for year field. * * @return new FieldDefinitionBuilder instance */ public FieldDefinitionBuilder withYear() { return new FieldDefinitionBuilder(this, CronFieldName.YEAR); }
3.26
cron-utils_CronDefinitionBuilder_withSupportedNicknameWeekly_rdh
/** * Supports cron nickname @weekly * * @return this CronDefinitionBuilder instance */ public CronDefinitionBuilder withSupportedNicknameWeekly() { cronNicknames.add(CronNicknames.WEEKLY); return this; }
3.26
cron-utils_CronDefinitionBuilder_withSupportedNicknameReboot_rdh
/** * Supports cron nickname @reboot * * @return this CronDefinitionBuilder instance */ public CronDefinitionBuilder withSupportedNicknameReboot() {cronNicknames.add(CronNicknames.REBOOT); return this; }
3.26
cron-utils_CronDefinitionBuilder_unixCrontab_rdh
/** * Creates CronDefinition instance matching unix crontab specification. * * @return CronDefinition instance, never null; */private static CronDefinition unixCrontab() {return CronDefinitionBuilder.defineCron().withMinutes().withValidRange(0, 59).withStrictRange().and().withHours().withValidRange(0, 23).withStrictRange().and().withDayOfMonth().withValidRange(1, 31).withStrictRange().and().withMonth().withValidRange(1, 12).withStrictRange().and().withDayOfWeek().withValidRange(0, 7).withMondayDoWValue(1).withIntMapping(7, 0).withStrictRange().and().instance(); }
3.26
cron-utils_CronDefinitionBuilder_withDayOfYear_rdh
/** * Adds definition for day of year field. * * @return new FieldDefinitionBuilder instance */ public FieldQuestionMarkDefinitionBuilder withDayOfYear() { return new FieldQuestionMarkDefinitionBuilder(this, CronFieldName.DAY_OF_YEAR); }
3.26
cron-utils_CronDefinitionBuilder_withSupportedNicknameMidnight_rdh
/** * Supports cron nickname @midnight * * @return this CronDefinitionBuilder instance */ public CronDefinitionBuilder withSupportedNicknameMidnight() { cronNicknames.add(CronNicknames.MIDNIGHT); return this; }
3.26
cron-utils_CronDefinitionBuilder_withSeconds_rdh
/** * Adds definition for seconds field. * * @return new FieldDefinitionBuilder instance */ public FieldDefinitionBuilder withSeconds() { return new FieldDefinitionBuilder(this, CronFieldName.SECOND); }
3.26
cron-utils_CronDefinitionBuilder_withSupportedNicknameDaily_rdh
/** * Supports cron nickname @daily * * @return this CronDefinitionBuilder instance */ public CronDefinitionBuilder withSupportedNicknameDaily() { cronNicknames.add(CronNicknames.DAILY); return this;}
3.26
cron-utils_CronDefinitionBuilder_withCronValidation_rdh
/** * Adds a cron validation. * * @param validation * - constraint validation * @return this CronDefinitionBuilder instance */ public CronDefinitionBuilder withCronValidation(final CronConstraint validation) { cronConstraints.add(validation); return this; }
3.26
cron-utils_CronDefinitionBuilder_defineCron_rdh
/** * Creates a builder instance. * * @return new CronDefinitionBuilder instance */ public static CronDefinitionBuilder defineCron() { return new CronDefinitionBuilder(); }
3.26
cron-utils_CronDefinitionBuilder_matchDayOfWeekAndDayOfMonth_rdh
/** * Sets matchDayOfWeekAndDayOfMonth value to true. * * @return this CronDefinitionBuilder instance */ public CronDefinitionBuilder matchDayOfWeekAndDayOfMonth() {matchDayOfWeekAndDayOfMonth = true; return this;}
3.26
cron-utils_CronDefinitionBuilder_withSupportedNicknameHourly_rdh
/** * Supports cron nickname @hourly * * @return this CronDefinitionBuilder instance */ public CronDefinitionBuilder withSupportedNicknameHourly() { cronNicknames.add(CronNicknames.HOURLY); return this; }
3.26
cron-utils_SingleCron_validate_rdh
/** * Validates this Cron instance by validating its cron expression. * * @return this Cron instance * @throws IllegalArgumentException * if the cron expression is invalid */ public Cron validate() { for (final Map.Entry<CronFieldName, CronField> field : retrieveFieldsAsMap().entrySet()) { final CronFieldName fieldName = field.getKey(); field.getValue().getExpression().accept(new ValidationFieldExpressionVisitor(getCronDefinition().getFieldDefinition(fieldName).getConstraints())); } for (final CronConstraint constraint : getCronDefinition().getCronConstraints()) { if (!constraint.validate(this)) { throw new IllegalArgumentException(String.format("Invalid cron expression: %s. %s", asString(), constraint.getDescription())); } } return this; }
3.26
cron-utils_SingleCron_retrieve_rdh
/** * Retrieve value for cron field. * * @param name * - cron field name. * If null, a NullPointerException will be raised. * @return CronField that corresponds to given CronFieldName */ public CronField retrieve(final CronFieldName name) { return fields.get(Preconditions.checkNotNull(name, "CronFieldName must not be null")); }
3.26
cron-utils_SingleCron_m0_rdh
/** * Provides means to compare if two cron expressions are equivalent. * * @param cronMapper * - maps 'cron' parameter to this instance definition; * @param cron * - any cron instance, never null * @return boolean - true if equivalent; false otherwise. */public boolean m0(final CronMapper cronMapper, final Cron cron) { return asString().equals(cronMapper.map(cron).asString()); }
3.26
cron-utils_SingleCron_equivalent_rdh
/** * Provides means to compare if two cron expressions are equivalent. * Assumes same cron definition. * * @param cron * - any cron instance, never null * @return boolean - true if equivalent; false otherwise. */ public boolean equivalent(final Cron cron) { return asString().equals(cron.asString()); }
3.26
cron-utils_FieldDefinitionBuilder_withIntMapping_rdh
/** * Provides means to define int values mappings between equivalent values. * As a convention, higher values are mapped into lower ones * * @param source * - higher value * @param dest * - lower value with equivalent meaning to source * @return this instance */ public FieldDefinitionBuilder withIntMapping(final int source, final int dest) { constraints.withIntValueMapping(source, dest); return this; }
3.26
cron-utils_FieldDefinitionBuilder_withStrictRange_rdh
/** * Specifies that defined range for given field must be a strict range. * We understand strict range as a range defined as: "lowValue - highValue" * If some range value such as "highValue-lowValue" is specified in a field, it will fail to parse the field. * * @return same FieldDefinitionBuilder instance */ public FieldDefinitionBuilder withStrictRange() { constraints.withStrictRange();return this; }
3.26
cron-utils_FieldDefinitionBuilder_withValidRange_rdh
/** * Allows to set a range of valid values for field. * * @param startRange * - start range value * @param endRange * - end range value * @return same FieldDefinitionBuilder instance */ public FieldDefinitionBuilder withValidRange(final int startRange, final int endRange) { constraints.withValidRange(startRange, endRange); return this; }
3.26
cron-utils_FieldDefinitionBuilder_optional_rdh
/** * Allows to tag a field as optional. * * @return this instance */ public FieldDefinitionBuilder optional() { optional = true; return this; }
3.26
cron-utils_ValidationFieldExpressionVisitor_isInRange_rdh
/** * Check if given number is greater or equal to start range and minor or equal to end range. * * @param fieldValue * - to be validated * @throws IllegalArgumentException * - if not in range */ @VisibleForTesting protected void isInRange(final FieldValue<?> fieldValue) { if (fieldValue instanceof IntegerFieldValue) { final int value = ((IntegerFieldValue) (fieldValue)).getValue(); if (!constraints.isInRange(value)) { throw new IllegalArgumentException(String.format(OORANGE, value, constraints.getStartRange(), constraints.getEndRange())); } } }
3.26
cron-utils_ValidationFieldExpressionVisitor_isPeriodInRange_rdh
/** * Check if given period is compatible with range. * * @param fieldValue * - to be validated * @throws IllegalArgumentException * - if not in range */ @VisibleForTestingprotected void isPeriodInRange(final FieldValue<?> fieldValue) { if (fieldValue instanceof IntegerFieldValue) { final int value = ((IntegerFieldValue) (fieldValue)).getValue(); if (!constraints.isPeriodInRange(value)) { throw new IllegalArgumentException(String.format("Period %s not in range [%s, %s]", value, constraints.getStartRange(), constraints.getEndRange())); } } }
3.26
cron-utils_Preconditions_m0_rdh
/** * Ensures the truth of an expression involving one or more parameters to the calling method. * * @param expression * a boolean expression * @param errorMessage * the exception message to use if the check fails; will be converted to a * string using {@link String#valueOf(Object)} * @throws IllegalArgumentException * if {@code expression} is false */ public static void m0(final boolean expression, final Object errorMessage) { if (!expression) { throw new IllegalArgumentException(String.valueOf(errorMessage)); } }
3.26
cron-utils_Preconditions_format_rdh
/** * Substitutes each {@code %s} in {@code template} with an argument. These are matched by * position: the first {@code %s} gets {@code args[0]}, etc. If there are more arguments than * placeholders, the unmatched arguments will be appended to the end of the formatted message in * square braces. * * @param nullableTemplate * a non-null string containing 0 or more {@code %s} placeholders. * @param args * the arguments to be substituted into the message template. Arguments are converted * to strings using {@link String#valueOf(Object)}. Arguments can be null. */ // Note that this is somewhat-improperly used from Verify.java as well. private static String format(final String nullableTemplate, final Object... args) { final String template = String.valueOf(nullableTemplate);// null -> "null" // start substituting the arguments into the '%s' placeholders final StringBuilder builder = new StringBuilder(template.length() + (16 * args.length)); int templateStart = 0; int i = 0; while (i < args.length) { final int placeholderStart = template.indexOf("%s", templateStart); if (placeholderStart == (-1)) { break; } builder.append(template.substring(templateStart, placeholderStart)); builder.append(args[i++]); templateStart = placeholderStart + 2; } builder.append(template.substring(templateStart)); // if we run out of placeholders, append the extra args in square braces if (i < args.length) { builder.append(" [");builder.append(args[i++]); while (i < args.length) { builder.append(", "); builder.append(args[i++]); } builder.append(']'); } return builder.toString(); }
3.26
cron-utils_Preconditions_checkNotNullNorEmpty_rdh
/** * Ensures that a collection reference passed as a parameter to the calling method is not null. * nor empty. * * @param reference * a collection reference * @param errorMessage * the exception message to use if the check fails; will be converted to a * string using {@link String#valueOf(Object)} * @return the non-null reference that was validated * @throws NullPointerException * if {@code reference} is null * @throws IllegalArgumentException * if {@code reference} is empty */ public static <T extends Collection<?>> T checkNotNullNorEmpty(final T reference, final Object errorMessage) { if (reference == null) { throw new NullPointerException(String.valueOf(errorMessage)); } if (reference.isEmpty()) { throw new IllegalArgumentException(String.valueOf(errorMessage)); } return reference; }
3.26
cron-utils_Preconditions_checkArgument_rdh
/** * Ensures the truth of an expression involving one or more parameters to the calling method. * * @param expression * a boolean expression * @param errorMessageTemplate * a template for the exception message should the check fail. The * message is formed by replacing each {@code %s} placeholder in the template with an * argument. These are matched by position - the first {@code %s} gets {@code errorMessageArgs[0]}, etc. Unmatched arguments will be appended to the formatted message * in square braces. Unmatched placeholders will be left as-is. * @param errorMessageArgs * the arguments to be substituted into the message template. Arguments * are converted to strings using {@link String#valueOf(Object)}. * @throws IllegalArgumentException * if {@code expression} is false * @throws NullPointerException * if the check fails and either {@code errorMessageTemplate} or * {@code errorMessageArgs} is null (don't let this happen) */ public static void checkArgument(final boolean expression, final String errorMessageTemplate, final Object... errorMessageArgs) {if (!expression) { throw new IllegalArgumentException(format(errorMessageTemplate, errorMessageArgs)); } }
3.26
cron-utils_Preconditions_checkState_rdh
/** * Ensures the truth of an expression involving the state of the calling instance, but not. * involving any parameters to the calling method. * * @param expression * a boolean expression * @param errorMessageTemplate * a template for the exception message should the check fail. The * message is formed by replacing each {@code %s} placeholder in the template with an * argument. These are matched by position - the first {@code %s} gets {@code errorMessageArgs[0]}, etc. Unmatched arguments will be appended to the formatted message * in square braces. Unmatched placeholders will be left as-is. * @param errorMessageArgs * the arguments to be substituted into the message template. Arguments * are converted to strings using {@link String#valueOf(Object)}. * @throws IllegalStateException * if {@code expression} is false * @throws NullPointerException * if the check fails and either {@code errorMessageTemplate} or * {@code errorMessageArgs} is null (don't let this happen) */ public static void checkState(final boolean expression, final String errorMessageTemplate, final Object... errorMessageArgs) { if (!expression) { throw new IllegalStateException(format(errorMessageTemplate, errorMessageArgs));} }
3.26
cron-utils_Preconditions_checkNotNull_rdh
/** * Ensures that an object reference passed as a parameter to the calling method is not null. * * @param reference * an object reference * @param errorMessage * the exception message to use if the check fails; will be converted to a * string using {@link String#valueOf(Object)} * @return the non-null reference that was validated * @throws NullPointerException * if {@code reference} is null */ @SuppressWarnings("NullPointerException") public static <T> T checkNotNull(final T reference, final Object errorMessage) { if (reference == null) { throw new NullPointerException(String.valueOf(errorMessage)); } return reference; }
3.26
cron-utils_FieldSpecialCharsDefinitionBuilder_withIntMapping_rdh
/** * Defines mapping between integer values with equivalent meaning. * * @param source * - higher value * @param dest * - lower value with equivalent meaning to source * @return this FieldSpecialCharsDefinitionBuilder instance */ @Override public FieldSpecialCharsDefinitionBuilder withIntMapping(final int source, final int dest) { super.withIntMapping(source, dest); return this; }
3.26
cron-utils_FieldSpecialCharsDefinitionBuilder_withValidRange_rdh
/** * Allows to set a range of valid values for field. * * @param startRange * - start range value * @param endRange * - end range value * @return same FieldSpecialCharsDefinitionBuilder instance */ @Override public FieldSpecialCharsDefinitionBuilder withValidRange(final int startRange, final int endRange) { super.withValidRange(startRange, endRange); return this; }
3.26
cron-utils_CronParserField_isOptional_rdh
/** * Returns optional tag. * * @return optional tag */ public final boolean isOptional() { return optional; }
3.26
cron-utils_CronParserField_parse_rdh
/** * Parses a String cron expression. * * @param expression * - cron expression * @return parse result as CronFieldParseResult instance - never null. May throw a RuntimeException if cron expression is bad. */ public CronField parse(final String expression) { String newExpression = expression; if (getField().equals(CronFieldName.DAY_OF_WEEK) && newExpression.endsWith("L")) { Integer value = constraints.getStringMappingValue(newExpression.substring(0, newExpression.length() - 1)); if (value != null) { newExpression = value + "L"; } }return new CronField(field, parser.parse(newExpression), constraints); }
3.26
cron-utils_WeekDay_mapTo_rdh
/** * Maps given WeekDay to representation hold by this instance. * * @param targetWeekDayDefinition * - referred weekDay * @param dayOfWeek * - day of week to be mapped. * Value corresponds to this instance mapping. * @return - int result */ public int mapTo(final int dayOfWeek, final WeekDay targetWeekDayDefinition) { if (firstDayZero && targetWeekDayDefinition.isFirstDayZero()) { return bothSameStartOfRange(0, 6, this, targetWeekDayDefinition).apply(dayOfWeek);} if ((!firstDayZero) && (!targetWeekDayDefinition.isFirstDayZero())) { return bothSameStartOfRange(1, 7, this, targetWeekDayDefinition).apply(dayOfWeek); } // start range is different for each case. We need to normalize ranges if (targetWeekDayDefinition.isFirstDayZero()) { // my range is 1-7. I normalize ranges, get the "zero" mapping and turn result into original scale return mapTo(dayOfWeek, new WeekDay(targetWeekDayDefinition.getMondayDoWValue() + 1, false)) - 1; } else { // my range is 0-6. I normalize ranges, get the "one" mapping and turn result into original scale return (mapTo(dayOfWeek, new WeekDay(targetWeekDayDefinition.getMondayDoWValue() - 1, true)) % 7) + 1; } }
3.26
cron-utils_NominalDescriptionStrategy_addDescription_rdh
/** * Allows to provide a specific description to handle a CronFieldExpression instance. * * @param desc * - function that maps CronFieldExpression to String. * The function should return "" if does not match criteria, * or the description otherwise. * @return NominalDescriptionStrategy, this instance */ public NominalDescriptionStrategy addDescription(final Function<FieldExpression, String> desc) { descriptions.add(desc); return this; }
3.26
cron-utils_StringUtils_isEmpty_rdh
// Empty checks // ----------------------------------------------------------------------- /** * <p>Checks if a CharSequence is empty ("") or null.</p> * * <pre> * StringUtils.isEmpty(null) = true * StringUtils.isEmpty("") = true * StringUtils.isEmpty(" ") = false * StringUtils.isEmpty("bob") = false * StringUtils.isEmpty(" bob ") = false * </pre> * * <p>NOTE: This method changed in Lang version 2.0. * It no longer trims the CharSequence. * That functionality is available in isBlank().</p> * * @param cs * the CharSequence to check, may be null * @return {@code true} if the CharSequence is empty or null * @since 3.0 Changed signature from isEmpty(String) to isEmpty(CharSequence) */ public static boolean isEmpty(final CharSequence cs) { return (cs == null) || (cs.length() == 0); } // ContainsAny // ----------------------------------------------------------------------- /** * <p>Checks if the CharSequence contains any character in the given. * set of characters.</p> * * <p>A {@code null} CharSequence will return {@code false}. * A {@code null} or zero length search array will return {@code false}.</p> * * <pre> * StringUtils.containsAny(null, *) = false * StringUtils.containsAny("", *) = false * StringUtils.containsAny(*, null) = false * StringUtils.containsAny(*, []) = false * StringUtils.containsAny("zzabyycdxx",['z','a']) = true * StringUtils.containsAny("zzabyycdxx",['b','y']) = true * StringUtils.containsAny("aba", ['z']) = false * </pre> * * @param cs * the CharSequence to check, may be null * @param searchChars * the chars to search for, may be null * @return the {@code true} if any of the chars are found, {@code false}
3.26
cron-utils_SecondsDescriptor_createAndDescription_rdh
/** * Creates human readable description for And element. * * @param builder * - StringBuilder instance to which description will be appended * @param expressions * - field expressions * @return same StringBuilder instance as parameter */ @VisibleForTesting StringBuilder createAndDescription(final StringBuilder builder, final List<FieldExpression> expressions) { if ((expressions.size() - 2) >= 0) { for (int j = 0; j < (expressions.size() - 2); j++) { builder.append(String.format(" %s, ", describe(expressions.get(j), true))); } builder.append(String.format(" %s ", describe(expressions.get(expressions.size() - 2), true))); } builder.append(String.format(" %s ", bundle.getString("and"))); builder.append(describe(expressions.get(expressions.size() - 1), true)); return builder; }
3.26
cron-utils_SecondsDescriptor_visit_rdh
/** * Provide a human readable description for Every instance. * * @param every * - Every * @return human readable description - String */ @Override public Every visit(final Every every) { String description; if (every.getPeriod().getValue() > 1) { description = String.format("%s %s ", bundle.getString(EVERY), nominalValue(every.getPeriod())) + " replace_plural "; } else { description = bundle.getString(EVERY) + " %s "; } // TODO save the description? return every; }
3.26
cron-utils_SecondsDescriptor_nominalValue_rdh
/** * Given an int, will return a nominal value. Example: * 1 in weeks context, may mean "Monday", * so nominal value for 1 would be "Monday" * Default will return int as String * * @param fieldValue * - some FieldValue * @return String */ protected String nominalValue(final FieldValue<?> fieldValue) { Preconditions.checkNotNull(fieldValue, "FieldValue must not be null"); if (fieldValue instanceof IntegerFieldValue) { return StringUtils.EMPTY + ((IntegerFieldValue) (fieldValue)).getValue(); } return fieldValue.toString(); }
3.26
cron-utils_SecondsDescriptor_describe_rdh
/** * Provide a human readable description for On instance. * * @param on * - On * @return human readable description - String */ protected String describe(final On on, final boolean and) { if (and) { return nominalValue(on.getTime()); } return String.format("%s %s ", bundle.getString("at"), nominalValue(on.getTime())) + "%s"; }
3.26
cron-utils_CronFieldName_getOrder_rdh
/** * Returns the order number that corresponds to the field. * * @return order number - int */ public int getOrder() { return order; }
3.26
cron-utils_FieldValue_toString_rdh
/** * String representation of encapsulated value. * * @return String, never null */@Override public final String toString() { return String.format("%s", getValue()); }
3.26
cron-utils_RebootCron_equivalent_rdh
/** * Provides means to compare if two cron expressions are equivalent. * * @param cronMapper * - maps 'cron' parameter to this instance definition; * @param cron * - any cron instance, never null * @return boolean - true if equivalent; false otherwise. */ public boolean equivalent(final CronMapper cronMapper, final Cron cron) { return asString().equals(cronMapper.map(cron).asString()); }
3.26
cron-utils_RebootCron_retrieve_rdh
/** * Retrieve value for cron field. * * @param name * - cron field name. * If null, a NullPointerException will be raised. * @return CronField that corresponds to given CronFieldName */ public CronField retrieve(final CronFieldName name) { Preconditions.checkNotNull(name, "CronFieldName must not be null"); return null; }
3.26
cron-utils_RebootCron_validate_rdh
/** * Validates this Cron instance by validating its cron expression. * * @return this Cron instance * @throws IllegalArgumentException * if the cron expression is invalid */ public Cron validate() { for (final Map.Entry<CronFieldName, CronField> field : retrieveFieldsAsMap().entrySet()) { final CronFieldName fieldName = field.getKey(); field.getValue().getExpression().accept(new ValidationFieldExpressionVisitor(getCronDefinition().getFieldDefinition(fieldName).getConstraints())); } for (final CronConstraint constraint : getCronDefinition().getCronConstraints()) { if (!constraint.validate(this)) { throw new IllegalArgumentException(String.format("Invalid cron expression: %s. %s", asString(), constraint.getDescription())); } } return this; }
3.26
cron-utils_RebootCron_m0_rdh
/** * Provides means to compare if two cron expressions are equivalent. * Assumes same cron definition. * * @param cron * - any cron instance, never null * @return boolean - true if equivalent; false otherwise. */ public boolean m0(final Cron cron) { return asString().equals(cron.asString()); }
3.26
cron-utils_FieldDayOfWeekDefinitionBuilder_withValidRange_rdh
/** * Allows to set a range of valid values for field. * * @param startRange * - start range value * @param endRange * - end range value * @return same FieldDayOfWeekDefinitionBuilder instance */ @Override public FieldDayOfWeekDefinitionBuilder withValidRange(final int startRange, final int endRange) { super.withValidRange(startRange, endRange); return this; }
3.26
cron-utils_FieldDayOfWeekDefinitionBuilder_m0_rdh
/** * Registers the field supports the W (W) special char. * * @return this FieldSpecialCharsDefinitionBuilder instance */ public FieldDayOfWeekDefinitionBuilder m0(final int mondayDoW) { constraints.withShiftedStringMapping(mondayDoW - mondayDoWValue); mondayDoWValue = mondayDoW; return this; }
3.26
cron-utils_FieldDayOfWeekDefinitionBuilder_withIntMapping_rdh
/** * Defines mapping between integer values with equivalent meaning. * * @param source * - higher value * @param dest * - lower value with equivalent meaning to source * @return this FieldDayOfWeekDefinitionBuilder instance */ @Override public FieldDayOfWeekDefinitionBuilder withIntMapping(final int source, final int dest) { super.withIntMapping(source, dest); return this; }
3.26
cron-utils_FieldDayOfWeekDefinitionBuilder_and_rdh
/** * Registers CronField in ParserDefinitionBuilder and returns its instance. * * @return ParserDefinitionBuilder instance obtained from constructor */ @Override public CronDefinitionBuilder and() { final boolean zeroInRange = constraints.createConstraintsInstance().isInRange(0); cronDefinitionBuilder.register(new DayOfWeekFieldDefinition(fieldName, constraints.createConstraintsInstance(), optional, new WeekDay(mondayDoWValue, zeroInRange))); return cronDefinitionBuilder; }
3.26
cron-utils_FieldParser_parse_rdh
/** * Parse given expression for a single cron field. * * @param expression * - String * @return CronFieldExpression object that with interpretation of given String parameter */ public FieldExpression parse(final String expression) { if (!StringUtils.containsAny(expression, SPECIAL_CHARS_MINUS_STAR)) { if (expression.contains(QUESTION_MARK_STRING) && (!fieldConstraints.getSpecialChars().contains(QUESTION_MARK))) { throw new IllegalArgumentException("Invalid expression: " + expression); } return noSpecialCharsNorStar(expression); } else { final String[] array = expression.split(","); if (array.length > 1) {return commaSplitResult(array); } else { final String[] splitted = expression.split("-"); if (expression.contains("-") && (splitted.length != 2)) { throw new IllegalArgumentException("Missing values for range: " + expression); } return splitted[0].equalsIgnoreCase(L_STRING) ? parseOnWithL(splitted[0], mapToIntegerFieldValue(splitted[1])) : dashSplitResult(expression, splitted); } } }
3.26
cron-utils_FieldParser_stringToInt_rdh
/** * Maps string expression to integer. If no mapping is found, will try to parse String as Integer * * @param exp * - expression to be mapped * @return integer value for string expression */ @VisibleForTesting protected int stringToInt(final String exp) { final Integer value = fieldConstraints.getStringMappingValue(exp);if (value != null) { return value; } else { try { return Integer.parseInt(exp); } catch (final NumberFormatException e) { final String invalidChars = new StringValidations(fieldConstraints).removeValidChars(exp); throw new IllegalArgumentException(String.format("Invalid chars in expression! Expression: %s Invalid chars: %s", exp, invalidChars)); } } }
3.26
cron-utils_FieldParser_intToInt_rdh
/** * Maps integer values to another integer equivalence. Always consider mapping higher integers to lower once. Ex.: if 0 and 7 mean the * same, map 7 to 0. * * @param exp * - integer to be mapped * @return Mapping integer. If no mapping int is found, will return exp */ @VisibleForTesting protected int intToInt(final Integer exp) { final Integer value = fieldConstraints.getIntMappingValue(exp); if (value != null) { return value; } return exp; }
3.26
cron-utils_FieldConstraintsBuilder_withShiftedStringMapping_rdh
/** * Shifts integer representation of weekday/month names. * * @param shiftSize * - size of the shift * @return same FieldConstraintsBuilder instance */ public FieldConstraintsBuilder withShiftedStringMapping(final int shiftSize) { if ((shiftSize > 0) || (endRange < stringMapping.size())) { for (final Entry<String, Integer> entry : stringMapping.entrySet()) { int value = entry.getValue();value += shiftSize; if (value > endRange) { value -= stringMapping.size(); } else if (value < startRange) { value += startRange - endRange; } stringMapping.put(entry.getKey(), value); } } return this; }
3.26
cron-utils_FieldConstraintsBuilder_withValidRange_rdh
/** * Allows to set a range of valid values for field. * * @param startRange * - start range value * @param endRange * - end range value * @return same FieldConstraintsBuilder instance */ public FieldConstraintsBuilder withValidRange(final int startRange, final int endRange) { this.startRange = startRange; this.endRange = endRange; return this; }
3.26
cron-utils_FieldConstraintsBuilder_daysOfWeekMapping_rdh
/** * Creates days of week mapping. * * @return Map where strings are weekday names in EEE format and integers correspond to their 1-7 mappings */ private static Map<String, Integer> daysOfWeekMapping() { final Map<String, Integer> stringMapping = new HashMap<>(); stringMapping.put("MON", 1); stringMapping.put("TUE", 2); stringMapping.put("WED", 3); stringMapping.put("THU", 4); stringMapping.put("FRI", 5); stringMapping.put("SAT", 6); stringMapping.put("SUN", 7); return stringMapping; }
3.26
cron-utils_FieldConstraintsBuilder_monthsMapping_rdh
/** * Creates months mapping. * * @return Map where strings month names in EEE format, and integers correspond to their 1-12 mappings */ private static Map<String, Integer> monthsMapping() { final Map<String, Integer> stringMapping = new HashMap<>(); stringMapping.put("JAN", 1); stringMapping.put("FEB", 2); stringMapping.put("MAR", 3); stringMapping.put("APR", 4); stringMapping.put("MAY", 5); stringMapping.put("JUN", 6); stringMapping.put("JUL", 7); stringMapping.put("AUG", 8); stringMapping.put("SEP", 9); stringMapping.put("OCT", 10); stringMapping.put("NOV", 11); stringMapping.put("DEC", 12);return stringMapping; }
3.26
cron-utils_FieldConstraintsBuilder_createConstraintsInstance_rdh
/** * Creates FieldConstraints instance based on previously built parameters. * * @return new FieldConstraints instance */ public FieldConstraints createConstraintsInstance() { return new FieldConstraints(stringMapping, intMapping, specialChars, startRange, endRange, strictRange); }
3.26
cron-utils_FieldConstraintsBuilder_withStrictRange_rdh
/** * With strict range. * * @return same FieldConstraintsBuilder instance */ public FieldConstraintsBuilder withStrictRange() { this.strictRange = true; return this; }
3.26
cron-utils_FieldConstraintsBuilder_forField_rdh
/** * Creates range constraints according to CronFieldName parameter. * * @param field * - CronFieldName * @return FieldConstraintsBuilder instance */ public FieldConstraintsBuilder forField(final CronFieldName field) { switch (field) { case SECOND : case MINUTE : endRange = 59; return this; case HOUR : endRange = 23; return this; case DAY_OF_WEEK : stringMapping = daysOfWeekMapping();endRange = 6; return this; case DAY_OF_MONTH : startRange = 1; endRange = 31; return this; case MONTH : stringMapping = monthsMapping(); startRange = 1; endRange = 12; return this; case DAY_OF_YEAR : startRange = 1; endRange = 366;return this; default : return this; } }
3.26
cron-utils_FieldConstraintsBuilder_m0_rdh
/** * Adds LW support. * * @return same FieldConstraintsBuilder instance */ public FieldConstraintsBuilder m0() { specialChars.add(SpecialChar.LW); return this; }
3.26
cron-utils_FieldConstraintsBuilder_withIntValueMapping_rdh
/** * Adds integer to integer mapping. Source should be greater than destination; * * @param source * - some int * @param dest * - some int * @return same FieldConstraintsBuilder instance */ public FieldConstraintsBuilder withIntValueMapping(final int source, final int dest) { intMapping.put(source, dest); return this; }
3.26
cron-utils_FieldConstraintsBuilder_addLSupport_rdh
/** * Adds L support. * * @return same FieldConstraintsBuilder instance */ public FieldConstraintsBuilder addLSupport() { specialChars.add(SpecialChar.L); return this; }
3.26
cron-utils_CronConstraintsFactory_ensureEitherDayOfYearOrMonth_rdh
/** * Creates CronConstraint to ensure that either day-of-year or month is assigned a specific value. * * @return newly created CronConstraint instance, never {@code null}; */ public static CronConstraint ensureEitherDayOfYearOrMonth() { return new CronConstraint("Both, a day-of-year AND a day-of-month or day-of-week, are not supported.") { private static final long serialVersionUID = 520379111876897579L; @Override public boolean validate(Cron cron) { CronField dayOfYearField = cron.retrieve(CronFieldName.DAY_OF_YEAR); if ((dayOfYearField != null) && (!(dayOfYearField.getExpression() instanceof QuestionMark))) { return (cron.retrieve(CronFieldName.DAY_OF_WEEK).getExpression() instanceof QuestionMark) && (cron.retrieve(CronFieldName.DAY_OF_MONTH).getExpression() instanceof QuestionMark); } return true; }}; }
3.26
cron-utils_TimeNode_getValueFromList_rdh
/** * Obtain value from list considering specified index and required shifts. * * @param values * - possible values * @param index * - index to be considered * @param shift * - shifts that should be applied * @return int - required value from values list */ @VisibleForTesting int getValueFromList(final List<Integer> values, int index, final AtomicInteger shift) { Preconditions.checkNotNullNorEmpty(values, "List must not be empty"); if (index < 0) { index = index + values.size(); shift.incrementAndGet(); return getValueFromList(values, index, shift); } if (index >= values.size()) { index = index - values.size(); shift.incrementAndGet();return getValueFromList(values, index, shift); }return values.get(index); }
3.26
cron-utils_TimeNode_getNearestBackwardValue_rdh
/** * We return same reference value if matches or previous one if does not match. * Then we start applying shifts. * This way we ensure same value is returned if no shift is requested. * * @param reference * - reference value * @param shiftsToApply * - shifts to apply * @return NearestValue instance, never null. Holds information on nearest (backward) value and shifts performed. */ @VisibleForTesting NearestValue getNearestBackwardValue(final int reference, int shiftsToApply) { final List<Integer> temporaryValues = new ArrayList<>(this.values); Collections.reverse(temporaryValues); int index = 0;boolean foundSmaller = false; final AtomicInteger shift = new AtomicInteger(0); if (!temporaryValues.contains(reference)) { for (final Integer value : temporaryValues) { if (value < reference) { index = temporaryValues.indexOf(value); shiftsToApply--;// we just moved a position! foundSmaller = true; break; } }if (!foundSmaller) { shift.incrementAndGet(); } } else {index = temporaryValues.indexOf(reference); } int value = temporaryValues.get(index); for (int v13 = 0; v13 < shiftsToApply; v13++) { value = getValueFromList(temporaryValues, index + 1, shift); index = temporaryValues.indexOf(value); } return new NearestValue(value, shift.get()); }
3.26
cron-utils_TimeNode_getNearestForwardValue_rdh
/** * We return same reference value if matches or next one if does not match. * Then we start applying shifts. * This way we ensure same value is returned if no shift is requested. * * @param reference * - reference value * @param shiftsToApply * - shifts to apply * @return NearestValue instance, never null. Holds information on nearest (forward) value and shifts performed. */ @VisibleForTesting NearestValue getNearestForwardValue(final int reference, int shiftsToApply) { final List<Integer> temporaryValues = new ArrayList<>(this.values); int index = 0; boolean foundGreater = false; final AtomicInteger shift = new AtomicInteger(0); if (!temporaryValues.contains(reference)) { for (final Integer value : temporaryValues) { if (value > reference) { index = temporaryValues.indexOf(value); shiftsToApply--;// we just moved a position! foundGreater = true; break; } } if (!foundGreater) { shift.incrementAndGet(); } } else { index = temporaryValues.indexOf(reference); } int value = temporaryValues.get(index); for (int j = 0; j < shiftsToApply; j++) { value = getValueFromList(temporaryValues, index + 1, shift); index = temporaryValues.indexOf(value); } return new NearestValue(value, shift.get()); }
3.26
druid_Lexer_mark_rdh
// 出现多次调用mark()后调用reset()会有问题 @Deprecated public SavePoint mark() { return this.savePoint = markOut(); }
3.26
druid_Lexer_lexError_rdh
/** * Report an error at the given position using the provided arguments. */ protected void lexError(String key, Object... args) { token = ERROR; }
3.26
druid_Lexer_integerValue_rdh
// QS_TODO negative number is invisible for lexer public final Number integerValue() { long result = 0; boolean negative = false; int i = mark; int max = mark + bufPos; long limit; long multmin; int digit; if (charAt(mark) == '-') { negative = true; limit = Long.MIN_VALUE; i++; } else {limit = -Long.MAX_VALUE; } multmin = (negative) ? MULTMIN_RADIX_TEN : N_MULTMAX_RADIX_TEN; if (i < max) { digit = charAt(i++) - '0'; result = -digit; } while (i < max) { // Accumulating negatively avoids surprises near MAX_VALUE digit = charAt(i++) - '0'; if (result < multmin) { return new BigInteger(m3()); } result *= 10; if (result < (limit + digit)) { return new BigInteger(m3()); } result -= digit; } if (negative) { if (i > (mark + 1)) { if (result >= Integer.MIN_VALUE) { return ((int) (result)); } return result; } else { /* Only got "-" */ throw new NumberFormatException(m3()); } } else { result = -result; if (result <= Integer.MAX_VALUE) { return ((int) (result)); } return result; } }
3.26
druid_Lexer_token_rdh
/** * Return the current token, set by nextToken(). */ public final Token.Token token() { return token;}
3.26
druid_Lexer_reset_rdh
// todo fix reset reset字段会导致lexer的游标不对齐 不建议使用 @Deprecated public void reset(int mark, char markChar, Token token) { this.pos = mark; this.ch = markChar; this.token = token; }
3.26
druid_Lexer_putChar_rdh
/** * Append a character to sbuf. */ protected final void putChar(char ch) { if (bufPos == buf.length) { char[] newsbuf = new char[buf.length * 2]; System.arraycopy(buf, 0, newsbuf, 0, buf.length); buf = newsbuf; } buf[bufPos++] = ch; }
3.26
druid_MySqlStatementParser_parseIf_rdh
/** * parse if statement * * @return MySqlIfStatement */ public SQLIfStatement parseIf() { accept(Token.Token.IF); SQLIfStatement stmt = new SQLIfStatement(); stmt.setCondition(this.exprParser.expr()); accept(Token.Token.THEN); this.parseStatementList(stmt.getStatements(), -1, stmt); while (lexer.token() == Token.Token.ELSE) { lexer.nextToken(); if (lexer.token() == Token.Token.IF) { lexer.nextToken(); SQLIfStatement.ElseIf elseIf = new SQLIfStatement.ElseIf(); elseIf.setCondition(this.exprParser.expr()); elseIf.setParent(stmt); accept(Token.Token.THEN); this.parseStatementList(elseIf.getStatements(), -1, elseIf); stmt.getElseIfList().add(elseIf); } else { SQLIfStatement.Else elseItem = new SQLIfStatement.Else(); this.parseStatementList(elseItem.getStatements(), -1, elseItem); stmt.setElseItem(elseItem); break; } } accept(Token.Token.END); accept(Token.Token.IF); accept(Token.Token.SEMI); stmt.setAfterSemi(true); return stmt; }
3.26
druid_MySqlStatementParser_parserParameters_rdh
/** * parse create procedure parameters * * @param parameters */ private void parserParameters(List<SQLParameter> parameters, SQLObject parent) { if (lexer.token() == Token.Token.RPAREN) { return; } for (; ;) { SQLParameter parameter = new SQLParameter(); if (lexer.token() == Token.Token.CURSOR) { lexer.nextToken(); parameter.setName(this.exprParser.name()); accept(Token.Token.IS); SQLSelect select = this.createSQLSelectParser().select(); SQLDataTypeImpl dataType = new SQLDataTypeImpl(); dataType.setName("CURSOR"); parameter.setDataType(dataType); parameter.setDefaultValue(new SQLQueryExpr(select)); } else if (((lexer.token() == Token.Token.IN) || (lexer.token() == Token.Token.OUT)) || (lexer.token() == Token.Token.INOUT)) { if (lexer.token() == Token.Token.IN) { parameter.setParamType(ParameterType.IN); } else if (lexer.token() == Token.Token.OUT) { parameter.setParamType(ParameterType.OUT); } else if (lexer.token() == Token.Token.INOUT) { parameter.setParamType(ParameterType.INOUT); } lexer.nextToken(); parameter.setName(this.exprParser.name()); parameter.setDataType(this.exprParser.parseDataType()); } else { // default parameter type is in parameter.setParamType(ParameterType.DEFAULT); parameter.setName(this.exprParser.name()); parameter.setDataType(this.exprParser.parseDataType()); if (lexer.token() == Token.Token.COLONEQ) { lexer.nextToken(); parameter.setDefaultValue(this.exprParser.expr()); } }parameters.add(parameter); if ((lexer.token() == Token.Token.COMMA) || (lexer.token() == Token.Token.SEMI)) { lexer.nextToken(); } if ((lexer.token() != Token.Token.BEGIN) && (lexer.token() != Token.Token.RPAREN)) { continue; } break; } }
3.26
druid_MySqlStatementParser_parseRepeat_rdh
/** * parse repeat statement with label * * @param label */ public MySqlRepeatStatement parseRepeat(String label) { MySqlRepeatStatement repeatStmt = new MySqlRepeatStatement();repeatStmt.setLabelName(label); accept(Token.Token.REPEAT); this.parseStatementList(repeatStmt.getStatements(), -1, repeatStmt); accept(Token.Token.UNTIL); repeatStmt.setCondition(exprParser.expr()); accept(Token.Token.END); accept(Token.Token.REPEAT); acceptIdentifier(label); accept(Token.Token.SEMI);return repeatStmt; }
3.26
druid_MySqlStatementParser_parseCursorDeclare_rdh
/** * parse cursor declare statement */ public MySqlCursorDeclareStatement parseCursorDeclare() { MySqlCursorDeclareStatement stmt = new MySqlCursorDeclareStatement(); accept(Token.Token.DECLARE); stmt.setCursorName(exprParser.name()); accept(Token.Token.CURSOR); accept(Token.Token.FOR); // SQLSelectStatement selelctStmt = (SQLSelectStatement) parseSelect(); SQLSelect select = this.createSQLSelectParser().select(); stmt.setSelect(select); accept(Token.Token.SEMI); return stmt; }
3.26
druid_MySqlStatementParser_parseDeclareCondition_rdh
/** * zhujun [[email protected]] * 2016-04-17 * 定义条件 */ public MySqlDeclareConditionStatement parseDeclareCondition() { MySqlDeclareConditionStatement stmt = new MySqlDeclareConditionStatement(); accept(Token.Token.DECLARE); stmt.setConditionName(exprParser.name().toString()); accept(Token.Token.CONDITION); accept(Token.Token.FOR); String tokenName = lexer.stringVal(); ConditionValue v761 = new ConditionValue(); if (tokenName.equalsIgnoreCase("SQLSTATE")) { // for SQLSTATE (SQLSTATE '10001') v761.setType(ConditionType.SQLSTATE); lexer.nextToken(); v761.setValue(exprParser.name().toString()); } else if (lexer.token() == Token.Token.LITERAL_INT) { v761.setType(ConditionType.MYSQL_ERROR_CODE); v761.setValue(lexer.integerValue().toString()); lexer.nextToken(); } else { throw new ParserException("declare condition grammer error. " + lexer.info()); } stmt.setConditionValue(v761); accept(Token.Token.SEMI);return stmt; }
3.26
druid_MySqlStatementParser_parseProcedureStatementList_rdh
/** * parse procedure statement block */ private void parseProcedureStatementList(List<SQLStatement> statementList, int max) { for (; ;) { if (max != (-1)) { if (statementList.size() >= max) { return; } } if (lexer.token() == Token.Token.EOF) { return; } if (lexer.token() == Token.Token.END) { return; } if (lexer.token() == Token.Token.ELSE) { return; } if (lexer.token() == Token.Token.SEMI) { lexer.nextToken(); continue; } if (lexer.token() == Token.Token.WHEN) {return; } if (lexer.token() == Token.Token.UNTIL) { return;} // select into if (lexer.token() == Token.Token.SELECT) { statementList.add(this.parseSelectInto()); continue; } // update if (lexer.token() == Token.Token.UPDATE) { statementList.add(parseUpdateStatement()); continue; } // create if (lexer.token() == Token.Token.CREATE) { statementList.add(parseCreate()); continue; } // insert if (lexer.token() == Token.Token.INSERT) { SQLStatement stmt = parseInsert(); statementList.add(stmt); continue; } // delete if (lexer.token() == Token.Token.DELETE) { statementList.add(parseDeleteStatement()); continue; } // call if ((lexer.token() == Token.Token.LBRACE) || lexer.identifierEquals("CALL")) { statementList.add(this.parseCall()); continue; } // begin if (lexer.token() == Token.Token.BEGIN) { statementList.add(this.parseBlock()); continue; }if (lexer.token() == Token.Token.VARIANT) { SQLExpr variant = this.exprParser.primary(); if (variant instanceof SQLBinaryOpExpr) { SQLBinaryOpExpr binaryOpExpr = ((SQLBinaryOpExpr) (variant)); if (binaryOpExpr.getOperator() == SQLBinaryOperator.Assignment) { SQLSetStatement stmt = new SQLSetStatement(binaryOpExpr.getLeft(), binaryOpExpr.getRight(), getDbType()); statementList.add(stmt); continue; } } accept(Token.Token.COLONEQ); SQLExpr value = this.exprParser.expr(); SQLSetStatement stmt = new SQLSetStatement(variant, value, getDbType()); statementList.add(stmt); continue; } // select if (lexer.token() == Token.Token.LPAREN) { Lexer.SavePoint savePoint = lexer.markOut(); lexer.nextToken(); if (lexer.token() == Token.Token.SELECT) { lexer.reset(savePoint); statementList.add(this.parseSelect()); continue;} else { throw new ParserException("TODO. " + lexer.info()); } } // assign statement if (lexer.token() == Token.Token.SET) { statementList.add(this.parseAssign()); continue; } // while statement if (lexer.token() == Token.Token.WHILE) { SQLStatement stmt = this.parseWhile(); statementList.add(stmt); continue; } // loop statement if (lexer.token() == Token.Token.LOOP) { statementList.add(this.parseLoop()); continue;} // if statement if (lexer.token() == Token.Token.IF) { statementList.add(this.parseIf()); continue; } // case statement if (lexer.token() == Token.Token.CASE) { statementList.add(this.parseCase()); continue; } // declare statement if (lexer.token() == Token.Token.DECLARE) { SQLStatement stmt = this.parseDeclare(); statementList.add(stmt); continue; } // leave statement if (lexer.token() == Token.Token.LEAVE) { statementList.add(this.parseLeave()); continue; } // iterate statement if (lexer.token() == Token.Token.ITERATE) { statementList.add(this.parseIterate()); continue; } // repeat statement if (lexer.token() == Token.Token.REPEAT) { statementList.add(this.parseRepeat()); continue; } // open cursor if (lexer.token() == Token.Token.OPEN) { statementList.add(this.parseOpen()); continue; } // close cursor if (lexer.token() == Token.Token.CLOSE) { statementList.add(this.parseClose()); continue; } // fetch cursor into if (lexer.token() == Token.Token.FETCH) { statementList.add(this.parseFetch()); continue; } if (lexer.identifierEquals(Constants.CHECKSUM)) { statementList.add(this.parseChecksum()); continue; } if (lexer.token() == Token.Token.IDENTIFIER) { String label = lexer.stringVal();Lexer.SavePoint savePoint = lexer.markOut(); lexer.nextToken(); if ((lexer.token() == Token.Token.VARIANT) && lexer.stringVal().equals(":")) { lexer.nextToken(); if (lexer.token() == Token.Token.LOOP) { // parse loop statement statementList.add(this.parseLoop(label)); } else if (lexer.token() == Token.Token.WHILE) { // parse while statement with label statementList.add(this.parseWhile(label)); } else if (lexer.token() == Token.Token.BEGIN) { // parse begin-end statement with label statementList.add(this.parseBlock(label)); } else if (lexer.token() == Token.Token.REPEAT) { // parse repeat statement with label statementList.add(this.parseRepeat(label)); } continue; } else { lexer.reset(savePoint); } } throw new ParserException("TODO, " + lexer.info()); } }
3.26
druid_MySqlStatementParser_parseSpStatement_rdh
/** * zhujun [[email protected]] * parse spstatement */ public SQLStatement parseSpStatement() { // update if (lexer.token() == Token.Token.UPDATE) { return parseUpdateStatement(); } // create if (lexer.token() == Token.Token.CREATE) { return parseCreate(); } // insert if (lexer.token() == Token.Token.INSERT) { return parseInsert(); } // delete if (lexer.token() == Token.Token.DELETE) { return parseDeleteStatement(); } // begin if (lexer.token() == Token.Token.BEGIN) { return this.parseBlock(); } // select if (lexer.token() == Token.Token.LPAREN) { Lexer.SavePoint savePoint = lexer.markOut(); lexer.nextToken(); if (lexer.token() == Token.Token.SELECT) { lexer.reset(savePoint); return this.parseSelect(); } else { throw new ParserException("TODO. " + lexer.info()); } } // assign statement if (lexer.token() == Token.Token.SET) { return parseAssign(); } throw new ParserException("error sp_statement. " + lexer.info()); }
3.26
druid_MySqlStatementParser_parseWhile_rdh
/** * parse while statement with label * * @return MySqlWhileStatement */ public SQLWhileStatement parseWhile(String label) { accept(Token.Token.WHILE); SQLWhileStatement stmt = new SQLWhileStatement(); stmt.setLabelName(label); stmt.setCondition(this.exprParser.expr()); accept(Token.Token.DO); this.parseStatementList(stmt.getStatements(), -1, stmt); accept(Token.Token.END); accept(Token.Token.WHILE); acceptIdentifier(label); accept(Token.Token.SEMI); stmt.setAfterSemi(true); return stmt; }
3.26
druid_MySqlStatementParser_parseBlock_rdh
/** * parse loop statement with label */ public SQLBlockStatement parseBlock(String label) { SQLBlockStatement block = new SQLBlockStatement(); block.setLabelName(label); accept(Token.Token.BEGIN); this.parseStatementList(block.getStatementList(), -1, block); accept(Token.Token.END); acceptIdentifier(label); return block; }
3.26
druid_MySqlStatementParser_parseCase_rdh
/** * parse case statement * * @return MySqlCaseStatement */ public MySqlCaseStatement parseCase() { MySqlCaseStatement stmt = new MySqlCaseStatement(); accept(Token.Token.CASE); // grammar 1 if (lexer.token() == Token.Token.WHEN) { while (lexer.token() == Token.Token.WHEN) { MySqlWhenStatement when = new MySqlWhenStatement(); accept(Token.Token.WHEN); // when expr when.setCondition(exprParser.expr()); accept(Token.Token.THEN); // when block this.parseStatementList(when.getStatements(), -1, when); stmt.addWhenStatement(when); } if (lexer.token() == Token.Token.ELSE) { // parse else block SQLIfStatement.Else elseStmt = new SQLIfStatement.Else(); this.parseStatementList(elseStmt.getStatements(), -1, elseStmt); stmt.setElseItem(elseStmt); } } else { // case expr stmt.setCondition(exprParser.expr()); while (lexer.token() == Token.Token.WHEN) { accept(Token.Token.WHEN); MySqlWhenStatement when = new MySqlWhenStatement(); // when expr when.setCondition(exprParser.expr()); accept(Token.Token.THEN); // when block this.parseStatementList(when.getStatements(), -1, when); stmt.addWhenStatement(when); } if (lexer.token() == Token.Token.ELSE) { accept(Token.Token.ELSE); // else block SQLIfStatement.Else elseStmt = new SQLIfStatement.Else(); this.parseStatementList(elseStmt.getStatements(), -1, elseStmt); stmt.setElseItem(elseStmt); } } accept(Token.Token.END); accept(Token.Token.CASE); accept(Token.Token.SEMI); return stmt; }
3.26
druid_MySqlStatementParser_parseLeave_rdh
/** * parse leave statement */ public MySqlLeaveStatement parseLeave() { accept(Token.Token.LEAVE); MySqlLeaveStatement leaveStmt = new MySqlLeaveStatement(); leaveStmt.setLabelName(exprParser.name().getSimpleName()); accept(Token.Token.SEMI); return leaveStmt; }
3.26
druid_MySqlStatementParser_parseAssign_rdh
/** * parse assign statement */ public SQLSetStatement parseAssign() { accept(Token.Token.SET); SQLSetStatement stmt = new SQLSetStatement(getDbType()); parseAssignItems(stmt.getItems(), stmt); return stmt; }
3.26
druid_MySqlStatementParser_parseCreateProcedure_rdh
/** * parse create procedure statement */ public SQLCreateProcedureStatement parseCreateProcedure() { /** * CREATE OR REPALCE PROCEDURE SP_NAME(parameter_list) BEGIN block_statement END */ SQLCreateProcedureStatement stmt = new SQLCreateProcedureStatement(); stmt.setDbType(dbType); if (lexer.token() == Token.Token.CREATE) { lexer.nextToken(); if (lexer.token() == Token.Token.OR) { lexer.nextToken(); accept(Token.Token.REPLACE); stmt.setOrReplace(true); } } if (lexer.identifierEquals(Constants.DEFINER)) { lexer.nextToken(); accept(Token.Token.EQ); SQLName definer = this.m5().userName(); stmt.setDefiner(definer); } accept(Token.Token.PROCEDURE); stmt.setName(this.exprParser.name()); if (lexer.token() == Token.Token.LPAREN) { lexer.nextToken(); parserParameters(stmt.getParameters(), stmt); accept(Token.Token.RPAREN); } for (; ;) { if (lexer.token() == Token.Token.COMMENT) { lexer.nextToken(); stmt.setComment(this.exprParser.charExpr()); } if (lexer.identifierEquals(Constants.LANGUAGE)) { lexer.nextToken(); acceptIdentifier("SQL"); stmt.setLanguageSql(true); } if (lexer.identifierEquals(Constants.DETERMINISTIC)) { lexer.nextToken();stmt.setDeterministic(true); continue; } if (lexer.identifierEquals(Constants.CONTAINS) || (lexer.token() == Token.Token.CONTAINS)) { lexer.nextToken(); acceptIdentifier("SQL"); stmt.setContainsSql(true); continue; }if (lexer.identifierEquals(Constants.SQL)) { lexer.nextToken(); acceptIdentifier("SECURITY"); SQLName authid = this.exprParser.name(); stmt.setAuthid(authid); } break; } SQLStatement block; if (lexer.token() == Token.Token.BEGIN) { block = this.parseBlock(); } else { block = this.parseStatement(); } stmt.setBlock(block); return stmt; }
3.26
druid_MySqlStatementParser_parseLoop_rdh
/** * parse loop statement with label */ public SQLLoopStatement parseLoop(String label) { SQLLoopStatement loopStmt = new SQLLoopStatement(); loopStmt.setLabelName(label); accept(Token.Token.LOOP); this.parseStatementList(loopStmt.getStatements(), -1, loopStmt); accept(Token.Token.END); accept(Token.Token.LOOP); if (lexer.token() != Token.Token.SEMI) { acceptIdentifier(label); } accept(Token.Token.SEMI); loopStmt.setAfterSemi(true); return loopStmt; }
3.26
druid_MySqlStatementParser_parseIterate_rdh
/** * parse iterate statement */ public MySqlIterateStatement parseIterate() { accept(Token.Token.ITERATE); MySqlIterateStatement iterateStmt = new MySqlIterateStatement(); iterateStmt.setLabelName(exprParser.name().getSimpleName()); accept(Token.Token.SEMI); return iterateStmt; }
3.26
druid_MySqlStatementParser_parseDeclare_rdh
/** * parse declare statement */public SQLStatement parseDeclare() { Lexer.SavePoint savePoint = lexer.markOut(); lexer.nextToken(); if (lexer.token() == Token.Token.CONTINUE) { lexer.reset(savePoint); return this.parseDeclareHandler(); } lexer.nextToken();if (lexer.token() == Token.Token.CURSOR) { lexer.reset(savePoint); return this.parseCursorDeclare(); } else if (lexer.identifierEquals("HANDLER")) { // DECLARE异常处理程序 [add by zhujun 2016-04-16] lexer.reset(savePoint); return this.parseDeclareHandler(); } else if (lexer.token() == Token.Token.CONDITION) { // DECLARE异常 [add by zhujun 2016-04-17] lexer.reset(savePoint); return this.parseDeclareCondition(); } else { lexer.reset(savePoint); }MySqlDeclareStatement stmt = new MySqlDeclareStatement(); accept(Token.Token.DECLARE); // lexer.nextToken(); for (; ;) { SQLDeclareItem item = new SQLDeclareItem(); item.setName(exprParser.name()); stmt.addVar(item); if (lexer.token() == Token.Token.COMMA) { lexer.nextToken(); stmt.setAfterSemi(true); continue; } else if (lexer.token() != Token.Token.EOF) { // var type item.setDataType(exprParser.parseDataType()); if (lexer.token() == Token.Token.DEFAULT) {lexer.nextToken(); SQLExpr defaultValue = this.exprParser.primary(); item.setValue(defaultValue); } break; } else { throw new ParserException("TODO. " + lexer.info()); } } return stmt; }
3.26
druid_MySqlStatementParser_parseSelectInto_rdh
/** * parse select into */ public MySqlSelectIntoStatement parseSelectInto() { MySqlSelectIntoParser parse = new MySqlSelectIntoParser(this.exprParser); return parse.parseSelectInto(); }
3.26
druid_NameResolveVisitor_isAliasColumn_rdh
/** * 是否是 select item 字段的别名 * * @param x * x 是否是 select item 字段的别名 * @param source * 从 source 数据中查找 and 判断 * @return true:是、false:不是 */ public boolean isAliasColumn(SQLExpr x, SQLSelectQueryBlock source) { if (x instanceof SQLIdentifierExpr) { SQLIdentifierExpr identifierExpr = ((SQLIdentifierExpr) (x)); long nameHashCode64 = identifierExpr.nameHashCode64(); SQLSelectQueryBlock queryBlock = source; SQLSelectItem selectItem = queryBlock.findSelectItem(nameHashCode64); if (selectItem != null) { return true; } if ((queryBlock.getFrom() instanceof SQLSubqueryTableSource) && (((SQLSubqueryTableSource) (queryBlock.getFrom())).getSelect().getQuery() instanceof SQLSelectQueryBlock)) { SQLSelectQueryBlock subQueryBlock = ((SQLSubqueryTableSource) (queryBlock.getFrom())).getSelect().getQueryBlock(); if (isAliasColumn(x, subQueryBlock)) { return true; } } } return false; }
3.26
druid_NameResolveVisitor_isRowNumColumn_rdh
/** * 是否是 rownum 或者 rownum 别名 * * @param x * x 是否是 rownum 或者 rownum 别名 * @param source * 从 source 数据中查找 and 判断 * @return true:是、false:不是 */ public boolean isRowNumColumn(SQLExpr x, SQLSelectQueryBlock source) { if (x instanceof SQLIdentifierExpr) { SQLIdentifierExpr identifierExpr = ((SQLIdentifierExpr) (x)); long nameHashCode64 = identifierExpr.nameHashCode64(); if (nameHashCode64 == Constants.ROWNUM) { return true; } SQLSelectQueryBlock queryBlock = source; if ((queryBlock.getFrom() instanceof SQLSubqueryTableSource) && (((SQLSubqueryTableSource) (queryBlock.getFrom())).getSelect().getQuery() instanceof SQLSelectQueryBlock)) { SQLSelectQueryBlock subQueryBlock = ((SQLSubqueryTableSource) (queryBlock.getFrom())).getSelect().getQueryBlock(); SQLSelectItem selectItem = subQueryBlock.findSelectItem(nameHashCode64); if ((selectItem != null) && isRowNumColumn(selectItem.getExpr(), subQueryBlock)) { return true; } }} return false; }
3.26