Skip to content

Commit

Permalink
Merge pull request #216 from kohkaixun/final-changes
Browse files Browse the repository at this point in the history
Final changes
  • Loading branch information
eugenetangkj authored Apr 10, 2023
2 parents 5e3aff8 + cd3d7c5 commit 31d8932
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 39 deletions.
Binary file modified docs/images/dg-int-overflow-solution.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 6 additions & 11 deletions src/main/java/seedu/internship/logic/parser/CopyCommandParser.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package seedu.internship.logic.parser;

import static seedu.internship.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.internship.commons.core.Messages.MESSAGE_INVALID_INTERNSHIP_DISPLAYED_INDEX;

import seedu.internship.commons.core.index.Index;
import seedu.internship.logic.commands.CopyCommand;
import seedu.internship.logic.parser.exceptions.ParseException;
Expand All @@ -18,18 +15,16 @@ public class CopyCommandParser implements Parser<CopyCommand> {
* @throws ParseException if the user input does not conform the expected format
*/
public CopyCommand parse(String args) throws ParseException {
Index index;

try {
Index index = ParserUtil.parseIndex(args);
index = ParserUtil.parseIndex(args);
assert index.getZeroBased() > -1;
return new CopyCommand(index);
} catch (ParseException pe) {
if (pe.getMessage().equals(ParserUtil.MESSAGE_INVALID_INDEX)) {
throw new ParseException(MESSAGE_INVALID_INTERNSHIP_DISPLAYED_INDEX);
} else {
throw new ParseException(
String.format(MESSAGE_INVALID_COMMAND_FORMAT, CopyCommand.MESSAGE_USAGE), pe);
}
ParseException e = ParserUtil.handleIndexException(pe, CopyCommand.MESSAGE_USAGE);
throw e;
}
return new CopyCommand(index);
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package seedu.internship.logic.parser;

import static seedu.internship.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.internship.commons.core.Messages.MESSAGE_INVALID_INTERNSHIP_DISPLAYED_INDEX;
import static seedu.internship.commons.core.Messages.MESSAGE_MISSING_ARGUMENTS;

import java.util.List;
Expand All @@ -25,17 +23,17 @@ public DeleteIndexCommand parse(String args) throws ParseException {
if (args.trim().isEmpty()) {
throw new ParseException(String.format(MESSAGE_MISSING_ARGUMENTS, DeleteIndexCommand.MESSAGE_USAGE));
}

List<Index> indexes;

try {
List<Index> indexes = ParserUtil.parseIndexes(args);
indexes = ParserUtil.parseIndexes(args);
assert indexes != null;
return new DeleteIndexCommand(indexes);
} catch (ParseException pe) {
if (pe.getMessage().equals(ParserUtil.MESSAGE_INVALID_INDEX)) {
throw new ParseException(MESSAGE_INVALID_INTERNSHIP_DISPLAYED_INDEX);
} else {
throw new ParseException(
String.format(MESSAGE_INVALID_COMMAND_FORMAT, DeleteIndexCommand.MESSAGE_USAGE), pe);
}
ParseException e = ParserUtil.handleIndexException(pe, DeleteIndexCommand.MESSAGE_USAGE);
throw e;
}

return new DeleteIndexCommand(indexes);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@


import static java.util.Objects.requireNonNull;
import static seedu.internship.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.internship.commons.core.Messages.MESSAGE_INVALID_INTERNSHIP_DISPLAYED_INDEX;
import static seedu.internship.logic.parser.CliSyntax.PREFIX_COMMENT;
import static seedu.internship.logic.parser.CliSyntax.PREFIX_COMPANY_NAME;
import static seedu.internship.logic.parser.CliSyntax.PREFIX_DATE;
Expand Down Expand Up @@ -57,11 +55,8 @@ public EditCommand parse(String args) throws ParseException {
try {
index = ParserUtil.parseIndex(argMultimap.getPreamble());
} catch (ParseException pe) {
if (pe.getMessage().equals(ParserUtil.MESSAGE_INVALID_INDEX)) {
throw new ParseException(MESSAGE_INVALID_INTERNSHIP_DISPLAYED_INDEX);
} else {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE), pe);
}
ParseException e = ParserUtil.handleIndexException(pe, EditCommand.MESSAGE_USAGE);
throw e;
}

EditInternshipDescriptor editInternshipDescriptor = new EditCommand.EditInternshipDescriptor();
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/seedu/internship/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package seedu.internship.logic.parser;

import static java.util.Objects.requireNonNull;
import static seedu.internship.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.internship.commons.core.Messages.MESSAGE_INVALID_INTERNSHIP_DISPLAYED_INDEX;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -61,6 +63,20 @@ public static List<Index> parseIndexes(String oneBasedIndexes) throws ParseExcep
return result;
}

/**
* Checks index exception error messages and returns corresponding ParseException
* @param pe ParseException from parseIndex or parseIndexes method
* @param commandFormatMessage Command format message to be contained in ParseException if to be used
* @return New ParseException with the corresponding error message according to message in ParseException given
*/
public static ParseException handleIndexException(ParseException pe, String commandFormatMessage) {
if (pe.getMessage().equals(ParserUtil.MESSAGE_INVALID_INDEX)) {
return new ParseException(MESSAGE_INVALID_INTERNSHIP_DISPLAYED_INDEX);
}
return new ParseException(
String.format(MESSAGE_INVALID_COMMAND_FORMAT, commandFormatMessage), pe);
}

/**
* Parses a {@code String companyName} into a {@code CompanyName}.
* Leading and trailing whitespaces will be trimmed.
Expand Down
18 changes: 7 additions & 11 deletions src/main/java/seedu/internship/logic/parser/ViewCommandParser.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package seedu.internship.logic.parser;

import static seedu.internship.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.internship.commons.core.Messages.MESSAGE_INVALID_INTERNSHIP_DISPLAYED_INDEX;

import seedu.internship.commons.core.index.Index;
import seedu.internship.logic.commands.ViewCommand;
import seedu.internship.logic.parser.exceptions.ParseException;
Expand All @@ -18,17 +15,16 @@ public class ViewCommandParser implements Parser<ViewCommand> {
* @throws ParseException if the user input does not conform the expected format
*/
public ViewCommand parse(String args) throws ParseException {
Index index;

try {
Index index = ParserUtil.parseIndex(args);
return new ViewCommand(index);
index = ParserUtil.parseIndex(args);
} catch (ParseException pe) {
if (pe.getMessage().equals(ParserUtil.MESSAGE_INVALID_INDEX)) {
throw new ParseException(MESSAGE_INVALID_INTERNSHIP_DISPLAYED_INDEX);
} else {
throw new ParseException(
String.format(MESSAGE_INVALID_COMMAND_FORMAT, ViewCommand.MESSAGE_USAGE), pe);
}
ParseException e = ParserUtil.handleIndexException(pe, ViewCommand.MESSAGE_USAGE);
throw e;
}

return new ViewCommand(index);
}

}

0 comments on commit 31d8932

Please sign in to comment.