-
Notifications
You must be signed in to change notification settings - Fork 565
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from mohamedsaf1/branch-devguide
Update Teams implementation in Developer Guide
- Loading branch information
Showing
5 changed files
with
116 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/main/java/seedu/address/logic/commands/groups/GroupCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package seedu.address.logic.commands.groups; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import seedu.address.logic.commands.Command; | ||
import seedu.address.logic.commands.CommandResult; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.group.Group; | ||
|
||
/** | ||
* Add a team to the address book. | ||
*/ | ||
public class GroupCommand extends Command { | ||
public static final String COMMAND_WORD = "team"; | ||
|
||
public static final String MESSAGE_SUCCESS = "New team added: %1$s!"; | ||
public static final String MESSAGE_DUPLICATE_TEAM = "This team already exists in the address book"; | ||
|
||
private final Group toAdd; | ||
/** | ||
* Creates an AddCommand to add the specified {@code Person} | ||
*/ | ||
public GroupCommand(Group team) { | ||
requireNonNull(team); | ||
toAdd = team; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
|
||
if (model.hasTeam(toAdd)) { | ||
throw new CommandException(MESSAGE_DUPLICATE_TEAM); | ||
} | ||
|
||
model.addTeam(toAdd); | ||
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd)); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof GroupCommand // instanceof handles nulls | ||
&& toAdd.equals(((GroupCommand) other).toAdd)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,3 +117,4 @@ public Command parseCommand(String userInput) throws ParseException { | |
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import seedu.address.commons.core.Messages; | ||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.group.Group; | ||
|
||
import java.util.List; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
public class DeleteGroupCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "rmgroup"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD | ||
+ ": Deletes the group identified by the index number used in the displayed group list.\n" | ||
+ "Parameters: INDEX (must be a positive integer)\n" | ||
+ "Example: " + COMMAND_WORD + " 1"; | ||
|
||
public static final String MESSAGE_DELETE_GROUP_SUCCESS = "Deleted Group: %1$s"; | ||
|
||
private final Index targetIndex; | ||
|
||
public DeleteGroupCommand(Index targetIndex) { | ||
this.targetIndex = targetIndex; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
List<Group> lastShownList = model.getFilteredTeamList(); | ||
|
||
if (targetIndex.getZeroBased() >= lastShownList.size()) { | ||
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); | ||
} | ||
|
||
Group groupToDelete = lastShownList.get(targetIndex.getZeroBased()); | ||
model.deleteTeam(groupToDelete); | ||
return new CommandResult(String.format(MESSAGE_DELETE_GROUP_SUCCESS, groupToDelete)); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof DeleteCommand // instanceof handles nulls | ||
&& targetIndex.equals(((DeleteCommand) other).targetIndex)); // state check | ||
} | ||
} |