forked from nus-cs2103-AY1920S1/addressbook-level3
/
AttendanceCommand.java
81 lines (66 loc) Β· 2.59 KB
/
AttendanceCommand.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
package seedu.address.logic.commands;
import static java.util.Objects.requireNonNull;
import java.util.List;
import seedu.address.commons.core.Messages;
import seedu.address.commons.core.index.Index;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Attendance;
import seedu.address.model.Model;
import seedu.address.model.person.Person;
/**
* Shows attendance of a person identified using it's displayed index from the address book.
*/
public class AttendanceCommand extends Command {
public static final String COMMAND_WORD = "attendance";
public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Checks attendance of person identified by the index number used in the displayed person list.\n"
+ "Parameters: INDEX (must be a positive integer)\n"
+ "Example: " + COMMAND_WORD + " 2";
public static final String MESSAGE_SUCCESS = "Attendance shown.";
/**
* Index of person identified.
*/
private Index index;
/**
* Constructor of AttendanceCommand.
* @param index Sets Index of person identified to {@code index}
*/
public AttendanceCommand(Index index) {
this.index = index;
}
/**
* Executes AttendanceCommand. Displays the attendance of Person specified by the index.
* @param model {@code Model} which the command should operate on.
* @return Outcome of executed command.
* @throws CommandException Thrown when specified index is invalid.
*/
@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
Attendance attendance = model.getAttendance();
List<Person> lastShownList = model.getFilteredPersonList();
if (index.getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
}
Person person = lastShownList.get(index.getZeroBased());
StringBuilder result = new StringBuilder();
result.append(MESSAGE_SUCCESS);
result.append("\n");
result.append(person.getName().toString());
result.append(": ");
result.append(attendance.getPersonAttendanceRateString(person));
return new CommandResult(result.toString());
}
/**
* Indicates whether an AttendanceCommand can be undone.
* @return Returns false as a AttendanceCommand is not undoable.
*/
@Override
public boolean isUndoable() {
return false;
}
@Override
public String toString() {
return "Attendance Command";
}
}