@Test public void testWriteCsv() { Map<String, Integer> metrics = new HashMap<>(); metrics.put("loc",30); metrics.put("nom",5); metrics.put("noc",2); String outputFilepath = "src/test/resources/output_metrics"; mex.writeFile("csv", metrics, outputFilepath); File outputFile = new File(outputFilepath + ".csv"); Assert.assertTrue(outputFile.exists()); outputFile.delete(); }
private void writeCsv(Map<String, Integer> metrics, String filepath) { File outputFile = new File(filepath + ".csv"); StringBuilder metricsNames = new StringBuilder(); StringBuilder metricsValues = new StringBuilder(); for (Map.Entry<String, Integer> entry : metrics.entrySet()) { metricsNames.append(entry.getKey() + ","); metricsValues.append(entry.getValue()+","); } try { FileWriter writer = new FileWriter(outputFile); writer.append(metricsNames + "\n"); writer.append(metricsValues + "\n"); writer.close(); System.out.println("Metrics saved in " + outputFile.getAbsolutePath()); } catch (IOException e) { e.printStackTrace(); } }
MetricsExporter { private void writeCsv(Map<String, Integer> metrics, String filepath) { File outputFile = new File(filepath + ".csv"); StringBuilder metricsNames = new StringBuilder(); StringBuilder metricsValues = new StringBuilder(); for (Map.Entry<String, Integer> entry : metrics.entrySet()) { metricsNames.append(entry.getKey() + ","); metricsValues.append(entry.getValue()+","); } try { FileWriter writer = new FileWriter(outputFile); writer.append(metricsNames + "\n"); writer.append(metricsValues + "\n"); writer.close(); System.out.println("Metrics saved in " + outputFile.getAbsolutePath()); } catch (IOException e) { e.printStackTrace(); } } }
MetricsExporter { private void writeCsv(Map<String, Integer> metrics, String filepath) { File outputFile = new File(filepath + ".csv"); StringBuilder metricsNames = new StringBuilder(); StringBuilder metricsValues = new StringBuilder(); for (Map.Entry<String, Integer> entry : metrics.entrySet()) { metricsNames.append(entry.getKey() + ","); metricsValues.append(entry.getValue()+","); } try { FileWriter writer = new FileWriter(outputFile); writer.append(metricsNames + "\n"); writer.append(metricsValues + "\n"); writer.close(); System.out.println("Metrics saved in " + outputFile.getAbsolutePath()); } catch (IOException e) { e.printStackTrace(); } }  }
MetricsExporter { private void writeCsv(Map<String, Integer> metrics, String filepath) { File outputFile = new File(filepath + ".csv"); StringBuilder metricsNames = new StringBuilder(); StringBuilder metricsValues = new StringBuilder(); for (Map.Entry<String, Integer> entry : metrics.entrySet()) { metricsNames.append(entry.getKey() + ","); metricsValues.append(entry.getValue()+","); } try { FileWriter writer = new FileWriter(outputFile); writer.append(metricsNames + "\n"); writer.append(metricsValues + "\n"); writer.close(); System.out.println("Metrics saved in " + outputFile.getAbsolutePath()); } catch (IOException e) { e.printStackTrace(); } }  void writeFile(String outputType, Map<String, Integer> metrics, String filepath); }
MetricsExporter { private void writeCsv(Map<String, Integer> metrics, String filepath) { File outputFile = new File(filepath + ".csv"); StringBuilder metricsNames = new StringBuilder(); StringBuilder metricsValues = new StringBuilder(); for (Map.Entry<String, Integer> entry : metrics.entrySet()) { metricsNames.append(entry.getKey() + ","); metricsValues.append(entry.getValue()+","); } try { FileWriter writer = new FileWriter(outputFile); writer.append(metricsNames + "\n"); writer.append(metricsValues + "\n"); writer.close(); System.out.println("Metrics saved in " + outputFile.getAbsolutePath()); } catch (IOException e) { e.printStackTrace(); } }  void writeFile(String outputType, Map<String, Integer> metrics, String filepath);  }