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

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

There is a newer version: 0.5.0.0-1039
Show newest version
package io.robe.convert.csv.parsers;

import org.supercsv.cellprocessor.*;

public enum Parsers {
    BIGDECIMAL("java.math.BigDecimal", ParseBigDecimal.class),
    BOOLEAN("java.lang.Boolean", ParseBool.class),
    BYTE("java.lang.Byte", ParseChar.class),
    DOUBLE("java.lang.Double", ParseDouble.class),
    INT("int", ParseInt.class),
    INTEGER("java.lang.Integer", ParseInt.class),
    LONG("java.lang.Long", ParseLong.class),
    STRING("java.lang.String", null),
    CHAR("java.lang.String", ParseChar.class),
    ENUM("java.lang.Enum", ParseEnum.class);


    private final String type;
    private final Class parser;

    public CellProcessorAdaptor getParser() {
        try {
            return (parser == null) ? null : parser.newInstance();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public CellProcessorAdaptor getParser(Object... params) {
        try {
            CellProcessorAdaptor instance = parser.newInstance();
            if (instance instanceof ParseEnum)
                ((ParseEnum) instance).setEnumType((Class) params[0]);
            return instance;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    private Parsers(String type, Class parser) {
        this.type = type;
        this.parser = parser;
    }

    @Override
    public String toString() {
        return type;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy