88import java .util .Arrays ;
99import java .util .List ;
1010import java .util .LongSummaryStatistics ;
11+ import java .util .stream .Collectors ;
1112
1213public class AllocationCsvExporter {
1314
1415 public static final AllocationCsvExporter INSTANCE = new AllocationCsvExporter ();
1516
1617 private AllocationCsvExporter () {}
1718
18- public void writeAllocationsToCsv (Maven3Version maven3Version , long [] allocations , String resultFilePath ) throws IOException {
19+ public void writeAllocationsToCsv (Maven3Version maven3Version , AllocationTimePair [] allocations , String resultFilePath ) throws IOException {
1920
2021 int numberOfAllocations = allocations .length ;
2122 CSVFormat csvFormat = buildCsvFormat (resultFilePath , numberOfAllocations );
@@ -37,7 +38,7 @@ private CSVFormat buildCsvFormat(String resultFilePath, int numberOfAllocations)
3738 }
3839
3940 private String [] buildCsvHeaders (int numberOfAllocations ) {
40- String [] csvHeaders = new String [(2 * numberOfAllocations ) + 5 ];
41+ String [] csvHeaders = new String [(3 * numberOfAllocations ) +5 ];
4142 csvHeaders [0 ] = "Maven version" ;
4243 csvHeaders [1 ] = "Average (bytes)" ;
4344 csvHeaders [2 ] = "Average (Gb)" ;
@@ -47,32 +48,40 @@ private String[] buildCsvHeaders(int numberOfAllocations) {
4748 for (int i = 1 ; i < numberOfAllocations + 1 ; i ++) {
4849 csvHeaders [i + 4 ] = "Allocation" + " " + i + " " + "(bytes)" ;
4950 }
51+
52+ for (int i = 1 ; i < numberOfAllocations + 1 ; i ++) {
53+ csvHeaders [i + 4 + numberOfAllocations ] = "Lenght" + " " + i + " " + "(seconds)" ;
54+ }
5055
5156 for (int i = 1 ; i < numberOfAllocations + 1 ; i ++) {
52- csvHeaders [i + 4 + numberOfAllocations ] = "Allocation" + " " + i + " " + "(Gb)" ;
57+ csvHeaders [i + 4 + numberOfAllocations * 2 ] = "Allocation" + " " + i + " " + "(Gb)" ;
5358 }
5459 return csvHeaders ;
5560 }
5661
57- private List <Object > buildCsvRecord (Maven3Version maven3Version , long [] allocations ) {
62+ private List <Object > buildCsvRecord (Maven3Version maven3Version , AllocationTimePair [] input ) {
5863
59- List <Object > csvRecord = new ArrayList <>((2 * allocations .length ) + 5 );
64+ List <Object > csvRecord = new ArrayList <>((2 * input .length ) + 5 );
6065
6166 csvRecord .add (maven3Version );
6267
63- LongSummaryStatistics allocationStatistics = Arrays .stream (allocations ). summaryStatistics ( );
68+ LongSummaryStatistics allocationStatistics = Arrays .stream (input ). collect ( Collectors . summarizingLong ( AllocationTimePair :: getAllocationInBytes ) );
6469 double averageAllocationInBytes = allocationStatistics .getAverage ();
6570 csvRecord .add (averageAllocationInBytes );
6671 csvRecord .add (averageAllocationInBytes / Math .pow (1024 , 3 ));
6772 csvRecord .add (allocationStatistics .getMin ());
6873 csvRecord .add (allocationStatistics .getMax ());
6974
70- for (int i = 0 ; i < allocations .length ; i ++) {
71- csvRecord .add (allocations [i ]);
75+ for (int i = 0 ; i < input .length ; i ++) {
76+ csvRecord .add (input [i ]. getAllocationInBytes () );
7277 }
73-
74- for (int i = 0 ; i < allocations .length ; i ++) {
75- csvRecord .add (allocations [i ] / Math .pow (1024 , 3 ));
78+
79+ for (int i = 0 ; i < input .length ; i ++) {
80+ csvRecord .add (input [i ].getLenghtInSeconds ());
81+ }
82+
83+ for (int i = 0 ; i < input .length ; i ++) {
84+ csvRecord .add (input [i ].getAllocationInBytes () / Math .pow (1024 , 3 ));
7685 }
7786
7887 return csvRecord ;
0 commit comments