java.lang.Object
com.ultikits.ultitools.abstracts.command.validation.ValidatorChain

public final class ValidatorChain extends Object
Manages a chain of validators that are executed in order. Thread-safe implementation supporting dynamic validator registration.

管理按顺序执行的验证器链。 支持动态验证器注册的线程安全实现。

Since:
6.2.0
Version:
2.0.0
Author:
wisdomme
  • Field Details

    • validators

      private final List<CommandValidator> validators
    • sorted

      private volatile boolean sorted
  • Constructor Details

    • ValidatorChain

      public ValidatorChain()
      Creates an empty validator chain. 创建一个空的验证器链。
    • ValidatorChain

      public ValidatorChain(Collection<CommandValidator> validators)
      Creates a validator chain with the specified validators. 使用指定的验证器创建验证器链。
      Parameters:
      validators - the validators to add
  • Method Details

    • addValidator

      public ValidatorChain addValidator(CommandValidator validator)
      Adds a validator to the chain. 向链中添加验证器。
      Parameters:
      validator - the validator to add
      Returns:
      this chain for fluent chaining
    • removeValidator

      public ValidatorChain removeValidator(CommandValidator validator)
      Removes a validator from the chain. 从链中移除验证器。
      Parameters:
      validator - the validator to remove
      Returns:
      this chain for fluent chaining
    • removeValidators

      public ValidatorChain removeValidators(Class<? extends CommandValidator> validatorClass)
      Removes all validators of the specified type. 移除所有指定类型的验证器。
      Parameters:
      validatorClass - the validator class to remove
      Returns:
      this chain for fluent chaining
    • clear

      public ValidatorChain clear()
      Clears all validators from the chain. 清除链中的所有验证器。
      Returns:
      this chain for fluent chaining
    • validate

      Validates the context through all validators in the chain. Stops at the first failure. 通过链中的所有验证器验证上下文。 在第一个失败时停止。
      Parameters:
      context - the command context to validate
      Returns:
      the result of the validation
    • validateAll

      Validates the context through all validators, collecting all failures. Does not stop at the first failure. 通过所有验证器验证上下文,收集所有失败。 不会在第一个失败时停止。
      Parameters:
      context - the command context to validate
      Returns:
      the result containing all validation results
    • size

      public int size()
      Gets the number of validators in the chain. 获取链中验证器的数量。
      Returns:
      the number of validators
    • isEmpty

      public boolean isEmpty()
      Checks if the chain is empty. 检查链是否为空。
      Returns:
      true if empty
    • getValidators

      public List<CommandValidator> getValidators()
      Gets an unmodifiable view of the validators. 获取验证器的不可修改视图。
      Returns:
      unmodifiable list of validators
    • ensureSorted

      private void ensureSorted()
    • sort

      private void sort()
    • builder

      public static ValidatorChain.Builder builder()
      Creates a new builder for validator chains. 创建验证器链的新构建器。
      Returns:
      a new builder