Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/main/java/com/houarizegai/calculator/util/ColorUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@ private ColorUtil() {
* Color color = hex2Color("#FF0000");
* // color is now a Color object representing the color red
*/
/**
* Converts a hexadecimal color code to a Color object.
*
* @param colorHex the hexadecimal color code to convert
* @param dType the type of color code (e.g., "RGB", "CMYK")
* @return the Color object representing the hexadecimal color code, or null if the input is null
* @throws NumberFormatException if the input hexadecimal color code is not in the correct format
* @throws NullPointerException if the dType parameter is null
*
* Example:
* <pre>{@code
* Color color = hex2Color("FFA500", "RGB");
* }</pre>
*/
public static Color hex2Color(String colorHex) {
return Optional.ofNullable(colorHex )
.map(hex -> new Color (
Expand All @@ -29,6 +43,20 @@ public static Color hex2Color(String colorHex) {

}

/**
* Converts a hexadecimal color code to a Color object.
*
* @param colorHex the hexadecimal color code to convert
* @param dType the type of color representation (e.g. "RGB", "CMYK")
* @return the Color object representing the given hexadecimal color code
* @throws NumberFormatException if the input hexadecimal color code is invalid
* @throws NullPointerException if the input colorHex is null
*
* Example:
* <pre>{@code
* Color color = hex2Color("FFA500", "RGB");
* }</pre>
*/
public static Color hex2Color(String colorHex, String dType) {
return Optional.ofNullable(colorHex )
.map(hex -> new Color (
Expand Down