Skip to content

Commit 555c522

Browse files
author
austenjs
committed
add doneCommand-related-classes
1 parent 39fa93a commit 555c522

3 files changed

Lines changed: 126 additions & 0 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package seedu.address.logic.commands;
2+
3+
import static java.util.Objects.requireNonNull;
4+
5+
import java.util.List;
6+
7+
import seedu.address.commons.core.Messages;
8+
import seedu.address.commons.core.index.Index;
9+
import seedu.address.logic.commands.exceptions.CommandException;
10+
import seedu.address.model.Model;
11+
import seedu.address.model.person.Person;
12+
13+
/**
14+
* Finishes a task identified using it's displayed index from the task list.
15+
*/
16+
public class DoneCommand extends Command {
17+
18+
public static final String COMMAND_WORD = "done";
19+
20+
public static final String MESSAGE_USAGE = COMMAND_WORD
21+
+ ": Finishes the task identified by the index number used in the displayed task list.\n"
22+
+ "Parameters: INDEX (must be a positive integer)\n"
23+
+ "Example: " + COMMAND_WORD + " 1";
24+
25+
public static final String MESSAGE_DONE_TASK_SUCCESS = "Finished Task: %1$s";
26+
27+
private final Index targetIndex;
28+
29+
public DoneCommand(Index targetIndex) {
30+
this.targetIndex = targetIndex;
31+
}
32+
33+
@Override
34+
public CommandResult execute(Model model) throws CommandException {
35+
requireNonNull(model);
36+
List<Person> lastShownList = model.getFilteredPersonList(); //Change to list of task later
37+
38+
if (targetIndex.getZeroBased() >= lastShownList.size()) {
39+
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
40+
}
41+
42+
Person taskToFinish = lastShownList.get(targetIndex.getZeroBased());
43+
model.deletePerson(taskToFinish); // change to finishTask later
44+
return new CommandResult(String.format(MESSAGE_DONE_TASK_SUCCESS, taskToFinish));
45+
}
46+
47+
@Override
48+
public boolean equals(Object other) {
49+
return other == this // short circuit if same object
50+
|| (other instanceof DoneCommand // instanceof handles nulls
51+
&& targetIndex.equals(((DoneCommand) other).targetIndex)); // state check
52+
}
53+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package seedu.address.logic.parser;
2+
3+
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
4+
5+
import seedu.address.commons.core.index.Index;
6+
import seedu.address.logic.commands.DoneCommand;
7+
import seedu.address.logic.parser.exceptions.ParseException;
8+
9+
/**
10+
* Parses input arguments and creates a new DoneComment object
11+
*/
12+
public class DoneCommandParser implements Parser<DoneCommand> {
13+
14+
/**
15+
* Parses the given {@code String} of arguments in the context of the DoneCommand
16+
* and returns a DoneCommand object for execution.
17+
* @throws ParseException if the user input does not conform the expected format
18+
*/
19+
public DoneCommand parse(String args) throws ParseException {
20+
try {
21+
Index index = ParserUtil.parseIndex(args);
22+
return new DoneCommand(index);
23+
} catch (ParseException pe) {
24+
throw new ParseException(
25+
String.format(MESSAGE_INVALID_COMMAND_FORMAT, DoneCommand.MESSAGE_USAGE), pe);
26+
}
27+
}
28+
29+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package seedu.address.model.person;
2+
3+
/**
4+
* Represents a Task's status in the task list.
5+
*/
6+
7+
public class Status {
8+
9+
private boolean isDone;
10+
11+
/**
12+
* Constructs a {@code Status}.
13+
*/
14+
public Status() {
15+
this.isDone = false;
16+
}
17+
18+
/**
19+
* Returns true if isDone is true.
20+
*/
21+
public boolean hasFinished() {
22+
return this.isDone;
23+
}
24+
25+
/**
26+
* Mark the task's status as finished.
27+
*/
28+
public void finishTask() {
29+
this.isDone = true;
30+
}
31+
32+
@Override
33+
public String toString() {
34+
return isDone ? "Finished" : "Unfinished";
35+
}
36+
37+
@Override
38+
public boolean equals(Object other) {
39+
return other == this // short circuit if same object
40+
|| (other instanceof Address // instanceof handles nulls
41+
&& (isDone == (((Status) other).isDone))); // state check
42+
}
43+
44+
}

0 commit comments

Comments
 (0)