<commit_before>package de.frosner.datagenerator.util;

import java.util.List;
import java.util.Map;

import net.sf.qualitycheck.Check;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

public final class ExportFormatReaderUtil {

	private ExportFormatReaderUtil() {
		throw new UnsupportedOperationException();
	}

	public static Map<String, List<String>> readCsvWithHeader(String csv, String delim) {
		Check.notNull(csv);
		if (csv.isEmpty()) {
			throw new MalformedExportFormatException("CSV", "No header available");
		}
		Map<String, List<String>> resultColumns = Maps.newHashMap();
		List<List<String>> columns = Lists.newArrayList();
		List<String> lines = Lists.newArrayList(csv.split("\\n"));
		List<String> header = Lists.newArrayList(lines.get(0).split(delim));
		for (String columnHead : header) {
			List<String> column = Lists.newArrayList();
			columns.add(column);
			resultColumns.put(columnHead, column);
		}
		for (int i = 1; i < lines.size(); i++) {
			List<String> line = Lists.newArrayList(lines.get(i).split(delim));
			int elementIndex = 0;
			for (String element : line) {
				columns.get(elementIndex++).add(element);
			}
		}
		return resultColumns;
	}
}
<commit_msg>#146 document MalformedExportFormatException in test util<commit_after>package de.frosner.datagenerator.util;

import java.util.List;
import java.util.Map;

import net.sf.qualitycheck.Check;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

public final class ExportFormatReaderUtil {

	private ExportFormatReaderUtil() {
		throw new UnsupportedOperationException();
	}

	/**
	 * Converts a CSV file into a {@linkplain Map} containing the column heads as keys.
	 * 
	 * @param csv
	 *            to convert
	 * @param delim
	 *            of the CSV
	 * @return CSV as {@linkplain Map}
	 * 
	 * @throws MalformedExportFormatException
	 *             if the CSV string does not contain a header
	 */
	public static Map<String, List<String>> readCsvWithHeader(String csv, String delim) {
		Check.notNull(csv);
		if (csv.isEmpty()) {
			throw new MalformedExportFormatException("CSV", "No header available");
		}
		Map<String, List<String>> resultColumns = Maps.newHashMap();
		List<List<String>> columns = Lists.newArrayList();
		List<String> lines = Lists.newArrayList(csv.split("\\n"));
		List<String> header = Lists.newArrayList(lines.get(0).split(delim));
		for (String columnHead : header) {
			List<String> column = Lists.newArrayList();
			columns.add(column);
			resultColumns.put(columnHead, column);
		}
		for (int i = 1; i < lines.size(); i++) {
			List<String> line = Lists.newArrayList(lines.get(i).split(delim));
			int elementIndex = 0;
			for (String element : line) {
				columns.get(elementIndex++).add(element);
			}
		}
		return resultColumns;
	}
}

{'fraction_non_alphanumeric': 0.1334985835694051, 'fraction_numerical': 0.003186968838526912, 'mean_word_length': 4.280373831775701, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7393306', 'n_tokens_mistral': 985, 'n_tokens_neox': 877, 'n_words': 206}