-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form.java
237 lines (197 loc) · 6 KB
/
Form.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
import java.util.ArrayList;
import java.util.Collection;
public class Form {
private String rawForm;
private FormType formType;
private int tabletNum;
private int teamNum;
private int matchNum;
private String scoutName;
// database report id
private int reportID;
ArrayList<Record> records;
public static final String FORM_DELIMITER = "||";
public static final String ITEM_DELIMITER = "|";
public static final String ID_DELIMITER = ",";
public enum FormType {
PRESCOUTING_FORM, MATCH_FORM
}
public static final class FormOrder {
public static final int FORM_TYPE = 0;
public static final int TABLET_NUM = 1;
public static final int SCOUT_NAME = 2;
public static final int TEAM_NUM = 3;
public static final int MATCH_NUM = 4;
public static final int highestIndex() {
return MATCH_NUM;
}
}
public Form(FormType formType, int tabletNum, int teamNum, String scoutName) {
this.formType = formType;
this.tabletNum = tabletNum;
this.teamNum = teamNum;
this.matchNum = -1;
this.scoutName = scoutName;
this.reportID = -1;
records = new ArrayList<>();
this.rawForm = null;
}
public Form(FormType formType, int tabletNum, int teamNum, int matchNum, String scoutName) {
this.formType = formType;
this.tabletNum = tabletNum;
this.teamNum = teamNum;
this.matchNum = matchNum;
this.scoutName = scoutName;
this.reportID = -1;
records = new ArrayList<>();
this.rawForm = null;
}
public Form(int reportID, FormType formType, int tabletNum, int teamNum, String scoutName) {
this.formType = formType;
this.tabletNum = tabletNum;
this.teamNum = teamNum;
this.matchNum = -1;
this.scoutName = scoutName;
this.reportID = reportID;
records = new ArrayList<>();
this.rawForm = null;
}
public Form(int reportID, FormType formType, int tabletNum, int teamNum, int matchNum, String scoutName) {
this.formType = formType;
this.tabletNum = tabletNum;
this.teamNum = teamNum;
this.matchNum = matchNum;
this.scoutName = scoutName;
this.reportID = reportID;
records = new ArrayList<>();
this.rawForm = null;
}
public Form(String rawForm) {
this.rawForm = rawForm;
records = new ArrayList<>();
breakDownForm(this);
}
public String getRawForm() {
return rawForm;
}
public void setRawForm(String rawForm) {
this.rawForm = rawForm;
breakDownForm(this);
}
public FormType getFormType() {
return formType;
}
public int getTabletNum() {
return tabletNum;
}
public int getTeamNum() {
return teamNum;
}
public int getFormID() {
return reportID;
}
public int getMatchNum() {
return matchNum;
}
public void setMatchNum(int matchNum) {
this.matchNum = matchNum;
}
public void setFormType(FormType formType) {
this.formType = formType;
}
public void setTabletNum(int tabletNum) {
this.tabletNum = tabletNum;
}
public void setTeamNum(int teamNum) {
this.teamNum = teamNum;
}
public void setFormID(int reportID) {
this.reportID = reportID;
}
public String getScoutName() {
return scoutName;
}
public void setScoutName(String scoutName) {
this.scoutName = scoutName;
}
public ArrayList<Record> getAllRecords() {
return records;
}
public Record getRecord(int index) {
return records.get(index);
}
public boolean addRecord(Record record) {
return records.add(record);
}
public boolean addRecords(Collection<? extends Record> records) {
return this.records.addAll(records);
}
public boolean addRecords(Record[] records) {
boolean bool = true;
for (int i = 0; i < records.length; i++)
if (this.records.add(records[i]) == false) bool = false;
return bool;
}
public Record[] addRecords(String rawRecords) {
rawForm += "|" + rawRecords;
this.addRecords(breakDownRecords(rawRecords, this.formType));
return null;
}
public boolean removeRecord(Record record) {
return records.remove(record);
}
public Record removeRecord(int index) {
return records.remove(index);
}
public boolean removeRecords(Collection<? extends Record> records) {
return this.records.removeAll(records);
}
public boolean removeRecords(Record[] records) {
boolean bool = true;
for (int i = 0; i < records.length; i++)
if (this.records.remove(records[i]) == false) bool = false;
return bool;
}
private static void breakDownForm(Form form) {
String rawForm = form.getRawForm();
if (rawForm != null) {
String[] items = rawForm.split("\\" + ITEM_DELIMITER);
int type = Integer.parseInt(items[FormOrder.FORM_TYPE]);
if (type == FormType.MATCH_FORM.ordinal()) form.setFormType(FormType.MATCH_FORM);
else if (type == FormType.PRESCOUTING_FORM.ordinal()) form.setFormType(FormType.PRESCOUTING_FORM);
form.setTabletNum(Integer.parseInt(items[FormOrder.TABLET_NUM]));
form.setTeamNum(Integer.parseInt(items[FormOrder.TEAM_NUM]));
form.setScoutName(items[FormOrder.SCOUT_NAME]);
form.setMatchNum(Integer.parseInt(items[FormOrder.MATCH_NUM]));
String rawRecords = "";
for (int i = 0; i < items.length-(FormOrder.highestIndex()+1); i++) {
if (i == 0) rawRecords += items[FormOrder.highestIndex()+i+1];
else rawRecords += ITEM_DELIMITER + items[FormOrder.highestIndex()+i+1];
}
if (!rawRecords.isEmpty()) form.addRecords(breakDownRecords(rawRecords, form.getFormType()));
}
}
private static Record[] breakDownRecords(String rawRecords, FormType type) {
ArrayList<Record> formRecords = new ArrayList<>();
String[] records = rawRecords.split("\\" + ITEM_DELIMITER);
for (String record : records) {
String[] elements = record.split("\\" + ID_DELIMITER);
formRecords.add(new Record(elements[1], Integer.parseInt(elements[0])));
}
return formRecords.toArray(new Record[0]);
}
@Override
public String toString() {
if (rawForm != null) return rawForm;
else {
rawForm = formType + ITEM_DELIMITER;
rawForm += tabletNum + ITEM_DELIMITER;
rawForm += scoutName + ITEM_DELIMITER;
rawForm += teamNum + ITEM_DELIMITER;
rawForm += matchNum;
for (int i = 0; i < records.size(); i++)
rawForm += ITEM_DELIMITER + records.get(i).toString();
return rawForm;
}
}
}