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

io.robe.convert.csv.parsers.ParseEnum Maven / Gradle / Ivy

The newest version!
package io.robe.convert.csv.parsers;


import org.supercsv.cellprocessor.CellProcessorAdaptor;
import org.supercsv.util.CsvContext;

import static java.lang.Enum.valueOf;

public class ParseEnum extends CellProcessorAdaptor {
    Class enumType;


    @Override
    public Object execute(Object value, CsvContext context) {
        validateInputNotNull(value, context);

        if (value instanceof Enum) {
            String result = value.toString();
            return next.execute(result, context);
        } else {
            Enum result = valueOf(enumType,value.toString());
            return next.execute(result, context);
        }
    }

    public void setEnumType(Class enumType) {
        this.enumType = enumType;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy