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

org.diirt.util.text.CsvParserResult Maven / Gradle / Ivy

Go to download

Basic Java utility classes to be shared across projects until suitable replacements are available in the JDK.

The newest version!
/**
 * Copyright (C) 2010-18 diirt developers. See COPYRIGHT.TXT
 * All rights reserved. Use is subject to license terms. See LICENSE.TXT
 */
package org.diirt.util.text;

import java.util.List;
import org.diirt.util.array.ListDouble;
import org.diirt.util.array.ListNumber;

/**
 * The result of the CSV parsing.
 * 

* This class contains all the information about the parsing: whether it was * successful, an error message, the parsed data, the parsed header and * the column type. *

* TODO: the error handling could be extended to include multiple error messages * while still giving a best effort result (e.g. skipping the lines that * can't be parsed). * * @author carcassi */ public class CsvParserResult { private final List columnNames; private final List columnValues; private final List> columnTypes; private final int rowCount; private final boolean parsingSuccessful; private final String message; CsvParserResult(List columnNames, List columnValues, List> columnTypes, int rowCount, boolean parsingSuccessful, String message) { this.columnNames = columnNames; this.columnValues = columnValues; this.columnTypes = columnTypes; this.rowCount = rowCount; this.parsingSuccessful = parsingSuccessful; this.message = message; } /** * The header of the CSV table. * * @return the list of column names */ public List getColumnNames() { return columnNames; } /** * The data of each column. *

* Depending on the type, the data will be stored in a {@link List} (for * Objects) and in a {@link ListNumber} (for primitive data). For example, * if the column type is {@link String}, then one can expect a {@code List}. * If it's {@code double}, then one can expect a {@link ListDouble}. * * @return the list of column data */ public List getColumnValues() { return columnValues; } /** * The type of data found in the column. *

* At present, it can be either {@link String} or {@code double}. * * @return list of column types */ public List> getColumnTypes() { return columnTypes; } /** * The number of rows. * * @return the number of rows */ public int getRowCount() { return rowCount; } /** * True whether the parsing was successful and one can safely read * data from the data methods. * * @return true if data is present and complete */ public boolean isParsingSuccessful() { return parsingSuccessful; } /** * An error message. * * @return an error message; null if no error occurred */ public String getMessage() { return message; } }