A small java library for building violations.
void example() throws ViolationException {
boolean condition = true;
ViolationBuilder.builder()
.error(condition,"error-key", () -> "some error message.")
.warning(condition,"waring-key", () -> "some warning message.")
.buildIgnoreWarnings();
}
Appends to the builder a violations of error type.
void example() throws ViolationException {
boolean condition = true;
ViolationBuilder.builder()
.error(condition, "error-key-01", "some error-01 message.")
.error("error-key-02", "some error-02 message.")
.error(condition,"error-key-03", () -> "some error-03 message.")
.error("error-key-04", () -> "some error-04 message.")
.build();
}
Appends to the builder a violations of warning type.
void example() throws ViolationException {
boolean condition = true;
ViolationBuilder.builder()
.warning(condition, "waring-key-01", "some waring-01 message.")
.warning("waring-key-02", "some waring-02 message.")
.warning(condition,"waring-key-03", () -> "some warning-03 message.")
.warning("waring-key-04", () -> "some warning-04 message.")
.build();
}
Executing a collection of validation rules
final Collection<ValidationRule<Object>> rules = Arrays.asList(
new ValidationRuleContinueFlow<Object>() {
@Override
public void runContinueFlow(ViolationBuilder violationBuilder, Object data) {
violationBuilder.warning(/* validation on the data */, "waring-key-01", "some waring-01 message.");
}
},
new ValidationRuleStopFlow<Object>() {
@Override
public void runStopFlow(ViolationBuilder violationBuilder, Object data) {
violationBuilder.error(/* validation on the data */, "error-key-01", "some error-01 message.");
}
},
new ValidationRuleContinueFlow<Object>() {
@Override
public void runContinueFlow(ViolationBuilder violationBuilder, Object data) {
violationBuilder.error(/* validation on the data */, "error-key-02", "some error-02 message.");
}
},
new ValidationRule<Object>() {
@Override
public Rulesflow run(ViolationBuilder violationBuilder, Object data) {
violationBuilder.error(/* validation on the data */, "error-key-03", "some error-03 message.");
return Rulesflow.CONTINUE;
}
}
);
RulesExecutor.rulesExecutor(rules, data);
Available in the Maven Central repository.
Add a dependency to com.github.thiagogarbazza:violation-builder
in your project.
Example using maven:
<dependency>
<groupId>com.github.thiagogarbazza</groupId>
<artifactId>violation-builder</artifactId>
<version>1.2.0</version>
</dependency>
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
We use SemVer for versioning. For the versions available, see the tags on this repository.
- Thiago Garbazza - Initial work
See also the list of contributors who participated in this project.
This project is licensed under the MIT License - see the LICENSE.md file for details.
- Java 8+
- Junit jupter