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

dataloader.utils.ParseUtils Maven / Gradle / Ivy

The newest version!
package dataloader.utils;

import tech.tablesaw.api.ColumnType;
import tech.tablesaw.columns.Column;

import java.util.ArrayList;
import java.util.List;

public class ParseUtils {


    /**
     * Parse the entries of the given list of strings as doubles
     */
    public static List< Double > parseAsDouble(List dataSet){

        List data = new ArrayList( dataSet.size());

        for (String entry: dataSet) {
            data.add( Double.parseDouble(entry));

        }

        return data;
    }


    /**
     * Parse the entries of the given Column  as doubles
     */
    public static List< Double > parseAsDouble(Column dataSet){

        List data =null;
        ColumnType type = dataSet.type();

        if(type.name() == "INTEGER"){

            data = ParseUtils.parseIntegerToDouble(dataSet);
        }
        else if(type.name() == "DOUBLE"){

            data = new ArrayList( dataSet.size());

            for (int i = 0; i < dataSet.size() ; i++) {
                data.add( (Double) dataSet.get(i));
            }
        }

        return data ;
    }


    public static double[] parseAsDoubleArray(Column dataSet){

        List listData = ParseUtils.parseAsDouble(dataSet);
        double[] data = new double[listData.size()];

        for (int i = 0; i < data.length; i++) {
            data[i] = listData.get(i);
        }

        return data ;
    }

    public static List< Double > parseIntegerToDouble(Column dataSet){

        List data = new ArrayList( dataSet.size());

        for (int i = 0; i < dataSet.size() ; i++) {
            data.add( (double) ((Integer)dataSet.get(i)).intValue());
        }

        return data;
    }



    /**
     * Parse the entries of the given list of strings as integers
     */
    public static List< Integer > parseAsInteger(List dataSet){

        List data = new ArrayList( dataSet.size());

        for (String entry: dataSet) {
            data.add( Integer.parseInt(entry));
        }
        return data;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy