I'm trying to write some Benchmark tests for this csv file reader just using default java utils, I'm not sure how to go about it
package org.sample;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.*;
public class Test {
Map<Integer, List<String>> props;
public Test(String filename) {
props = new HashMap<>();
String line = "";
String splitBy = ",";
boolean isFirstLine = true;
try {
BufferedReader br = new BufferedReader(new FileReader(filename));
while ((line = br.readLine()) != null) {
if (isFirstLine) {
isFirstLine = false;
continue;
}
String[] data = line.split(splitBy);
List<String> details = new ArrayList<>();
details.add(data[0]);
details.add(data[1]);
details.add(data[2]);
details.add(data[3]);
details.add(data[4]);
props.put(Integer.parseInt(data[0]), details);
}
} catch (FileNotFoundException e) {
System.out.println("File not found");
} catch (IOException e) {
System.out.println("Error Reading File");
}
}
public static void main(String[] args) {
Test cw = new Test(args[0]);
System.out.println(cw.getProperty(Integer.parseInt(args[1])));
System.out.println();
System.out.println(cw.getTotalSalesForCity(args[2]));
System.out.println();
String[] properties = cw.getMostRecentPropertiesSold(Integer.parseInt(args[3]));
for (int i = 0; i < Integer.parseInt(args[3]); i++) {
System.out.println(properties[i] + ",");
}
System.out.println();
}
public String getProperty(int id) {
String property = "" + id;
if (props.containsKey(id)) {
List<String> details = props.get(id);
return "ID: " + details.get(0) + ", " + "City: " + details.get(1) + ", " + "Owner: " + details.get(2) + ", " + "Sale Price: " + details.get(3) + ", " + "Sale Date: " + details.get(4);
}
return property;
}
public String getTotalSalesForCity(String c) {
int total = 0;
for (List<String> details : props.values()) {
if (details.get(1).trim().equalsIgnoreCase(c.trim())) {
total += Integer.parseInt(details.get(3));
}
}
return "Total Sales for " + c + " = " + total;
}
public String[] getMostRecentPropertiesSold(int n) {
String[] properties = new String[n];
List<List<String>> propertyList = new ArrayList<>(props.values());
Collections.sort(propertyList, (p1, p2) -> p2.get(4).compareTo(p1.get(4)));
for (int i = 0; i < n && i < propertyList.size(); i++) {
List<String> details = propertyList.get(i);
properties[i] = "ID: " + details.get(0) + " " + "City: " + details.get(1) + " " + "Owner: " + details.get(2) + " " + "Sale Price: " + details.get(3) + " " + "Sale Date: " + details.get(4);
}
return properties;
}```