-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
78 lines (66 loc) · 2.42 KB
/
Copy pathMain.java
File metadata and controls
78 lines (66 loc) · 2.42 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main;
import checker.Checker;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.fasterxml.jackson.databind.node.ArrayNode;
import checker.CheckerConstants;
import fileio.Input;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Objects;
/**
* The entry point to this homework. It runs the checker that tests your implentation.
*/
public final class Main {
/**
* for coding style
*/
private Main() {
}
/**
* DO NOT MODIFY MAIN METHOD
* Call the checker
* @param args from command line
* @throws IOException in case of exceptions to reading / writing
*/
public static void main(final String[] args) throws IOException {
File directory = new File(CheckerConstants.TESTS_PATH);
Path path = Paths.get(CheckerConstants.RESULT_PATH);
if (Files.exists(path)) {
File resultFile = new File(String.valueOf(path));
for (File file : Objects.requireNonNull(resultFile.listFiles())) {
file.delete();
}
resultFile.delete();
}
Files.createDirectories(path);
for (File file : Objects.requireNonNull(directory.listFiles())) {
String filepath = CheckerConstants.OUT_PATH + file.getName();
File out = new File(filepath);
boolean isCreated = out.createNewFile();
if (isCreated) {
action(file.getName(), filepath);
}
}
Checker.calculateScore();
}
/**
* @param filePath1 for input file
* @param filePath2 for output file
* @throws IOException in case of exceptions to reading / writing
*/
public static void action(final String filePath1,
final String filePath2) throws IOException {
ObjectMapper objectMapper = new ObjectMapper();
Input inputData = objectMapper.readValue(new File(CheckerConstants.TESTS_PATH + filePath1),
Input.class);
ArrayNode output = objectMapper.createArrayNode();
GameManager gameManager = new GameManager(inputData, output);
output = gameManager.generateOutput();
ObjectWriter objectWriter = objectMapper.writerWithDefaultPrettyPrinter();
objectWriter.writeValue(new File(filePath2), output);
}
}