package nuclibook.entity_utils;

import nuclibook.models.Exportable;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ExportUtils {

    private static String rowAsCSV(List<String> row) {
        String output = "";

        for (String cell : row) {
            cell = cell.replace("\"", "\"\"");
            output += "\"" + cell + "\",";
        }

        output = output.substring(0, output.length() - 1);

        return output;
    }

    public static <E> String exportCSV(Class dbClass) {
        List<E> allEntities = AbstractEntityUtils.getAllEntities(dbClass);

        String output = "";

        HashMap<String, String> entityHashMap;
        for (E entity : allEntities) {
            entityHashMap = ((Exportable) entity).getExportableHashMap();

            if (output.equals("")) {
                List<String> header = new ArrayList<String>();
                for (Map.Entry<String, String> entityEntry : entityHashMap.entrySet()) {
                    String key = entityEntry.getKey();
                    header.add(key);
                }

                output += rowAsCSV(header) + "\n";
            }
        }

        return output;
    }

}

@@ -1187,16 +1187,305 @@
       %7D%0A
+%0A%0A            List%3CString%3E row = new ArrayList%3CString%3E();%0A            for (Map.Entry%3CString, String%3E entityEntry : entityHashMap.entrySet()) %7B%0A                String value = entityEntry.getValue();%0A                row.add(value);%0A            %7D%0A%0A            output += rowAsCSV(row) + %22%5Cn%22;%0A
         

Add value export