Class RangeValidator

java.lang.Object
cloud.opencode.base.config.validation.RangeValidator
All Implemented Interfaces:
ConfigValidator

public class RangeValidator extends Object implements ConfigValidator
Range Validator - Validates numeric configuration values are within specified range 范围验证器 - 验证数字配置值在指定范围内

Validates that configuration values fall within the specified minimum and maximum bounds. Supports all numeric types including Integer, Long, Double, and Float.

验证配置值在指定的最小和最大界限内。支持所有数字类型包括Integer、Long、Double和Float。

Features | 主要功能:

  • Min/max validation - 最小/最大值验证
  • Multiple numeric type support - 支持多种数字类型
  • Inclusive/exclusive bounds - 包含/排除边界
  • Optional bounds (min-only or max-only) - 可选边界(仅最小值或最大值)

Usage Examples | 使用示例:

// Integer range for port
RangeValidator portValidator = new RangeValidator("server.port", 1, 65535);
ValidationResult result = portValidator.validate(config);

// Double range for percentage
RangeValidator percentValidator = new RangeValidator("completion", 0.0, 100.0);
result = percentValidator.validate(config);

Performance | 性能特性:

  • Time complexity: O(1) - 时间复杂度: O(1)
  • Space complexity: O(1) - 空间复杂度: O(1)

Security | 安全性:

  • Thread-safe: Yes - 线程安全: 是
  • Immutable: Yes (after construction) - 不可变: 是(构造后)
  • Null-safe: Yes - 空值安全: 是
Since:
JDK 25, opencode-base-config V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • RangeValidator

      public RangeValidator(String key, Number min, Number max)
      Create range validator with inclusive bounds 创建包含边界的范围验证器
      Parameters:
      key - configuration key | 配置键
      min - minimum value (null for no min limit) | 最小值(null表示无最小限制)
      max - maximum value (null for no max limit) | 最大值(null表示无最大限制)
    • RangeValidator

      public RangeValidator(String key, Number min, Number max, boolean minInclusive, boolean maxInclusive)
      Create range validator with configurable bounds 创建可配置边界的范围验证器
      Parameters:
      key - configuration key | 配置键
      min - minimum value | 最小值
      max - maximum value | 最大值
      minInclusive - include minimum value | 包含最小值
      maxInclusive - include maximum value | 包含最大值
  • Method Details

    • validate

      public ValidationResult validate(Config config)
      Description copied from interface: ConfigValidator
      Validate configuration 验证配置
      Specified by:
      validate in interface ConfigValidator
      Parameters:
      config - configuration to validate | 要验证的配置
      Returns:
      validation result | 验证结果