Refactor Tokenizer (#1605)

This commit is contained in:
Grzegorz Piwowarek 2017-04-07 18:15:19 +02:00 committed by maibin
parent e7d81e6e98
commit 196ea6b5f7
1 changed files with 38 additions and 38 deletions

View File

@ -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 {
@ -23,19 +24,19 @@ public class Application {
return tokens;
}
public List<String> getTokensWithCollection( String str ) {
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;
}
}