Last active
January 7, 2019 00:06
-
-
Save stuart-marks/66000c5fb1f019dc19b67ea970a788e1 to your computer and use it in GitHub Desktop.
Processing Large Files in Java, Variation 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- ReadFileJavaApplicationBufferedReader2.java | |
+++ ReadFileJavaApplicationBufferedReader3.java | |
@@ -44,6 +45,7 @@ | |
Instant commonNameStart = Instant.now(); | |
ArrayList<String> firstNames = new ArrayList<>(); | |
+ var namePat = Pattern.compile(", \\s*(([^ ]*), |([^ ]+))"); | |
System.out.println("Reading file using " + Caller.getName()); | |
@@ -55,20 +57,13 @@ | |
String name = array1[7].strip(); | |
names.add(name); | |
- if(name.contains(", ")) { | |
- | |
- String array2[] = (name.split(", ")); | |
- String firstHalfOfName = array2[1].trim(); | |
- | |
- if (!firstHalfOfName.isEmpty()) { | |
- if (firstHalfOfName.contains(" ")) { | |
- String array3[] = firstHalfOfName.split(" "); | |
- String firstName = array3[0].trim(); | |
- firstNames.add(firstName); | |
- } else { | |
- firstNames.add(firstHalfOfName); | |
- } | |
+ var matcher = namePat.matcher(name); | |
+ if (matcher.find()) { | |
+ String s = matcher.group(2); | |
+ if (s == null) { | |
+ s = matcher.group(3); | |
} | |
+ firstNames.add(s); | |
} | |
String rawDate = array1[4].strip(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment