Skip to content

Commit

Permalink
add logger to files
Browse files Browse the repository at this point in the history
  • Loading branch information
Kappaccinoh committed Mar 25, 2024
1 parent 8c3f20c commit 215b562
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import static java.util.Objects.requireNonNull;

import java.util.logging.Logger;

import seedu.address.commons.util.ToStringBuilder;
import seedu.address.logic.Messages;
import seedu.address.model.Model;
Expand All @@ -13,6 +15,8 @@
* (case-insensitive) and displays them as a list with index numbers.
*/
public class QueryDoctorAppointmentCommand extends Command {
private static final Logger logger = Logger.getLogger(QueryDoctorAppointmentCommand.class.getName());

public static final String COMMAND_WORD = "appfordoctor";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Finds all appointments of doctors whose "
Expand All @@ -30,10 +34,12 @@ public QueryDoctorAppointmentCommand(AppointmentContainsDoctorPredicate predicat
@Override
public CommandResult execute(Model model) {
requireNonNull(model);
logger.info("Executing QueryDoctorAppointmentCommand");
model.updateFilteredAppointmentList(predicate);
int numberOfAppointments = model.getFilteredAppointmentList().size();
logger.info("Number of appointments found: " + numberOfAppointments);
return new CommandResult(
String.format(Messages.MESSAGE_APPOINTMENTS_LISTED_OVERVIEW,
model.getFilteredAppointmentList().size()));
String.format(Messages.MESSAGE_APPOINTMENTS_LISTED_OVERVIEW, numberOfAppointments));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;

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

import seedu.address.logic.commands.QueryDoctorAppointmentCommand;
import seedu.address.logic.parser.exceptions.ParseException;
Expand All @@ -12,19 +14,23 @@
* Parses input arguments and creates a new QueryDoctorAppointmentCommand object
*/
public class QueryDoctorAppointmentCommandParser implements Parser<QueryDoctorAppointmentCommand> {
private static final Logger logger = Logger.getLogger(QueryDoctorAppointmentCommandParser.class.getName());

/**
* Parses the given {@code String} of arguments in the context of the QueryDoctorAppointmentCommand
* and returns a QueryDoctorAppointmentCommand object for execution.
* @throws ParseException if the user input does not conform the expected format
*/
public QueryDoctorAppointmentCommand parse(String args) throws ParseException {
logger.log(Level.INFO, "Parsing QueryDoctorAppointmentCommand arguments: " + args);
String trimmedArgs = args.trim();
if (trimmedArgs.isEmpty()) {
throw new ParseException(
String.format(MESSAGE_INVALID_COMMAND_FORMAT, QueryDoctorAppointmentCommand.MESSAGE_USAGE));
}

String[] nameKeywords = trimmedArgs.split("\\s+");
logger.log(Level.INFO, "Name keywords: " + Arrays.toString(nameKeywords));

return new QueryDoctorAppointmentCommand(new AppointmentContainsDoctorPredicate(Arrays.asList(nameKeywords)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.util.List;
import java.util.function.Predicate;
import java.util.logging.Level;
import java.util.logging.Logger;

import seedu.address.commons.util.StringUtil;
import seedu.address.commons.util.ToStringBuilder;
Expand All @@ -10,6 +12,7 @@
* Represents a Predicate used to test if an Appointment contains specified doctor keywords.
*/
public class AppointmentContainsDoctorPredicate implements Predicate<Appointment> {
private static final Logger logger = Logger.getLogger(AppointmentContainsDoctorPredicate.class.getName());
private final List<String> keywords;

public AppointmentContainsDoctorPredicate(List<String> keywords) {
Expand All @@ -18,8 +21,11 @@ public AppointmentContainsDoctorPredicate(List<String> keywords) {

@Override
public boolean test(Appointment appointment) {
return keywords.stream()
logger.log(Level.INFO, "Testing appointment: " + appointment);
boolean result = keywords.stream()
.anyMatch(keyword -> StringUtil.containsWordIgnoreCase(appointment.getDoctorNric().nric, keyword));
logger.log(Level.INFO, "Test result: " + result);
return result;
}

@Override
Expand Down

0 comments on commit 215b562

Please sign in to comment.