kz.greetgo.scheduling.exceptions.ScheduledParseException Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of greetgo.scheduling Show documentation
Show all versions of greetgo.scheduling Show documentation
Scheduler using in greetgo!
The newest version!
package kz.greetgo.scheduling.exceptions;
import kz.greetgo.scheduling.trigger.TriggerParseError;
import java.util.List;
import java.util.Optional;
import static kz.greetgo.scheduling.util.StrUtil.mul;
public class ScheduledParseException extends RuntimeException {
public ScheduledParseException(String message) {
super(message);
}
public static Optional exception(List errors) {
return generateErrorMessage(errors).map(ScheduledParseException::new);
}
public static void check(List errors) {
generateErrorMessage(errors)
.map(ScheduledParseException::new)
.ifPresent(e -> { throw e; });
}
public static Optional generateErrorMessage(List errors) {
if (errors.isEmpty()) {
return Optional.empty();
}
StringBuilder sb = new StringBuilder();
sb.append("\n");
for (TriggerParseError error : errors) {
sb.append("Ошибка : ").append(error.errorCode()).append(" ").append(error.errorMessage()).append("\n");
sb.append(" Строка: ").append(error.triggerString()).append("\n");
String s1 = mul(" ", error.errorPlace().from);
String s2 = mul("¯", error.errorPlace().to - error.errorPlace().from);//"‾¯"
sb.append(" ").append(s1).append(s2).append("\n");
}
return Optional.of(sb.toString());
}
}