org.meeuw.i18n.regions.validation.RegionValidatorService Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of i18n-regions Show documentation
Show all versions of i18n-regions Show documentation
Provides the service loader for Regions, and some utilities to deal with regions generally
package org.meeuw.i18n.regions.validation;
import java.util.Collections;
import java.util.Set;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.logging.Logger;
import javax.validation.*;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.meeuw.i18n.regions.RegionService;
/**
* Makes validation settings (via annotation) available as a {@link Predicate}.
* @author Michiel Meeuwissen
* @since 0.1
*/
public class RegionValidatorService {
private static final Logger logger = Logger.getLogger(RegionValidatorService.class.getName());
private final static Validator VALIDATOR;
static {
Validator proposal;
try {
ValidatorFactory factory = Validation.byDefaultProvider()
.configure()
.buildValidatorFactory();
proposal = factory.getValidator();
} catch (Exception e) {
logger.warning(e.getMessage());
proposal = null;
}
VALIDATOR = proposal;
}
private static final RegionValidatorService INSTANCE = new RegionValidatorService();
public static RegionValidatorService getInstance() {
return INSTANCE;
}
private RegionValidatorService() {
}
/**
* Returns the validation info for the given property of the name as a {@link Predicate}, which can e.g. be used to {@link java.util.stream.Stream#filter(Predicate)} the results of {@link RegionService#values()}
* @param clazz
* @param propertyName The property which is annotation with javax.validation annotation's like {@link ValidRegion}.
* @param groups
* @return
*/
public Predicate
© 2015 - 2025 Weber Informatics LLC | Privacy Policy