use of com.cronutils.utils.VisibleForTesting in project cron-utils by jmrozanec.
the class TimeNode method getNearestForwardValue.
/**
* 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);
// we just moved a position!
shiftsToApply--;
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());
}
use of com.cronutils.utils.VisibleForTesting in project cron-utils by jmrozanec.
the class FieldParser method parseOnWithLW.
@VisibleForTesting
protected On parseOnWithLW(final String exp) {
final SpecialCharFieldValue specialChar = new SpecialCharFieldValue(LW);
final String lwExpression = exp.replace(LW_STRING, EMPTY_STRING);
if (EMPTY_STRING.equals(lwExpression)) {
return new On(new IntegerFieldValue(-1), specialChar, new IntegerFieldValue(-1));
} else {
throw new IllegalArgumentException(String.format("Expected: LW, found: %s", lwExpression));
}
}
use of com.cronutils.utils.VisibleForTesting in project cron-utils by jmrozanec.
the class CronBuilder method addField.
@VisibleForTesting
CronBuilder addField(final CronFieldName name, final FieldExpression expression) {
checkState(definition != null, "CronBuilder not initialized.");
final FieldDefinition fieldDefinition = definition.getFieldDefinition(name);
checkState(fieldDefinition != null, "Cron field definition does not exist: %s", name);
final FieldConstraints constraints = fieldDefinition.getConstraints();
expression.accept(new ValidationFieldExpressionVisitor(constraints));
fields.put(name, new CronField(name, expression, constraints));
return this;
}
Aggregations