
com.openpojo.validation.ValidatorBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of openpojo Show documentation
Show all versions of openpojo Show documentation
This project was born out of a need to validate all POJOs (Plain Old Java Object) are behaving correctly.
This project has two main aspects to it:
* Make Testing as easy as possible.
* Simplifying identity management (hashCode / equals) using annotation.
/*
* Copyright (c) 2010-2016 Osman Shoukry
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.openpojo.validation;
import java.util.ArrayList;
import java.util.List;
import com.openpojo.validation.exception.ValidationException;
import com.openpojo.validation.impl.DefaultValidator;
import com.openpojo.validation.rule.Rule;
import com.openpojo.validation.test.Tester;
/**
* @author oshoukry
*/
public class ValidatorBuilder {
private List rules = new ArrayList();
private List testers = new ArrayList();
private ValidatorBuilder() {
}
public static ValidatorBuilder create() {
return new ValidatorBuilder();
}
public ValidatorBuilder with(Rule... rules) {
if (rules != null)
for (Rule rule : rules) {
if (rule != null)
this.rules.add(rule);
}
return this;
}
public List getRules() {
return rules;
}
public ValidatorBuilder with(Tester... testers) {
if (testers != null)
for (Tester tester : testers) {
if (tester != null)
this.testers.add(tester);
}
return this;
}
public List getTesters() {
return testers;
}
public Validator build() {
if (rules.size() == 0 && testers.size() == 0)
throw ValidationException.getInstance("You must add at least 1 Rule or Tester before building Validator");
return new DefaultValidator(rules, testers);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy