cz.jalasoft.util.configuration.ConverterIntegrityValidator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of JalasoftUtils Show documentation
Show all versions of JalasoftUtils Show documentation
A collection of utility classes that might be useful.
The newest version!
package cz.jalasoft.util.configuration;
import cz.jalasoft.util.configuration.exception.InvalidPropertyMethod;
import java.lang.reflect.Method;
import java.util.Arrays;
/**
* @author Honza Lastovicka ([email protected])
* @since 2016-07-31.
*/
final class ConverterIntegrityValidator {
private final ConverterRegistry converterRegistry;
public ConverterIntegrityValidator(ConverterRegistry converterRegistry) {
this.converterRegistry = converterRegistry;
}
void validate(Class> type) {
Method[] methods = type.getDeclaredMethods();
Arrays.stream(methods).forEach(this::assertReturnValueHasConverter);
}
private void assertReturnValueHasConverter(Method method) {
Class> returnType = method.getReturnType();
if (!converterRegistry.hasConverter(returnType)) {
throw new InvalidPropertyMethod(method, "Method returns a value of type '" + returnType + "' for which no converter is registered.");
}
}
}