Class CheckerColor
- All Implemented Interfaces:
InterfaceChecker<AbstractChecker<Color,
CheckerColor>, Color>
CheckerColor is a specialized checker for validating and performing assertions on
Color
values.
It provides a fluent API for common color validations such as checking color equality, brightness, transparency, contrast, and more.
-
Field Summary
Fields inherited from class util.AbstractChecker
backObject, exceptionTracker, name, object, saveErrors, stop
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
CheckerColor
(Color color, String name) Constructs a newCheckerColor
with the specified color and name. -
Method Summary
Modifier and TypeMethodDescriptionstatic CheckerColor
Creates a new CheckerColor instance for the given color with a default name.static CheckerColor
Creates a new CheckerColor instance for the given color and name.hasAlpha
(int alpha) Checks if the color has the specified alpha (transparency) value.hasContrast
(Color other) Checks if the color has sufficient contrast with another color using the default threshold (128).hasContrast
(Color other, double umbral) Checks if the color has sufficient contrast with another color using the specified threshold.hasHexadecimal
(String hex) Checks if the color's hexadecimal representation matches the specified string.isBlack()
Checks if the color is black.Checks if the color is equal to another color.isDark()
Checks if the color is considered dark using the default threshold (128).isDark
(double umbral) Checks if the color is considered dark using the specified threshold.isDesaturated
(double umbral) Checks if the color is desaturated (saturation below the specified threshold).isGray()
Checks if the color is a shade of gray (red, green, and blue components are equal).isLight()
Checks if the color is considered light using the default threshold (128).isLight
(double umbral) Checks if the color is considered light using the specified threshold.isOpaque()
Checks if the color is fully opaque (alpha value is 255).Checks if the color is similar to another color within the specified threshold.Checks if the color is transparent (alpha value less than 255).isWhite()
Checks if the color is white.protected CheckerColor
self()
Returns this instance (for fluent API usage).Methods inherited from class util.AbstractChecker
checkProperty, checkProperty, checkProperty, end, getMethod, getObject, getProperty, hasErrors, hasNotErrors, is, is, isEqual, isNonNull, isNot, isNot, isNull, notSaveErrors, saveErrors, show, showNotThrownException, showThrownException, stop
-
Constructor Details
-
CheckerColor
-
-
Method Details
-
check
Creates a new CheckerColor instance for the given color and name.- Parameters:
color
- the color value to be checkedname
- the name to identify the color in error messages- Returns:
- a CheckerColor instance for further validations
-
check
Creates a new CheckerColor instance for the given color with a default name.- Parameters:
color
- the color value to be checked- Returns:
- a CheckerColor instance for further validations
-
self
Returns this instance (for fluent API usage).- Specified by:
self
in classAbstractChecker<Color,
CheckerColor> - Returns:
- this CheckerColor instance
-
isBlack
Checks if the color is black.- Returns:
- this CheckerColor instance for chaining
-
isWhite
Checks if the color is white.- Returns:
- this CheckerColor instance for chaining
-
isGray
Checks if the color is a shade of gray (red, green, and blue components are equal).- Returns:
- this CheckerColor instance for chaining
-
isColor
Checks if the color is equal to another color.- Parameters:
other
- the color to compare with- Returns:
- this CheckerColor instance for chaining
-
isDark
Checks if the color is considered dark using the default threshold (128).- Returns:
- this CheckerColor instance for chaining
-
isDark
Checks if the color is considered dark using the specified threshold.- Parameters:
umbral
- the threshold for darkness (lower value means darker)- Returns:
- this CheckerColor instance for chaining
-
isLight
Checks if the color is considered light using the default threshold (128).- Returns:
- this CheckerColor instance for chaining
-
isLight
Checks if the color is considered light using the specified threshold.- Parameters:
umbral
- the threshold for lightness (higher value means lighter)- Returns:
- this CheckerColor instance for chaining
-
isTransparent
Checks if the color is transparent (alpha value less than 255).- Returns:
- this CheckerColor instance for chaining
-
hasContrast
Checks if the color has sufficient contrast with another color using the default threshold (128).- Parameters:
other
- the color to compare contrast with- Returns:
- this CheckerColor instance for chaining
-
hasContrast
Checks if the color has sufficient contrast with another color using the specified threshold.- Parameters:
other
- the color to compare contrast withumbral
- the threshold for contrast difference- Returns:
- this CheckerColor instance for chaining
-
hasAlpha
Checks if the color has the specified alpha (transparency) value.- Parameters:
alpha
- the expected alpha value- Returns:
- this CheckerColor instance for chaining
-
isDesaturated
Checks if the color is desaturated (saturation below the specified threshold).- Parameters:
umbral
- the threshold for saturation (0 = grayscale, 1 = fully saturated)- Returns:
- this CheckerColor instance for chaining
-
isSimilar
Checks if the color is similar to another color within the specified threshold.- Parameters:
other
- the color to compare withumbral
- the maximum allowed distance for similarity- Returns:
- this CheckerColor instance for chaining
-
isOpaque
Checks if the color is fully opaque (alpha value is 255).- Returns:
- this CheckerColor instance for chaining
-
hasHexadecimal
Checks if the color's hexadecimal representation matches the specified string.- Parameters:
hex
- the expected hexadecimal string (e.g., "#FFFFFF")- Returns:
- this CheckerColor instance for chaining
-