/** * Test of a text contains a color definition with a specified amount of color * digits. * * @param toCheck the text to check * @param components the amount of digits to be used to define the color * @return {@code true} if the text fits a color text and meets the * required length exactly */ private static boolean isColor(@Nullable final String toCheck, final int components) { return (toCheck != null && toCheck.length() == (components + 1) && checkSyntax(toCheck)); }
/** * Check if a string fits any type of color definition string. * * @param toCheck the text to check * @return {@code true} in case the text is a color definition */ public static boolean isValid(@Nullable final String toCheck) { if (toCheck == null) { return false; } if (!toCheck.startsWith("#")) { return false; } final int digits = toCheck.length() - 1; if (digits == 3 || digits == 4 || digits == 6 || digits == 8) { return checkSyntax(toCheck); } return false; }