/** * 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 the color text is written in the short form with alpha. The text * would have to look like this: {@code #rgba} * * @param toCheck the text to check * @return {@code true} in case the text is a short form color definition * with alpha */ public static boolean isShortMode(@Nullable final String toCheck) { return isColor(toCheck, 4); }
public static boolean check(final String color) { if (ColorValidator.isShortModeWithoutAlpha(color) || ColorValidator.isLongModeWithoutAlpha(color) || ColorValidator.isValid(color)) { return true; } return false; }
/** * Returns true when the given string is from format: #ffff and false when #ffffffff. * * @param color the color string * @return true or false */ private boolean isShortMode(final String color) { return ColorValidator.isShortMode(color) || ColorValidator.isShortModeWithoutAlpha(color); }
public void fromString(@Nonnull final String color) { colorString = color; if (ColorValidator.isShortModeWithoutAlpha(color)) { red = getRFromString(color); green = getGFromString(color); "value of [#f]"); } else if (ColorValidator.isLongModeWithoutAlpha(color)) { red = getRFromString(color); green = getGFromString(color); "value of [#ff]"); } else if (ColorValidator.isValid(color)) { red = getRFromString(color); green = getGFromString(color);
/** * Check if the color text is written in the short form without alpha. The * text would have to look like this: {@code #rgb} * * @param toCheck the text to check * @return {@code true} in case the text is a short form color definition * without alpha */ public static boolean isShortModeWithoutAlpha(@Nullable final String toCheck) { return isColor(toCheck, 3); }
/** * 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; }
public void fromStringWithoutAlpha(@Nonnull final String color) { colorString = color + toHex(alpha); if (ColorValidator.isShortModeWithoutAlpha(color)) { red = getRFromString(color); green = getGFromString(color); blue = getBFromString(color); } else if (ColorValidator.isLongModeWithoutAlpha(color)) { red = getRFromString(color); green = getGFromString(color); blue = getBFromString(color); } else if (ColorValidator.isValid(color)) { red = getRFromString(color); green = getGFromString(color); blue = getBFromString(color); } else { red = green = blue = 1.0f; } }
/** * Check if the color text is written in the long form with alpha. The text * would have to look like this: {@code #rrggbbaa} * * @param toCheck the text to check * @return {@code true} in case the text is a long form color definition * with alpha */ public static boolean isLongMode(@Nullable final String toCheck) { return isColor(toCheck, 8); }
/** * Check if the color text is written in the long form without alpha. The text * would have to look like this: {@code #rrggbb} * * @param toCheck the text to check * @return {@code true} in case the text is a long form color definition * without alpha */ public static boolean isLongModeWithoutAlpha(@Nullable final String toCheck) { return isColor(toCheck, 6); }