/** * Returns the higher of the given severities by comparing their ordinals. * Since the higher severities have a lower ordinal, this method returns * the severity with the lower ordinal. * * @param severity1 the first severity to check * @param severity2 the second severity to check * @return the higher of the given severities */ public static Severity max(Severity severity1, Severity severity2) { return severity1.ordinal() < severity2.ordinal() ? severity1 : severity2; }
/** * Returns the higher of the given severities by comparing their ordinals. * Since the higher severities have a lower ordinal, this method returns * the severity with the lower ordinal. * * @param severity1 the first severity to check * @param severity2 the second severity to check * @return the higher of the given severities */ public static Severity max(Severity severity1, Severity severity2) { return severity1.ordinal() < severity2.ordinal() ? severity1 : severity2; }
/** * Returns the highest severity of this result's messages, * {@code Severity.OK} if there are no messages. * A single validation message can have only the severity * error or warning. Hence, this method returns the error severity * if there's at least one error message; and it returns * the warning severity, otherwise - assuming that there are * no other severities.<p> * * @param messages the List of ValidationMessages to check * @return the highest severity of this result's messages, * {@code Severity.OK} if there are no messages */ private static Severity getSeverity(List<ValidationMessage> messages) { Severity severity = Severity.OK; for (ValidationMessage message : messages) { severity = Severity.max(severity, message.severity()); if (severity.ordinal() == 0) { // we found the maximum severity. break; } } return severity; }