use of com.cronutils.utils.VisibleForTesting in project cron-utils by jmrozanec.
the class TimeNode method getNearestBackwardValue.
/**
* 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);
// we just moved a position!
shiftsToApply--;
foundSmaller = true;
break;
}
}
if (!foundSmaller) {
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 parseOnWithQuestionMark.
@VisibleForTesting
protected On parseOnWithQuestionMark(final String exp) {
final SpecialCharFieldValue specialChar = new SpecialCharFieldValue(QUESTION_MARK);
final String questionMarkExpression = exp.replace(QUESTION_MARK_STRING, EMPTY_STRING);
if (EMPTY_STRING.equals(questionMarkExpression)) {
return new On(new IntegerFieldValue(-1), specialChar, new IntegerFieldValue(-1));
} else {
throw new IllegalArgumentException(String.format("Expected: '?', found: %s", questionMarkExpression));
}
}
use of com.cronutils.utils.VisibleForTesting in project cron-utils by jmrozanec.
the class FieldParser method parseOnWithHash.
@VisibleForTesting
protected On parseOnWithHash(final String exp) {
if (!fieldConstraints.getSpecialChars().contains(HASH)) {
throw new IllegalArgumentException("Invalid expression: " + exp);
}
final SpecialCharFieldValue specialChar = new SpecialCharFieldValue(HASH);
final String[] array = exp.split(HASH_TAG);
if (array.length == 0) {
throw new IllegalArgumentException("Invalid Position of # Character!");
}
final IntegerFieldValue nth = mapToIntegerFieldValue(array[1]);
if (array[0].isEmpty()) {
throw new IllegalArgumentException("Time should be specified!");
}
return new On(mapToIntegerFieldValue(array[0]), specialChar, nth);
}
use of com.cronutils.utils.VisibleForTesting in project cron-utils by jmrozanec.
the class StringValidations method removeValidChars.
@VisibleForTesting
public String removeValidChars(final String exp) {
final Matcher numsAndCharsMatcher = NUMS_AND_CHARS_PATTERN.matcher(exp.toUpperCase());
final Matcher stringToIntKeysMatcher = stringToIntKeysPattern.matcher(numsAndCharsMatcher.replaceAll(""));
final Matcher specialWordsMatcher = lwPattern.matcher(stringToIntKeysMatcher.replaceAll(""));
return specialWordsMatcher.replaceAll("").replaceAll("\\s+", "").replaceAll(",", "").replaceAll("-", "");
}
use of com.cronutils.utils.VisibleForTesting in project job-scheduler by opensearch-project.
the class LockService method createLockIndex.
@VisibleForTesting
void createLockIndex(ActionListener<Boolean> listener) {
if (lockIndexExist()) {
listener.onResponse(true);
} else {
final CreateIndexRequest request = new CreateIndexRequest(LOCK_INDEX_NAME).mapping(lockMapping());
client.admin().indices().create(request, ActionListener.wrap(response -> listener.onResponse(response.isAcknowledged()), exception -> {
if (exception instanceof ResourceAlreadyExistsException || exception.getCause() instanceof ResourceAlreadyExistsException) {
listener.onResponse(true);
} else {
listener.onFailure(exception);
}
}));
}
}
Aggregations