Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Javadoc comments #221

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public class AnalyticsCommand extends Command {
public static final String MESSAGE_SUCCESS = "Analytics generated";
private final Index targetIndex;

/**
* @param targetIndex The index of the person to view analytics for.
*/
public AnalyticsCommand(Index targetIndex) {
this.targetIndex = targetIndex;
}
Expand All @@ -35,6 +38,7 @@ public AnalyticsCommand(Index targetIndex) {
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
List<Person> lastShownList = model.getFilteredPersonList();
assert lastShownList != null;

if (targetIndex.getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class DeleteLoanCommand extends Command {

/**
* Creates a DeleteLoanCommand to delete the specified loan.
* @param loanIndex index of the loan in the last shown loan list.
* @param loanIndex Index of the loan in the last shown loan list.
*/
public DeleteLoanCommand(Index loanIndex) {
requireAllNonNull(loanIndex);
Expand All @@ -37,8 +37,8 @@ public DeleteLoanCommand(Index loanIndex) {
@Override
public CommandResult execute(Model model) throws CommandException {
List<Loan> lastShownList = model.getSortedLoanList();
assert lastShownList != null;
if (loanIndex.getZeroBased() >= lastShownList.size()) {
// in reality, it's loan index outside of list range. We will be concerned about it later.
throw new CommandException(String.format(MESSAGE_FAILURE_LOAN, loanIndex.getOneBased()));
}
// delete specified loan number
Expand All @@ -48,8 +48,7 @@ public CommandResult execute(Model model) throws CommandException {
}

/**
* Generates a command execution success message after loan is deleted from the
* {@code personToEdit}.
* Generates a command execution success message after loan is deleted.
*/
private String generateSuccessMessage(Loan removedLoan) {
return String.format(MESSAGE_SUCCESS, removedLoan);
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/seedu/address/logic/commands/EditLoanCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,11 @@ public CommandResult execute(Model model) throws CommandException {

Loan loanToEdit = lastShownList.get(loanIndex.getZeroBased());
Person linkedPerson = loanToEdit.getAssignee();
// Generate updated details of the loan
LinkLoanDescriptor updatedLoanDetails = generateEditedLoanDetails(loanToEdit, editedDetails);
// Delete the old loan
model.deleteLoan(loanToEdit);
// Create and link a new loan using the updated loan details
Loan editedLoan = model.addLoan(updatedLoanDetails, linkedPerson);

return new CommandResult(generateSuccessMessage(editedLoan), false, false, true);
Expand All @@ -93,6 +96,14 @@ private String generateSuccessMessage(Loan editedLoan) {
return String.format(MESSAGE_SUCCESS, editedLoan);
}

/**
* Generates the new loan details in the form of a LinkLoanDescriptor.
*
* @param loanToEdit The original loan that was edited.
* @param editedDetails The details of the loan that were changed.
* @return All details of the new loan, including the changed and unchanged details.
* @throws CommandException If the edited date(s) are invalid.
*/
private LinkLoanDescriptor generateEditedLoanDetails(Loan loanToEdit, EditLoanDescriptor editedDetails)
throws CommandException {
BigDecimal newValue = editedDetails.getValue().orElse(loanToEdit.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public LinkLoanCommand(LinkLoanDescriptor loanDescription, Index index) {
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
List<Person> lastShownList = model.getFilteredPersonList();
assert lastShownList != null;

if (linkTarget.getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/seedu/address/logic/commands/MarkLoanCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public class MarkLoanCommand extends Command {
private final Index loanIndex;

/**
* Creates a MarkLoanCommand to delete the specified loan.
* @param loanIndex
* Creates a MarkLoanCommand to mark the specified loan.
* @param loanIndex Index of the loan in the last shown loan list.
*/
public MarkLoanCommand(Index loanIndex) {
requireAllNonNull(loanIndex);
Expand All @@ -38,19 +38,18 @@ public MarkLoanCommand(Index loanIndex) {
@Override
public CommandResult execute(Model model) throws CommandException {
List<Loan> lastShownList = model.getSortedLoanList();
assert lastShownList != null;
if (loanIndex.getZeroBased() >= lastShownList.size()) {
// in reality, it's loan index outside of list range. We will be concerned about it later.
throw new CommandException(String.format(MESSAGE_FAILURE_LOAN, loanIndex.getOneBased()));
}
// delete specified loan number
// mark specified loan number
Loan loanToMark = lastShownList.get(loanIndex.getZeroBased());
model.markLoan(loanToMark);
return new CommandResult(generateSuccessMessage(loanToMark), false, false, true);
}

/**
* Generates a command execution success message after loan is deleted from the
* {@code personToEdit}.
* Generates a command execution success message after loan is marked.
*/
private String generateSuccessMessage(Loan markedLoan) {
return String.format(MESSAGE_SUCCESS, markedLoan);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public class UnmarkLoanCommand extends Command {
private final Index loanIndex;

/**
* Creates a UnmarkLoanCommand to delete the specified loan.
* @param loanIndex
* Creates a UnmarkLoanCommand to unmark the specified loan.
* @param loanIndex Index of the loan in the last shown loan list.
*/
public UnmarkLoanCommand(Index loanIndex) {
requireAllNonNull(loanIndex);
Expand All @@ -37,19 +37,18 @@ public UnmarkLoanCommand(Index loanIndex) {
@Override
public CommandResult execute(Model model) throws CommandException {
List<Loan> lastShownList = model.getSortedLoanList();
assert lastShownList != null;
if (loanIndex.getZeroBased() >= lastShownList.size()) {
// in reality, it's loan index outside of list range. We will be concerned about it later.
throw new CommandException(String.format(MESSAGE_FAILURE_LOAN, loanIndex.getOneBased()));
}
// delete specified loan number
// unmark specified loan number
Loan loanToUnmark = lastShownList.get(loanIndex.getZeroBased());
model.unmarkLoan(loanToUnmark);
return new CommandResult(generateSuccessMessage(loanToUnmark), false, false, true);
}

/**
* Generates a command execution success message after loan is deleted from the
* {@code personToEdit}.
* Generates a command execution success message after loan is unmarked.
*/
private String generateSuccessMessage(Loan markedLoan) {
return String.format(MESSAGE_SUCCESS, markedLoan);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public ViewLoanCommand(Index targetIndex, boolean isShowAllLoans) {
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
List<Person> lastShownList = model.getFilteredPersonList();
assert lastShownList != null;

if (targetIndex.getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
* Lists all active loans in the address book to the user.
*/
public class ViewLoansCommand extends ViewLoanRelatedCommand {
public static final String COMMAND_WORD = "viewloans";

public static final String MESSAGE_SUCCESS = "Listed all loans";

/**
* @param isShowAllLoans Whether to show all loans or only active loans.
*/
public ViewLoansCommand(boolean isShowAllLoans) {
super(isShowAllLoans);
}
Expand Down
Loading