forked from nus-cs2113-AY2425S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
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
Assertion, Logging and Exception #93
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
81d21bc
Add Assertion, Logging and Exception
f9842e7
Modify the delete function
70ddaf0
Add JUnit test to find multiple outputs
84ab9df
Modify JUnit test and Delete statement
f670749
Fix checkstyle
154783f
Fix JUnit Issue
616efbb
Modify the JUnit test
28cbafd
Update JUnit testing
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -171,30 +171,33 @@ public void list(Records records) { | |
} | ||
} | ||
|
||
// @@Author G13nd0n | ||
// @@author G13nd0n | ||
public void delete(String nric, Records records) throws IOException { | ||
assert nric != null: | ||
"Please provide a valid NRIC"; | ||
|
||
Comment on lines
+176
to
+178
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good use of assertion to assert nric != null when user wants to delete a specific patient record |
||
List<Patient> patients = records.getPatients(); | ||
int initialPatientSize = patients.size(); | ||
if (initialPatientSize == 0) { | ||
System.out.println("There are no patients in the record currently."); | ||
double initialSize = patients.size(); | ||
if (patients.isEmpty()) { | ||
System.out.println("No patients found."); | ||
return; | ||
} | ||
for (int i = 0; i < patients.size(); i++) { | ||
Patient currentPatient = patients.get(i); | ||
String patientNRIC = currentPatient.getNric(); | ||
if (patientNRIC.equals(nric)) { | ||
Patient patient = patients.get(i); | ||
if (patient.getNric().equals(nric)) { | ||
patients.remove(i); | ||
System.out.println("Patient " + currentPatient.getName() + ", " + patientNRIC + ", has been deleted."); | ||
System.out.println("Patient " + patient.getName() + ", " + nric + ", has been deleted."); | ||
break; | ||
} | ||
} | ||
if (patients.size() == initialPatientSize) { | ||
System.out.println("Patient " + nric + " not found"); | ||
} | ||
|
||
if (patients.size() == initialSize) { | ||
System.out.println("Patient with " + nric + " not found"); | ||
} | ||
FileHandler.autosave(records); | ||
} | ||
|
||
|
||
// Takes in an input string and determines whether to exit the program | ||
public void exit(String input) { | ||
if(input.equalsIgnoreCase("exit")) { | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good use of catch statement to catch an exception processing the delete command and print out the specific error message