Skip to content

Commit

Permalink
Printing the compute time taken for entire program to finish
Browse files Browse the repository at this point in the history
  • Loading branch information
GShah9 committed Mar 1, 2017
1 parent 05da55d commit 0d2655b
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/main/java/com/postcode/BulkImport.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Instant;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -61,6 +62,7 @@ public String getHeaderString() {
public Map<Integer, String> readRecords() {
Map<Integer, String> postcodeMap = new HashMap<Integer, String>();
BufferedReader br = null;

try {
br = new BufferedReader(source);
setHeader(br.lines()
Expand All @@ -85,19 +87,23 @@ public static String toCsvRow(Map<Integer, String> records) {
.stream()
.map(map -> map.toString().replaceAll("=", ","))
.collect(Collectors.joining("\n"));

}

public static Map<Integer, String> postcodeValidity(Map<Integer, String> records) {
Map<Integer, String> newMap = new HashMap<Integer, String>();
//SortedMap<Integer, String> newMap = new TreeMap<>();

//Comparator<Map.Entry<Integer, String>> byKey = (entry1, entry2) -> entry1.getKey().compareTo(entry2.getKey());

records.entrySet()
.stream()
//.sorted(byKey)
.forEach(
postMap -> {
if (postMap.getValue() != null && !PostCodeValidator.isPostCode(postMap.getValue())) {
if (postMap.getValue() == null || !PostCodeValidator.isPostCode(postMap.getValue())) {
newMap.put(postMap.getKey(), postMap.getValue());
} else {
// add your map for valid postcodes
} else if (postMap.getValue() != null && PostCodeValidator.isPostCode(postMap.getValue())) {

}
}
);
Expand All @@ -117,6 +123,8 @@ public static void writeCsvFile(String fileNamePath, String header, String conte
}

public static void main(String[] args) {
final long startTime = Instant.now().toEpochMilli();

BulkImport bi = null;
try {
File file = new File("src/main/resources/import_data.csv");
Expand All @@ -132,5 +140,9 @@ public static void main(String[] args) {
//System.out.println(toCsvRow(records));
//writeCsvFile("testname.csv", bi.getHeaderString(), toCsvRow(records));
writeCsvFile("failed_validation.csv", bi.getHeaderString(), toCsvRow(postcodeValidity(records)));

final long stopTime = Instant.now().toEpochMilli();

System.out.println("Took: " + (stopTime - startTime) + "ms to complete the process");
}
}

0 comments on commit 0d2655b

Please sign in to comment.