Class ValidatorChain
java.lang.Object
com.ultikits.ultitools.abstracts.command.validation.ValidatorChain
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder for creating validator chains.static final classResult of chain validation. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates an empty validator chain.ValidatorChain(Collection<CommandValidator> validators) Creates a validator chain with the specified validators. -
Method Summary
Modifier and TypeMethodDescriptionaddValidator(CommandValidator validator) Adds a validator to the chain.static ValidatorChain.Builderbuilder()Creates a new builder for validator chains.clear()Clears all validators from the chain.private voidGets an unmodifiable view of the validators.booleanisEmpty()Checks if the chain is empty.removeValidator(CommandValidator validator) Removes a validator from the chain.removeValidators(Class<? extends CommandValidator> validatorClass) Removes all validators of the specified type.intsize()Gets the number of validators in the chain.private voidsort()validate(CommandContext context) Validates the context through all validators in the chain.validateAll(CommandContext context) Validates the context through all validators, collecting all failures.
-
Field Details
-
validators
-
sorted
private volatile boolean sorted
-
-
Constructor Details
-
ValidatorChain
public ValidatorChain()Creates an empty validator chain. 创建一个空的验证器链。 -
ValidatorChain
Creates a validator chain with the specified validators. 使用指定的验证器创建验证器链。- Parameters:
validators- the validators to add
-
-
Method Details
-
addValidator
Adds a validator to the chain. 向链中添加验证器。- Parameters:
validator- the validator to add- Returns:
- this chain for fluent chaining
-
removeValidator
Removes a validator from the chain. 从链中移除验证器。- Parameters:
validator- the validator to remove- Returns:
- this chain for fluent chaining
-
removeValidators
Removes all validators of the specified type. 移除所有指定类型的验证器。- Parameters:
validatorClass- the validator class to remove- Returns:
- this chain for fluent chaining
-
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
Gets an unmodifiable view of the validators. 获取验证器的不可修改视图。- Returns:
- unmodifiable list of validators
-
ensureSorted
private void ensureSorted() -
sort
private void sort() -
builder
Creates a new builder for validator chains. 创建验证器链的新构建器。- Returns:
- a new builder
-