Class CaptchaConfig.Builder

java.lang.Object
cloud.opencode.base.captcha.CaptchaConfig.Builder
Enclosing class:
CaptchaConfig

public static final class CaptchaConfig.Builder extends Object
Configuration Builder 配置构建器
Since:
JDK 25, opencode-base-captcha V1.0.0
Author:
Leon Soo www.LeonSoo.com
  • Method Details

    • width

      public CaptchaConfig.Builder width(int width)
      Sets the image width. 设置图像宽度。
      Parameters:
      width - the width | 宽度
      Returns:
      this builder | 此构建器
    • height

      public CaptchaConfig.Builder height(int height)
      Sets the image height. 设置图像高度。
      Parameters:
      height - the height | 高度
      Returns:
      this builder | 此构建器
    • length

      public CaptchaConfig.Builder length(int length)
      Sets the CAPTCHA code length. 设置验证码长度。
      Parameters:
      length - the length | 长度
      Returns:
      this builder | 此构建器
    • type

      public CaptchaConfig.Builder type(CaptchaType type)
      Sets the CAPTCHA type. 设置验证码类型。
      Parameters:
      type - the type | 类型
      Returns:
      this builder | 此构建器
    • expireTime

      public CaptchaConfig.Builder expireTime(Duration expireTime)
      Sets the expiration time. 设置过期时间。
      Parameters:
      expireTime - the expire time | 过期时间
      Returns:
      this builder | 此构建器
    • noiseLines

      public CaptchaConfig.Builder noiseLines(int noiseLines)
      Sets the number of noise lines. 设置干扰线数量。
      Parameters:
      noiseLines - the noise lines count | 干扰线数量
      Returns:
      this builder | 此构建器
    • noiseDots

      public CaptchaConfig.Builder noiseDots(int noiseDots)
      Sets the number of noise dots. 设置干扰点数量。
      Parameters:
      noiseDots - the noise dots count | 干扰点数量
      Returns:
      this builder | 此构建器
    • fontSize

      public CaptchaConfig.Builder fontSize(float fontSize)
      Sets the font size. 设置字体大小。
      Parameters:
      fontSize - the font size | 字体大小
      Returns:
      this builder | 此构建器
    • fontName

      public CaptchaConfig.Builder fontName(String fontName)
      Sets the font name. 设置字体名称。
      Parameters:
      fontName - the font name | 字体名称
      Returns:
      this builder | 此构建器
    • backgroundColor

      public CaptchaConfig.Builder backgroundColor(Color backgroundColor)
      Sets the background color. 设置背景颜色。
      Parameters:
      backgroundColor - the background color | 背景颜色
      Returns:
      this builder | 此构建器
    • fontColors

      public CaptchaConfig.Builder fontColors(Color... fontColors)
      Sets the font colors. 设置字体颜色。
      Parameters:
      fontColors - the font colors | 字体颜色数组
      Returns:
      this builder | 此构建器
    • caseSensitive

      public CaptchaConfig.Builder caseSensitive(boolean caseSensitive)
      Sets case sensitivity. 设置区分大小写。
      Parameters:
      caseSensitive - true for case sensitive | true 表示区分大小写
      Returns:
      this builder | 此构建器
    • gifFrameCount

      public CaptchaConfig.Builder gifFrameCount(int gifFrameCount)
      Sets the GIF frame count. 设置 GIF 帧数。
      Parameters:
      gifFrameCount - the frame count | 帧数
      Returns:
      this builder | 此构建器
    • gifDelay

      public CaptchaConfig.Builder gifDelay(int gifDelay)
      Sets the GIF frame delay. 设置 GIF 帧延迟。
      Parameters:
      gifDelay - the delay in milliseconds | 延迟(毫秒)
      Returns:
      this builder | 此构建器
    • customFontPaths

      public CaptchaConfig.Builder customFontPaths(List<String> paths)
      Sets the custom font paths. 设置自定义字体路径列表。
      Parameters:
      paths - the font paths | 字体路径列表
      Returns:
      this builder | 此构建器
    • customFontPath

      public CaptchaConfig.Builder customFontPath(String path)
      Adds a single custom font path. 追加单个自定义字体路径。
      Parameters:
      path - the font path | 字体路径
      Returns:
      this builder | 此构建器
    • randomFontPerChar

      public CaptchaConfig.Builder randomFontPerChar(boolean randomFontPerChar)
      Sets whether each character uses a random different font. 设置每个字符是否使用随机不同字体。
      Parameters:
      randomFontPerChar - true to enable | true 表示启用
      Returns:
      this builder | 此构建器
    • charOverlapRatio

      public CaptchaConfig.Builder charOverlapRatio(float charOverlapRatio)
      Sets the character overlap ratio. 设置字符重叠比例。
      Parameters:
      charOverlapRatio - the ratio (0.0-0.5) | 重叠比例(0.0-0.5)
      Returns:
      this builder | 此构建器
    • sineWarpEnabled

      public CaptchaConfig.Builder sineWarpEnabled(boolean sineWarpEnabled)
      Sets whether sine wave warp is enabled. 设置是否启用正弦波变形。
      Parameters:
      sineWarpEnabled - true to enable | true 表示启用
      Returns:
      this builder | 此构建器
    • outlineShadowEnabled

      public CaptchaConfig.Builder outlineShadowEnabled(boolean outlineShadowEnabled)
      Sets whether character outline shadow is enabled. 设置是否启用字符轮廓阴影。
      Parameters:
      outlineShadowEnabled - true to enable | true 表示启用
      Returns:
      this builder | 此构建器
    • bezierNoiseEnabled

      public CaptchaConfig.Builder bezierNoiseEnabled(boolean bezierNoiseEnabled)
      Sets whether Bezier curve noise is enabled. 设置是否启用贝塞尔穿字噪声。
      Parameters:
      bezierNoiseEnabled - true to enable | true 表示启用
      Returns:
      this builder | 此构建器
    • powDifficulty

      public CaptchaConfig.Builder powDifficulty(int powDifficulty)
      Sets the PoW (Proof-of-Work) difficulty. 设置 PoW(工作量证明)难度。
      Parameters:
      powDifficulty - the number of leading zero bits (1-32) | 前导零位数(1-32)
      Returns:
      this builder | 此构建器
    • audioSpeedVariation

      public CaptchaConfig.Builder audioSpeedVariation(float audioSpeedVariation)
      Sets the audio speed variation range. 设置音频语速变化范围。
      Parameters:
      audioSpeedVariation - the variation (0.0-0.5) | 变化范围(0.0-0.5)
      Returns:
      this builder | 此构建器
    • build

      public CaptchaConfig build()
      Builds the configuration after validating all parameters. 验证所有参数后构建配置。

      Bounds are enforced to prevent resource exhaustion (e.g., OOM from oversized BufferedImage allocation).

      强制边界检查以防止资源耗尽(例如,过大的 BufferedImage 分配导致 OOM)。

      Returns:
      the configuration | 配置
      Throws:
      NullPointerException - if type, expireTime, or fontName is null | 如果 type、expireTime 或 fontName 为 null
      IllegalArgumentException - if any numeric parameter is out of bounds | 如果任何数值参数超出范围