Refactor Tokenizer
@@ -7,6 +7,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.StringTokenizer;
+import java.util.stream.Collectors;
public class Application {
@@ -25,17 +26,17 @@ public class Application {
public List<String> getTokensWithCollection(String str) {
StringTokenizer tokenizer = new StringTokenizer(str, ",");
- List<String> tokens = new ArrayList<String>();
- Collections.list(tokenizer).forEach(token -> tokens.add((String) token));
- return tokens;
+
+ return Collections.list(tokenizer).stream()
+ .map(token -> (String) token)
+ .collect(Collectors.toList());
}
public List<String> getTokensFromFile(String path, String delim) {
- List<String> tokens = new ArrayList<String>();
+ List<String> tokens = new ArrayList<>();
String currLine = "";
StringTokenizer tokenizer;
- try (BufferedReader br = new BufferedReader(
- new InputStreamReader(Application.class.getResourceAsStream("/" + path)))) {
+ try (BufferedReader br = new BufferedReader(new InputStreamReader(Application.class.getResourceAsStream("/" + path)))) {
while ((currLine = br.readLine()) != null) {
tokenizer = new StringTokenizer(currLine, delim);
while (tokenizer.hasMoreElements()) {
@@ -48,5 +49,4 @@ public class Application {
return tokens;
}
-
}
