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

Bug Fix: Edit with same fields, Wrong status, Company Case Sensitivity #200

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
6 changes: 4 additions & 2 deletions src/main/java/seedu/internship/commons/core/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ public class Messages {

public static final String MESSAGE_UNKNOWN_COMMAND = "Unknown command";
public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format! \n%1$s";
public static final String MESSAGE_INVALID_INTERNSHIP_DISPLAYED_INDEX = "The internship index provided is invalid";
public static final String MESSAGE_INVALID_EVENT_DISPLAYED_INDEX = "The event index provided is invalid";
public static final String MESSAGE_INVALID_INTERNSHIP_DISPLAYED_INDEX =
"The internship index provided is out of range";
public static final String MESSAGE_INVALID_EVENT_DISPLAYED_INDEX =
"The event index provided is out of range";

}
11 changes: 11 additions & 0 deletions src/main/java/seedu/internship/commons/util/StringUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ public static String getDetails(Throwable t) {
return t.getMessage() + "\n" + sw.toString();
}

public static boolean isInteger(String s) {
requireNonNull(s);

try {
int value = Integer.parseInt(s);
return true;
} catch (NumberFormatException nfe) {
return false;
}
}

/**
* Returns true if {@code s} represents a non-zero unsigned integer
* e.g. 1, 2, 3, ..., {@code Integer.MAX_VALUE} <br>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class EditCommand extends Command {

public static final String MESSAGE_EDIT_INTERNSHIP_SUCCESS = "Edited Internship: %1$s";
public static final String MESSAGE_NOT_EDITED = "At least one field to edit must be provided.";
public static final String MESSAGE_INTERNSHIP_UNCHANGED = "Internship is unchanged";
public static final String MESSAGE_DUPLICATE_INTERNSHIP = "This internship already exists "
+ "in the internship catalogue.";

Expand Down Expand Up @@ -81,10 +82,16 @@ public CommandResult execute(Model model) throws CommandException {
Internship internshipToEdit = lastShownList.get(index.getZeroBased());
Internship editedInternship = createEditedInternship(internshipToEdit, editInternshipDescriptor);

// if another internship other than internshipToEdit has same Position and Company as editedInternship
if (!internshipToEdit.isSameInternship(editedInternship) && model.hasInternship(editedInternship)) {
throw new CommandException(MESSAGE_DUPLICATE_INTERNSHIP);
}

// if internshipToEdit is not changed.
if (internshipToEdit.equals(editedInternship)) {
throw new CommandException(MESSAGE_INTERNSHIP_UNCHANGED);
}

model.setInternship(internshipToEdit, editedInternship);
model.updateFilteredInternshipList(PREDICATE_SHOW_ALL_INTERNSHIPS);
model.updateSelectedInternship(editedInternship);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
public class EventDeleteCommand extends EventCommand {
public static final String COMMAND_WORD = "delete";
public static final String MESSAGE_USAGE = EventCommand.COMMAND_WORD + " "
+ EventDeleteCommand.COMMAND_WORD + ": Deletes a event to the event catalogue. \n"
+ "Parameters: "
+ "Index of Delete Command\n"
+ EventDeleteCommand.COMMAND_WORD + ": Deletes an event in the event catalogue. \n"
+ "Parameters: EVENT_INDEX (must be a positive integer)\n"
+ "Example: " + EventCommand.COMMAND_WORD + " "
+ EventDeleteCommand.COMMAND_WORD + " "
+ "1";
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/seedu/internship/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,14 @@ public static Company parseCompany(String company) throws ParseException {
public static Status parseStatus(String status) throws ParseException {
requireNonNull(status);
String trimmedStatus = status.trim();
if (!Status.isValidStatus(Integer.valueOf(trimmedStatus))) {
if (!StringUtil.isInteger(trimmedStatus)) {
throw new ParseException(Status.MESSAGE_CONSTRAINTS);
}
return new Status(Integer.valueOf(trimmedStatus));

if (!Status.isValidStatus(Integer.parseInt(trimmedStatus))) {
throw new ParseException(Status.MESSAGE_CONSTRAINTS);
}
return new Status(Integer.parseInt(trimmedStatus));
}

/**
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/seedu/internship/model/internship/Company.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ public String toString() {
return companyName;
}

/**
* Returns true if both companies have the same name, regardless of casing - Non-Case Sensitive.
* This defines a weaker notion of equality between two companies.
*/
public boolean isSameCompany(Company otherCompany) {
return companyName.equalsIgnoreCase(otherCompany.companyName);
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public Set<Tag> getTags() {
}

/**
* Returns true if both internships have the same position and company name.
* Returns true if both internships have the same position and company name regardless of case - Non-Case Sensitive.
* This defines a weaker notion of equality between two internships.
*/
public boolean isSameInternship(Internship otherInternship) {
Expand All @@ -75,8 +75,8 @@ public boolean isSameInternship(Internship otherInternship) {
}

return otherInternship != null
&& otherInternship.getPosition().equals(getPosition())
&& otherInternship.getCompany().equals(getCompany());
&& otherInternship.getPosition().isSamePosition(getPosition())
&& otherInternship.getCompany().isSameCompany(getCompany());
}

/**
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/seedu/internship/model/internship/Position.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,19 @@ public String toString() {
return positionName;
}

/**
* Returns true if both positions have the same name, regardless of casing - Non-Case Sensitive.
* This defines a weaker notion of equality between two positions.
*/
public boolean isSamePosition(Position otherPosition) {
return positionName.equalsIgnoreCase(otherPosition.positionName);
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof Position // instanceof handles nulls
&& positionName.equalsIgnoreCase(((Position) other).positionName)); // state check
&& positionName.equals(((Position) other).positionName)); // state check
}

@Override
Expand Down