Class ColorUtils

java.lang.Object
com.dianxin.tori.base.utils.ColorUtils

public final class ColorUtils extends Object
Utility class for color operations, hex transformations, and randomized palettes.
  • Method Details

    • random

      @NotNull public static @NotNull Color random()
      Generates a completely randomized RGB Color.
      Returns:
      a random color instance
    • randomHexString

      @NotNull public static @NotNull String randomHexString()
      Generates a randomized uppercase Hex string representation (e.g., "#FFAABB").
      Returns:
      a 7-character hex color string
    • randomColorRestricted

      @NotNull public static @NotNull Color randomColorRestricted(@NotNull @NotNull String minHex, @NotNull @NotNull String maxHex)
      Generates a randomized color bounded between two hexadecimal thresholds per channel. Useful for constrained palettes and gradient stepping.
      Parameters:
      minHex - the starting hex string (e.g., "#000000" or "000000")
      maxHex - the ending hex string (e.g., "#101010" or "101010")
      Returns:
      a randomized color bounded within the designated range
      Throws:
      IllegalArgumentException - if the hex string format or length is invalid
    • toHexString

      @NotNull public static @NotNull String toHexString(@NotNull @NotNull Color color)
      Converts a Color object into an uppercase Hex string (#RRGGBB).
      Parameters:
      color - the color to convert
      Returns:
      formatted hex color string
    • fromHex

      @NotNull public static @NotNull Color fromHex(@Nullable @Nullable String hexStr)
      Parses a hexadecimal string into a Color object.
      Parameters:
      hexStr - the hex string (e.g., "#FF0000" or "FF0000")
      Returns:
      the resolved Color
      Throws:
      IllegalArgumentException - if the string is null, empty, or improperly formatted