com.memority.toolkit.rule.api.ValidationRuleResult Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of toolkit-rule-api Show documentation
Show all versions of toolkit-rule-api Show documentation
This artifact provides the API classes that are necessary to implement the contracts of Memority configuration Rules.
/*
* Copyright (c) 2016-2023 Memority. All Rights Reserved.
*
* This file is part of Memority Toolkit API , a Memority project.
*
* This file is released under the Memority Public Artifacts End-User License Agreement,
* see
* Unauthorized copying of this file, via any medium is strictly prohibited.
*/
package com.memority.toolkit.rule.api;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.HashMap;
import java.util.Map;
/**
* Returned by the execution of a {@link ValidationRule}.
*/
@Data
@Accessors(chain = true)
public class ValidationRuleResult {
private final boolean valid;
private String msg;
private String i18nKey;
private Map i18nArgs = new HashMap<>();
public ValidationRuleResult(boolean valid) {
this.valid = valid;
}
public ValidationRuleResult(boolean valid, String msg) {
this.valid = valid;
this.msg = msg;
}
public ValidationRuleResult(boolean valid, String msg, String i18nKey) {
this(valid, msg);
this.i18nKey = i18nKey;
}
public ValidationRuleResult putI18nArg(String key, Object value) {
this.i18nArgs.put(key, value);
return this;
}
public static ValidationRuleResult valid() {
return new ValidationRuleResult(true);
}
public static ValidationRuleResult invalid() {
return new ValidationRuleResult(false);
}
public static ValidationRuleResult invalid(String msg) {
return new ValidationRuleResult(false, msg);
}
public static ValidationRuleResult invalid(String msg, String i18nKey) {
return new ValidationRuleResult(false, msg, i18nKey);
}
}