package prope.reporting;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;

public final class ReportWriter {

	private final Report report;

	private final String excelDelimiter = ";";

	private final String rDelimiter = ",";

	public ReportWriter(Report report) {
		this.report = report;
	}

	public void printToConsole() {
		for (ReportEntry entry : report) {
			System.out.println(entry);
		}
	}

	public void writeToExcelFile(String outputFile) {
		if (report.getEntries().isEmpty()) {
			System.out
					.println("There is nothing to write... Did you use the correct analysis type?");
			return;
		}

		writeToFile(outputFile, excelDelimiter);
	}

	private void writeToFile(String outputFile, String delimiter) {
		try (PrintWriter writer = new PrintWriter(new OutputStreamWriter(
				new FileOutputStream(outputFile), "UTF-8"))) {
			printHeader(writer, delimiter);
			printBody(writer, delimiter);
		} catch (IOException e) {
			System.err.println("Could no write to file " + outputFile + ": "
					+ e.getMessage());
			e.printStackTrace();
		}
	}

	private void printHeader(PrintWriter writer, String delimiter) {
		writer.print("filename" + delimiter);
		for (String varName : report.getEntries().get(0).getVariableNames()) {
			writer.print(varName + delimiter);
		}
		writer.println();
	}

	private void printBody(PrintWriter writer, String delimiter) {
		for (ReportEntry entry : report) {
			writer.println(entry.toStringWithSeparator(delimiter));
		}
	}

	public void writeToRFile(String outputFile) {
		writeToFile(outputFile, rDelimiter);
	}
}

@@ -400,46 +400,23 @@
 %7B%0A%09%09
-for (ReportEntry entry : report) %7B%0A%09%09%09
+report.forEach(
 Syst
@@ -425,28 +425,19 @@
 .out
-.
+::
 println
-(entry);%0A%09%09%7D
+);
 %0A%09%7D%0A
@@ -1204,32 +1204,11 @@
 r);%0A
+%0A
 %09%09
-for (String varName : 
 repo
@@ -1248,23 +1248,41 @@
 eNames()
-) %7B
 %0A%09%09%09
+%09.forEach(varName -%3E 
 writer.p
@@ -1306,21 +1306,19 @@
 limiter)
+)
 ;%0A
-%09%09%7D
 %0A%09%09write
@@ -1404,46 +1404,57 @@
 %7B%0A%09%09
-for (ReportEntry entry : report) %7B%0A%09%09%09
+report.getEntries()%0A%09%09%09%09.forEach(%0A%09%09%09%09%09%09entry -%3E 
 writ
@@ -1469,16 +1469,25 @@
 ln(entry
+%0A%09%09%09%09%09%09%09%09
 .toStrin
@@ -1512,21 +1512,18 @@
 imiter))
+)
 ;
-%0A%09%09%7D
 %0A%09%7D%0A%0A%09pu

Use lambda expressions for report writing