All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.leeonky.dal.format.Formatter Maven / Gradle / Ivy

There is a newer version: 0.7.4
Show newest version
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