-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathApp.java
More file actions
35 lines (29 loc) · 1.26 KB
/
App.java
File metadata and controls
35 lines (29 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import org.example.volunteers.Cleaner;
import org.example.volunteers.Volunteer;
import org.example.volunteers.utils.FieldsSanitizer;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import static java.util.stream.Collectors.toList;
public class App {
public static void main(String[] args) throws IOException {
Pattern quotes = Pattern.compile("^\"([^\"]*)\"$");
List<Volunteer> inputVolunteers = Files.readAllLines(Paths.get(args[0])).stream()
.map(string -> Arrays.stream(string.split(";", -1))
.map(token -> quotes.matcher(token).replaceAll("$1"))
.collect(toList()))
.map(tokens -> new Volunteer(tokens.get(0), tokens.get(1), tokens.get(2), tokens.get(3), tokens.get(4)))
.collect(toList());
List<Volunteer> outputVolunteers = Cleaner.cleanUp(inputVolunteers, new FieldsSanitizer());
PrintWriter writer = new PrintWriter(new FileWriter("src/main/resources/output.csv"));
outputVolunteers.forEach(writer::println);
writer.close();
}
}