com.github.leeonky.dal.format.Formatter Maven / Gradle / Ivy
package com.github.leeonky.dal.format;
import com.github.leeonky.dal.token.IllegalTypeException;
public interface Formatter {
R convert(T input);
boolean isValidType(Object input);
default boolean isValid(T value) {
try {
return isValidValue(transform(value));
} catch (IllegalTypeException ignore) {
return false;
}
}
default boolean isValidValue(R value) {
return true;
}
default String getFormatterName() {
return getClass().getSimpleName().replaceFirst("^Formatter", "");
}
default R transform(T o) {
if (isValidType(o))
return convert(o);
throw new IllegalTypeException();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy