package com.github.omaru.daymeeting.io;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Collection;
import java.util.LinkedList;
import java.util.Scanner;

public class CSVReader implements FileReader{
	private static final String TOKEN_SEPARATOR = ",";
	
	public Collection<CSVLine>read(File file) throws FileNotFoundException{
		Scanner scanner = new Scanner(file);
		Collection<CSVLine> lines = new LinkedList<>();

		while (scanner.hasNext()) {
			lines.add(parse(scanner.nextLine()));
		}

		scanner.close();

		return lines;

	}
	public Collection<CSVLine> read(String path) throws FileNotFoundException {
		return read(new File(path));
	}

	private CSVLine parse(String line) {
		return new CSVLine(line.split(TOKEN_SEPARATOR));
	}
}
