Skip to content

Commit

Permalink
add defensive coding techniques
Browse files Browse the repository at this point in the history
  • Loading branch information
Kappaccinoh committed Apr 15, 2024
1 parent 7b7d2f5 commit 0ad96f1
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static java.util.Objects.requireNonNull;

import java.util.logging.Level;
import java.util.logging.Logger;

import seedu.address.commons.util.ToStringBuilder;
Expand All @@ -11,7 +12,7 @@

/**
* Represents a command for querying appointments for a specific doctor.
* The command searches for appointments of doctors whose NRICs/names contain any of the specified keywords
* The command searches for appointments of doctors whose NRICs contain any of the specified keywords
* (case-insensitive) and displays them as a list with index numbers.
*/
public class QueryDoctorAppointmentCommand extends Command {
Expand All @@ -28,17 +29,27 @@ public class QueryDoctorAppointmentCommand extends Command {

private final AppointmentContainsDoctorPredicate predicate;

/**
* Constructs a QueryDoctorAppointmentCommand with the given predicate.
*
* @param predicate The predicate to be used for querying doctor appointments.
* @throws NullPointerException if the predicate is null.
*/
public QueryDoctorAppointmentCommand(AppointmentContainsDoctorPredicate predicate) {
requireNonNull(predicate, "Predicate cannot be null in QueryDoctorAppointmentCommand constructor.");
this.predicate = predicate;
}

@Override
public CommandResult execute(Model model) {
requireNonNull(model);
logger.info("Executing QueryDoctorAppointmentCommand");
requireNonNull(model, "Model cannot be null in execute method of QueryDoctorAppointmentCommand.");

logger.log(Level.INFO, "Executing QueryDoctorAppointmentCommand");

model.updateFilteredAppointmentList(predicate);
int numberOfAppointments = model.getFilteredAppointmentList().size();
logger.info("Number of appointments found: " + numberOfAppointments);
logger.log(Level.INFO, "Number of appointments found: " + numberOfAppointments);

return new CommandResult(
String.format(Messages.MESSAGE_APPOINTMENTS_LISTED_OVERVIEW, numberOfAppointments));
}
Expand All @@ -49,7 +60,6 @@ public boolean equals(Object other) {
return true;
}

// instanceof handles nulls
if (!(other instanceof QueryDoctorAppointmentCommand)) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

/**
* Represents a command for querying appointments for a specific patient.
* The command searches for appointments of patients whose NRICs/names contain any of the specified keywords
* The command searches for appointments of patients whose NRICs contain any of the specified keywords
* (case-insensitive) and displays them as a list with index numbers.
*/
public class QueryPatientAppointmentCommand extends Command {
Expand All @@ -28,17 +28,27 @@ public class QueryPatientAppointmentCommand extends Command {

private final AppointmentContainsPatientPredicate predicate;

/**
* Constructs a QueryPatientAppointmentCommand with the given predicate.
*
* @param predicate The predicate to be used for querying patient appointments.
* @throws NullPointerException if the predicate is null.
*/
public QueryPatientAppointmentCommand(AppointmentContainsPatientPredicate predicate) {
requireNonNull(predicate, "Predicate cannot be null in QueryPatientAppointmentCommand constructor.");
this.predicate = predicate;
}

@Override
public CommandResult execute(Model model) {
requireNonNull(model);
requireNonNull(model, "Model cannot be null in execute method of QueryPatientAppointmentCommand.");

logger.log(Level.INFO, "Executing QueryPatientAppointmentCommand");

model.updateFilteredAppointmentList(predicate);
int numberOfAppointments = model.getFilteredAppointmentList().size();
logger.log(Level.INFO, "Number of appointments found: " + numberOfAppointments);

return new CommandResult(
String.format(Messages.MESSAGE_APPOINTMENTS_LISTED_OVERVIEW, numberOfAppointments));
}
Expand All @@ -49,7 +59,6 @@ public boolean equals(Object other) {
return true;
}

// instanceof handles nulls
if (!(other instanceof QueryPatientAppointmentCommand)) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
import seedu.address.model.person.PatientContainsKeywordsPredicate;

/**
* Queries and returns all patients whose name matches the input string.
* Keyword matching is case insensitive.
* Query more than one name at a time is supported
* Queries and returns all patients whose name, NRIC, DoB and phone number matches
* or substring matches the input string.
* Keyword matching is case-insensitive.
* Query more than one name, nric, date of birth and phone number at a time is supported
*/
public class QueryPatientCommand extends Command {

Expand All @@ -28,17 +29,27 @@ public class QueryPatientCommand extends Command {

private final PatientContainsKeywordsPredicate predicate;

/**
* Constructs a QueryPatientCommand with the given predicate.
*
* @param predicate The predicate to be used for querying patients.
* @throws NullPointerException if the predicate is null.
*/
public QueryPatientCommand(PatientContainsKeywordsPredicate predicate) {
requireNonNull(predicate, "Predicate cannot be null in QueryPatientCommand constructor.");
this.predicate = predicate;
}

@Override
public CommandResult execute(Model model) {
requireNonNull(model);
requireNonNull(model, "Model cannot be null in execute method of QueryPatientCommand.");

logger.log(Level.INFO, "Executing QueryPatientCommand");

model.updateFilteredPersonList(predicate);
int numberOfPatients = model.getFilteredPersonList().size();
logger.log(Level.INFO, "Number of patients found: " + numberOfPatients);

return new CommandResult(
String.format(Messages.MESSAGE_PERSONS_LISTED_OVERVIEW, numberOfPatients));
}
Expand All @@ -49,7 +60,6 @@ public boolean equals(Object other) {
return true;
}

// instanceof handles nulls
if (!(other instanceof QueryPatientCommand)) {
return false;
}
Expand Down

0 comments on commit 0ad96f1

Please sign in to comment.