forked from nus-cs2103-AY1819S2/addressbook-level4
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Model.java
executable file
·296 lines (237 loc) · 8.17 KB
/
Model.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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
package seedu.knowitall.model;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Comparator;
import java.util.List;
import java.util.function.Predicate;
import javafx.beans.Observable;
import javafx.beans.property.ReadOnlyProperty;
import javafx.collections.ObservableList;
import javafx.collections.transformation.FilteredList;
import seedu.knowitall.commons.core.GuiSettings;
import seedu.knowitall.logic.commands.exceptions.CommandException;
import seedu.knowitall.model.card.Answer;
import seedu.knowitall.model.card.Card;
import seedu.knowitall.storage.csvmanager.CsvFile;
import seedu.knowitall.storage.csvmanager.exceptions.CsvManagerNotInitialized;
import seedu.knowitall.storage.csvmanager.exceptions.IncorrectCsvHeadersException;
/**
* The API of the Model component.
*/
public interface Model extends Observable {
/** {@code Predicate} that always evaluate to true */
Predicate<Card> PREDICATE_SHOW_ALL_CARDS = unused -> true;
/** {@code Comparator} that sorts cards by ascending percentage score */
Comparator<Card> COMPARATOR_ASC_SCORE_CARDS = Comparator.comparing(Card::getScore);
/** {@code Comparator} that sorts cards by lexicographic order of questions */
Comparator<Card> COMPARATOR_LEXICOGRAPHIC_CARDS = Comparator.comparing(Card::getQuestion);
/**
* Minimum fraction of number of cards, i.e. if n, then floor(number of cards/n) cards need to be attempted for
* the test score to be committed.
*/
int MIN_FRACTION_ANSWERED_TO_COUNT = 4;
/**
* Represents the location the user is in.
*/
enum State {
IN_FOLDER,
IN_HOMEDIR,
IN_TEST,
IN_REPORT,
}
/**
* Replaces user prefs data with the data in {@code userPrefs}.
*/
void setUserPrefs(ReadOnlyUserPrefs userPrefs);
/**
* Returns the user prefs.
*/
ReadOnlyUserPrefs getUserPrefs();
/**
* Returns the user prefs' GUI settings.
*/
GuiSettings getGuiSettings();
/**
* Sets the user prefs' GUI settings.
*/
void setGuiSettings(GuiSettings guiSettings);
/**
* Returns the user prefs' card folder file path.
*/
Path getcardFolderFilesPath();
/**
* Sets the user prefs' card folder file path.
*/
void setcardFolderFilesPath(Path cardFolderFilesPath);
/**
* Replaces card folder data with the data in {@code cardFolder}.
*/
void resetCardFolder(ReadOnlyCardFolder cardFolder);
/** Returns the name of the active {@code CardFolder} */
String getActiveCardFolderName();
/** Returns the active {@code CardFolder} */
ReadOnlyCardFolder getActiveCardFolder();
/** Returns all {@code CardFolders} */
List<ReadOnlyCardFolder> getCardFolders();
/**
* Returns true if a card with the same identity as {@code card} exists in the card folder.
*/
boolean hasCard(Card card);
/**
* Deletes the given card.
* The card must exist in the card folder.
*/
void deleteCard(Card target);
/**
* Adds the given card.
* {@code card} must not already exist in the card folder.
*/
void addCard(Card card);
/**
* Replaces the given card {@code target} with {@code editedCard}.
* {@code target} must exist in the card folder.
* The card identity of {@code editedCard} must not be the same as another existing card in the card folder.
*/
void setCard(Card target, Card editedCard);
/**
* Removes the selected card, if any.
*/
void removeSelectedCard();
/**
* Returns true if a{@code CardFolder} with the same name as {@code folderName} exists.
*/
boolean hasFolder(String name);
/**
* Deletes the folder at the given index.
* The folder must exist.
*/
void deleteFolder(int index);
/**
* Adds the given folder.
* {@code cardFolder} must not already exist.
*/
void addFolder(CardFolder cardFolder);
/**
* Renames the folder at the given index to the string passed.
* {@code newName} must not be the name of an existing folder.
*/
void renameFolder(int index, String newName);
/**
* Gets the index of the current active {@code CardFolder}.
*/
int getActiveCardFolderIndex();
/**
* Enters the folder at the specified {@code index}.
*/
void enterFolder(int index);
/**
* Sets the Model back to the home directory, outside of any {@code CardFolder}.
*/
void exitFolderToHome();
/** Returns a copy of the filtered cards list */
List<FilteredList<Card>> getFilteredCardsList();
/** Returns a copy of the active filtered cards */
ObservableList<Card> getActiveFilteredCards();
/** Returns a copy of the filtered folders list */
ObservableList<VersionedCardFolder> getFilteredFolders();
/**
* Updates the filter of the filtered card list to filter by the given {@code predicate}.
* @throws NullPointerException if {@code predicate} is null.
*/
void updateFilteredCard(Predicate<Card> predicate);
/**
* Updates the filter of the filtered card list to filter by the given {@code predicate}.
* @throws NullPointerException if {@code predicate} is null.
*/
void sortFilteredCard(Comparator<Card> cardComparator);
/**
* Returns true if the model has previous card folder states to restore.
*/
boolean canUndoActiveCardFolder();
/**
* Returns true if the model has undone card folder states to restore.
*/
boolean canRedoActiveCardFolder();
/**
* Restores the model's card folder to its previous state.
*/
void undoActiveCardFolder();
/**
* Restores the model's card folder to its previously undone state.
*/
void redoActiveCardFolder();
/**
* Saves the current card folder state for undo/redo.
*/
void commitActiveCardFolder();
/**
* Selected card in the filtered card list.
* null if no card is selected.
*/
ReadOnlyProperty<Card> selectedCardProperty();
/**
* Returns the selected card in the filtered card list.
* null if no card is selected.
*/
Card getSelectedCard();
/**
* Sets the selected card in the filtered card list.
*/
void setSelectedCard(Card card);
/**
* Enters a test session using the specified card folder index.
*/
void startTestSession();
/**
* Sets the current card in the test session.
*/
void setCurrentTestedCard(Card card);
/**
* Returns the current card in the test session
* null if there is no cards in folder or user is not in a test session.
*/
Card getCurrentTestedCard();
/**
* End the current test session.
*/
void endTestSession();
/**
* Test the next card in the current folder in this test session.
* Returns true if successfully found next card,
* false if there is no next card.
*/
boolean testNextCard();
/**
* Returns true if the given answer is right
* false if answer is wrong
*/
boolean markAttemptedAnswer(Answer attemptedAnswer);
/**
*
* @param cardToMark {@code Card} which is being marked correct or wrong
* @param markCorrect Boolean representing if card should be graded correct or wrong
* @return Card created with new score
*/
Card createScoredCard(Card cardToMark, boolean markCorrect);
/**
* Returns true if the index provided matches the answerIndex of the currently tested card,
* false otherwise.
*/
boolean markAttemptedMcqAnswer(int answerIndex);
/**
* Set cardAlreadyAnswered variable to true to indicate current card as answered
*/
void setCardAsAnswered();
/**
* Returns true if the answer has already been input for that card
* false if otherwise
*/
boolean isCardAlreadyAnswered();
State getState();
void exportCardFolders(List<Integer> cardFolderExports) throws IOException, CsvManagerNotInitialized;
void importCardFolders(CsvFile csvFile) throws IOException, CommandException, IncorrectCsvHeadersException;
void enterReportDisplay();
void exitReportDisplay();
void setTestCsvPath(String path);
String getDefaultPath();
}