-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.java
81 lines (68 loc) · 2.08 KB
/
main.java
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
79
80
81
import java.io.*;
import java.util.*;
public class main {
private static ArrayList<Objective> unsorted = new ArrayList<Objective>();
private static ArrayList<ArrayList<Objective>> sorted = new ArrayList<ArrayList<Objective>>();
private static Scanner input = new Scanner(System.in);
public static void main(String[] args) {
System.out.print("Input file: ");
String file = input.nextLine();
if(file.startsWith("\"")) {
file = file.substring(1,file.length()-1);
}
try {
Scanner in = new Scanner(new File(file));
in.nextLine();
while(in.hasNextLine()) {
String value = in.nextLine();
String[] values = value.split("\t");
if(values.length >=2) {
int tier = Integer.parseInt(values[0]);
String name = values[1];
ArrayList<String> tags = new ArrayList<String>(); // separate tags
for(int i=2; i<values.length;i++) {
tags.add(values[i]);
}
Objective obj = new Objective(tier, name, tags);
unsorted.add(obj);
}
}
// create tiers
for(int i=0; i<25; i++) {
sorted.add(new ArrayList<Objective>());
}
// sort objectives into tiers
for(Objective obj: unsorted) {
sorted.get(obj.tier-1).add(obj);
}
String srl = generateSRL(sorted);
PrintWriter out = new PrintWriter(new FileOutputStream(new File("SRL.json")));
out.print(srl);
out.close();
System.out.print("SRL.json generated.\nPress [ENTER] to close.");
input.nextLine();
}
catch(IOException e)
{
System.out.println(e);
}
catch(Exception e)
{
System.out.println(e);
}
}
private static String generateSRL(ArrayList<ArrayList<Objective>> objectives) {
String output = "[\n";
for(ArrayList<Objective> objtier: objectives) {
output += "\t[\n";
for(Objective obj: objtier) {
output += "\t\t" + obj.toString() + ",\n";
}
output = output.substring(0, output.length()-2) + "\n";
output += "\t],\n";
}
output = output.substring(0, output.length()-2) + "\n";
output += "]";
return output;
}
}