package com.gregory.testing.log;

import com.gregory.testing.message.TimestampedMessage;
import com.gregory.testing.result.BatchResult;

import java.io.*;
import java.util.List;

public final class Logger {

    private Logger() {
    }

    public static void saveAsCsv(String path, String separator, List<BatchResult> results) throws IOException {
        for (BatchResult result : results) {
            try (FileWriter fw = new FileWriter(new File(path, result.id() + ".csv"));
                 BufferedWriter bw = new BufferedWriter(fw);
                 PrintWriter out = new PrintWriter(bw)) {
                List<TimestampedMessage> requests = result.requests();
                for (TimestampedMessage request : requests) {
                    String line = request.timestamp() + separator
                            + new String(request.message().data()) + separator
                            + "1"
                            + "\n";
                    out.append(line);
                }
                List<TimestampedMessage> responses = result.responses();
                for (TimestampedMessage response : responses) {
                    String line = response.timestamp() + separator
                            + new String(response.message().data()) + separator
                            + "0"
                            + "\n";
                    out.append(line);
                }
            }
        }
    }

}

@@ -27,16 +27,54 @@
 g.log;%0A%0A
+import com.google.common.base.Joiner;%0A
 import c
@@ -385,57 +385,8 @@
 n %7B%0A
-        for (BatchResult result : results) %7B%0A    
     
@@ -429,34 +429,12 @@
 ter(
-new File(path, result.id()
+path
  + %22
@@ -439,17 +439,16 @@
  %22.csv%22)
-)
 ;%0A      
@@ -454,20 +454,16 @@
         
-   
- 
 Buffered
@@ -498,20 +498,16 @@
 er(fw);%0A
-    
         
@@ -548,24 +548,73 @@
 iter(bw)) %7B%0A
+            for (BatchResult result : results) %7B%0A
             
@@ -758,238 +758,75 @@
     
-String line = request.timestamp() + separator%0A                            + new String(request.message().data()) + separator%0A                            + %221%22%0A                            + %22%5Cn%22;%0A                    out.append(line
+out.append(messageToRow(result.id(), %22request%22, request, separator)
 );%0A 
@@ -1003,44 +1003,66 @@
     
-String line = response.timestamp() +
+out.append(messageToRow(result.id(), %22response%22, response,
  sep
@@ -1059,32 +1059,35 @@
 ponse, separator
+));
 %0A               
@@ -1079,32 +1079,34 @@
                 
+%7D%0A
             + ne
@@ -1105,209 +1105,265 @@
     
-+ new String(response.message().data()) + separator%0A                            + %220%22%0A                            + %22%5Cn%22;%0A                    out.append(line);%0A                %7D%0A            %7D%0A        %7D
+%7D%0A        %7D%0A    %7D%0A%0A    private static String messageToRow(int batchId, String messageType, TimestampedMessage message, String separator) %7B%0A        return Joiner.on(separator)%0A                .join(batchId, messageType, new String(message.message().data()));
 %0A   

Change persistence model