-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathApp.java
More file actions
executable file
·47 lines (40 loc) · 2.02 KB
/
App.java
File metadata and controls
executable file
·47 lines (40 loc) · 2.02 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
36
37
38
39
40
41
42
43
44
45
46
47
import org.example.volunteers.Cleaner;
import org.example.volunteers.Volunteer;
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> inputVolunteersForUnique = 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);
List<Volunteer> outputVolunteersUnique = Cleaner.cleanUpUniqueContact(inputVolunteersForUnique);
System.out.println(outputVolunteers);
System.out.println(outputVolunteersUnique);
PrintWriter writer = new PrintWriter(new FileWriter("src/main/resources/output.csv"));
PrintWriter writerUnique = new PrintWriter(new FileWriter("src/main/resources/outputUnique.csv"));
outputVolunteers.forEach(writer::println);
outputVolunteersUnique.forEach(writerUnique::println);
writer.close();
writerUnique.close();
}
}