From 036a5a14fa7d30fe961fc47625462f85d74e3008 Mon Sep 17 00:00:00 2001 From: macareonie Date: Sun, 17 Mar 2024 21:41:31 +0800 Subject: [PATCH] Resolve checkstyle violations Resolve checkstyle violations in main directory. --- .../java/seedu/address/logic/Messages.java | 5 +- .../logic/commands/AddInterviewCommand.java | 46 ++++++++++++------- .../commands/DeleteInterviewCommand.java | 6 +-- .../parser/AddApplicantCommandParser.java | 3 +- .../parser/AddInterviewCommandParser.java | 21 +++++---- .../parser/AddInterviewerCommandParser.java | 2 +- .../logic/parser/AddressBookParser.java | 14 +++++- .../seedu/address/logic/parser/CliSyntax.java | 3 +- .../parser/DeleteInterviewCommandParser.java | 11 ++--- .../java/seedu/address/model/AddressBook.java | 11 +++++ src/main/java/seedu/address/model/Model.java | 2 +- .../address/model/interview/Interview.java | 17 +++++-- .../model/interview/UniqueInterviewList.java | 23 ++++++---- .../DuplicateInterviewException.java | 4 ++ .../InterviewNotFoundException.java | 3 ++ 15 files changed, 116 insertions(+), 55 deletions(-) diff --git a/src/main/java/seedu/address/logic/Messages.java b/src/main/java/seedu/address/logic/Messages.java index b1719e26c94..2282854a546 100644 --- a/src/main/java/seedu/address/logic/Messages.java +++ b/src/main/java/seedu/address/logic/Messages.java @@ -52,9 +52,12 @@ public static String format(Person person) { return builder.toString(); } + /** + * Formats the {@code interview} for display to the user. + */ public static String formatInterview(Interview interview) { final StringBuilder builder = new StringBuilder(); - builder.append("Applicant: ").append(interview.getApplicant().getName()) + builder.append("Interview: ").append(interview.getApplicant().getName()) .append(" Interviewer: ") .append(interview.getInterviewer().getName()) .append(" Date: ") diff --git a/src/main/java/seedu/address/logic/commands/AddInterviewCommand.java b/src/main/java/seedu/address/logic/commands/AddInterviewCommand.java index f3e496978ec..632bc1d4d9b 100644 --- a/src/main/java/seedu/address/logic/commands/AddInterviewCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddInterviewCommand.java @@ -1,30 +1,48 @@ package seedu.address.logic.commands; import static java.util.Objects.requireNonNull; +import static seedu.address.logic.parser.CliSyntax.PREFIX_APPLICANT; +import static seedu.address.logic.parser.CliSyntax.PREFIX_DATE; +import static seedu.address.logic.parser.CliSyntax.PREFIX_DESCRIPTION; +import static seedu.address.logic.parser.CliSyntax.PREFIX_END_TIME; +import static seedu.address.logic.parser.CliSyntax.PREFIX_INTERVIEWER; +import static seedu.address.logic.parser.CliSyntax.PREFIX_START_TIME; + +import java.time.LocalDate; +import java.time.LocalTime; +import java.util.List; -import seedu.address.commons.util.ToStringBuilder; import seedu.address.logic.Messages; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; import seedu.address.model.interview.Interview; -import seedu.address.model.person.Applicant; -import seedu.address.model.person.Interviewer; import seedu.address.model.person.Person; import seedu.address.model.person.Phone; -import java.time.LocalDate; -import java.time.LocalTime; -import java.util.List; - /** * Adds an Interview to the talent tracker. */ -public class AddInterviewCommand extends Command{ +public class AddInterviewCommand extends Command { public static final String COMMAND_WORD = AddPersonCommand.COMMAND_WORD + "_interview"; + public static final String MESSAGE_INFORMATION = "Parameters: " + + PREFIX_DESCRIPTION + "DESCRIPTION " + + PREFIX_DATE + "DATE " + + PREFIX_START_TIME + "START TIME " + + PREFIX_END_TIME + "END TIME " + + PREFIX_APPLICANT + "APPLICANT PHONE NUMBER" + + PREFIX_INTERVIEWER + "INTERVIEWER PHONE NUMBER " + "\n" + + "Example: " + COMMAND_WORD + " " + + PREFIX_DESCRIPTION + "technical interview " + + PREFIX_DATE + "2022-11-11 " + + PREFIX_START_TIME + "10:00 " + + PREFIX_END_TIME + "11:00 " + + PREFIX_APPLICANT + "88888888" + + PREFIX_INTERVIEWER + "88889999"; + public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds an interview to the talent tracker. " - + AddPersonCommand.MESSAGE_USAGE; + + MESSAGE_INFORMATION; public static final String MESSAGE_SUCCESS = "New Interview added: %1$s"; @@ -44,7 +62,8 @@ public class AddInterviewCommand extends Command{ /** * Creates an AddInterviewCommand to add the specified {@code Person} */ - public AddInterviewCommand(String description, Phone applicant, Phone interviewer, LocalDate date, LocalTime startTime, LocalTime endTime) { + public AddInterviewCommand(String description, Phone applicant, Phone interviewer, LocalDate date, + LocalTime startTime, LocalTime endTime) { this.description = description; this.applicant = applicant; this.interviewer = interviewer; @@ -58,7 +77,6 @@ public CommandResult execute(Model model) throws CommandException { requireNonNull(model); List lastShownList = model.getFilteredPersonList(); - boolean isFoundApplicant = false; boolean isFoundInterviewer = false; Phone targetApplicantPhone = applicant; @@ -81,14 +99,9 @@ public CommandResult execute(Model model) throws CommandException { } } - if (!isFoundApplicant || !isFoundInterviewer) { throw new CommandException(Messages.MESSAGE_PERSON_NOT_IN_LIST); } -// else if (!(applicantSearch instanceof Applicant) || !(interviewerSearch instanceof Interviewer)) { -// throw new CommandException("Phone Number error"); -// } - Interview interview = new Interview(applicantSearch, interviewerSearch, date, startTime, endTime, description); @@ -113,7 +126,6 @@ public boolean equals(Object other) { } AddInterviewCommand otherCommmand = (AddInterviewCommand) other; -// return interview.equals(otherCommmand.interview); return false; } diff --git a/src/main/java/seedu/address/logic/commands/DeleteInterviewCommand.java b/src/main/java/seedu/address/logic/commands/DeleteInterviewCommand.java index 4ee53d7115d..4730176ed6f 100644 --- a/src/main/java/seedu/address/logic/commands/DeleteInterviewCommand.java +++ b/src/main/java/seedu/address/logic/commands/DeleteInterviewCommand.java @@ -9,8 +9,7 @@ import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; import seedu.address.model.interview.Interview; -import seedu.address.model.person.Person; -import seedu.address.model.person.Phone; + /** * Deletes a person identified using it's displayed index from the address book. @@ -46,7 +45,8 @@ public CommandResult execute(Model model) throws CommandException { } model.deleteInterview(interview); - return new CommandResult(MESSAGE_DELETE_INTERVIEW_SUCCESS + "\nInformation about delete interview: \n" + Messages.formatInterview(interview)); + return new CommandResult(MESSAGE_DELETE_INTERVIEW_SUCCESS + + "\nInformation about delete interview: \n" + Messages.formatInterview(interview)); } @Override diff --git a/src/main/java/seedu/address/logic/parser/AddApplicantCommandParser.java b/src/main/java/seedu/address/logic/parser/AddApplicantCommandParser.java index 78c32721332..be101701280 100644 --- a/src/main/java/seedu/address/logic/parser/AddApplicantCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddApplicantCommandParser.java @@ -34,7 +34,8 @@ public AddApplicantPersonCommand parse(String args) throws ParseException { if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL) || !argMultimap.getPreamble().isEmpty()) { - throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddApplicantPersonCommand.MESSAGE_USAGE)); + throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, + AddApplicantPersonCommand.MESSAGE_USAGE)); } argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL); diff --git a/src/main/java/seedu/address/logic/parser/AddInterviewCommandParser.java b/src/main/java/seedu/address/logic/parser/AddInterviewCommandParser.java index b4aab5408f2..1c9c0e1bf22 100644 --- a/src/main/java/seedu/address/logic/parser/AddInterviewCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddInterviewCommandParser.java @@ -1,16 +1,12 @@ package seedu.address.logic.parser; import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; -import static seedu.address.logic.parser.CliSyntax.PREFIX_DESCRIPTION; +import static seedu.address.logic.parser.CliSyntax.PREFIX_APPLICANT; import static seedu.address.logic.parser.CliSyntax.PREFIX_DATE; -import static seedu.address.logic.parser.CliSyntax.PREFIX_START_TIME; +import static seedu.address.logic.parser.CliSyntax.PREFIX_DESCRIPTION; import static seedu.address.logic.parser.CliSyntax.PREFIX_END_TIME; -import static seedu.address.logic.parser.CliSyntax.PREFIX_APPLICANT; import static seedu.address.logic.parser.CliSyntax.PREFIX_INTERVIEWER; - -import seedu.address.logic.commands.AddInterviewCommand; -import seedu.address.logic.parser.exceptions.ParseException; -import seedu.address.model.person.Phone; +import static seedu.address.logic.parser.CliSyntax.PREFIX_START_TIME; import java.time.LocalDate; import java.time.LocalTime; @@ -18,6 +14,11 @@ import java.time.format.DateTimeParseException; import java.util.stream.Stream; +import seedu.address.logic.commands.AddInterviewCommand; +import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.person.Phone; + + /** * Parses input arguments and creates a new AddInterviewCommand object */ @@ -30,9 +31,11 @@ public class AddInterviewCommandParser implements Parser { */ public AddInterviewCommand parse(String args) throws ParseException { ArgumentMultimap argMultimap = - ArgumentTokenizer.tokenize(args, PREFIX_DESCRIPTION, PREFIX_DATE, PREFIX_START_TIME, PREFIX_END_TIME, PREFIX_APPLICANT, PREFIX_INTERVIEWER); + ArgumentTokenizer.tokenize(args, PREFIX_DESCRIPTION, PREFIX_DATE, PREFIX_START_TIME, PREFIX_END_TIME, + PREFIX_APPLICANT, PREFIX_INTERVIEWER); - if (!arePrefixesPresent(argMultimap, PREFIX_DESCRIPTION, PREFIX_DATE, PREFIX_START_TIME, PREFIX_END_TIME, PREFIX_APPLICANT, PREFIX_INTERVIEWER) + if (!arePrefixesPresent(argMultimap, PREFIX_DESCRIPTION, PREFIX_DATE, PREFIX_START_TIME, PREFIX_END_TIME, + PREFIX_APPLICANT, PREFIX_INTERVIEWER) || !argMultimap.getPreamble().isEmpty()) { throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddInterviewCommand.MESSAGE_USAGE)); } diff --git a/src/main/java/seedu/address/logic/parser/AddInterviewerCommandParser.java b/src/main/java/seedu/address/logic/parser/AddInterviewerCommandParser.java index 5cf05113fbe..3424881690f 100644 --- a/src/main/java/seedu/address/logic/parser/AddInterviewerCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddInterviewerCommandParser.java @@ -9,8 +9,8 @@ import java.util.Set; import java.util.stream.Stream; -import seedu.address.logic.commands.AddPersonCommand; import seedu.address.logic.commands.AddInterviewerPersonCommand; +import seedu.address.logic.commands.AddPersonCommand; import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.model.person.Email; import seedu.address.model.person.Interviewer; diff --git a/src/main/java/seedu/address/logic/parser/AddressBookParser.java b/src/main/java/seedu/address/logic/parser/AddressBookParser.java index dfb5f231b89..ac4f818aa1d 100644 --- a/src/main/java/seedu/address/logic/parser/AddressBookParser.java +++ b/src/main/java/seedu/address/logic/parser/AddressBookParser.java @@ -6,7 +6,19 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import seedu.address.logic.commands.*; +import seedu.address.logic.commands.AddApplicantPersonCommand; +import seedu.address.logic.commands.AddInterviewCommand; +import seedu.address.logic.commands.AddInterviewerPersonCommand; +import seedu.address.logic.commands.ClearCommand; +import seedu.address.logic.commands.Command; +import seedu.address.logic.commands.DeleteCommand; +import seedu.address.logic.commands.DeleteInterviewCommand; +import seedu.address.logic.commands.EditCommand; +import seedu.address.logic.commands.ExitCommand; +import seedu.address.logic.commands.FindCommand; +import seedu.address.logic.commands.HelpCommand; +import seedu.address.logic.commands.ListCommand; +import seedu.address.logic.commands.RemarkCommand; import seedu.address.logic.parser.exceptions.ParseException; /** diff --git a/src/main/java/seedu/address/logic/parser/CliSyntax.java b/src/main/java/seedu/address/logic/parser/CliSyntax.java index 242ba199a64..a920d54244f 100644 --- a/src/main/java/seedu/address/logic/parser/CliSyntax.java +++ b/src/main/java/seedu/address/logic/parser/CliSyntax.java @@ -11,7 +11,6 @@ public class CliSyntax { public static final Prefix PREFIX_EMAIL = new Prefix("e/"); public static final Prefix PREFIX_REMARK = new Prefix("r/"); public static final Prefix PREFIX_TAG = new Prefix("t/"); - public static final Prefix PREFIX_DESCRIPTION = new Prefix("desc/"); public static final Prefix PREFIX_DATE = new Prefix("date/"); public static final Prefix PREFIX_START_TIME = new Prefix("st/"); @@ -19,4 +18,4 @@ public class CliSyntax { public static final Prefix PREFIX_APPLICANT = new Prefix("a/"); public static final Prefix PREFIX_INTERVIEWER = new Prefix("i/"); -} \ No newline at end of file +} diff --git a/src/main/java/seedu/address/logic/parser/DeleteInterviewCommandParser.java b/src/main/java/seedu/address/logic/parser/DeleteInterviewCommandParser.java index 1c8121e24d4..ab8e9cc29ab 100644 --- a/src/main/java/seedu/address/logic/parser/DeleteInterviewCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/DeleteInterviewCommandParser.java @@ -1,14 +1,13 @@ package seedu.address.logic.parser; -import seedu.address.logic.commands.DeleteCommand; +import static seedu.address.logic.Messages.MESSAGE_NOT_INTEGER; + import seedu.address.logic.commands.DeleteInterviewCommand; import seedu.address.logic.parser.exceptions.ParseException; -import seedu.address.model.interview.Interview; -import seedu.address.model.person.Phone; - -import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; -import static seedu.address.logic.Messages.MESSAGE_NOT_INTEGER; +/** + * Parses input arguments and creates a new DeleteInterviewCommand object + */ public class DeleteInterviewCommandParser implements Parser { /** diff --git a/src/main/java/seedu/address/model/AddressBook.java b/src/main/java/seedu/address/model/AddressBook.java index 364db945992..ab2e308bf94 100644 --- a/src/main/java/seedu/address/model/AddressBook.java +++ b/src/main/java/seedu/address/model/AddressBook.java @@ -102,15 +102,26 @@ public void removePerson(Person key) { // Interview Operations + /** + * Adds an interview to the address book. + * The interview must not already exist in the address book. + */ public void addInterview(Interview interview) { interviews.add(interview); } + /** + * Returns true if an interview with the same identity as {@code interview} exists in the address book. + */ public boolean hasInterview(Interview interview) { requireNonNull(interview); return interviews.contains(interview); } + /** + * Removes {@code key} from this {@code AddressBook}. + * {@code key} must exist in the address book. + */ public void removeInterview(Interview key) { interviews.remove(key); } diff --git a/src/main/java/seedu/address/model/Model.java b/src/main/java/seedu/address/model/Model.java index 9af64acb5a6..e9eb66df8bb 100644 --- a/src/main/java/seedu/address/model/Model.java +++ b/src/main/java/seedu/address/model/Model.java @@ -90,7 +90,7 @@ public interface Model { boolean hasInterview(Interview interview); - void deleteInterview (Interview interview); + void deleteInterview(Interview interview); ObservableList getFilteredInterviewList(); } diff --git a/src/main/java/seedu/address/model/interview/Interview.java b/src/main/java/seedu/address/model/interview/Interview.java index 37e5dfd1fc3..0e370f08861 100644 --- a/src/main/java/seedu/address/model/interview/Interview.java +++ b/src/main/java/seedu/address/model/interview/Interview.java @@ -1,10 +1,13 @@ package seedu.address.model.interview; -import seedu.address.model.person.Person; - import java.time.LocalDate; import java.time.LocalTime; +import seedu.address.model.person.Person; + +/** + * Represents an Interview in the talent tracker. + */ public class Interview { private Person applicant; private Person interviewer; @@ -13,7 +16,11 @@ public class Interview { private LocalTime endTime; private String description; - public Interview(Person applicant, Person interviewer, LocalDate date, LocalTime startTime, LocalTime endTime, String description) { + /** + * Represents a Interview in the address book. + */ + public Interview(Person applicant, Person interviewer, LocalDate date, LocalTime startTime, + LocalTime endTime, String description) { this.applicant = applicant; this.interviewer = interviewer; this.date = date; @@ -42,6 +49,10 @@ public LocalTime getEndTime() { return endTime; } + /** + * Returns true if both interviews of the same name have at least one other identity field that is the same. + * This defines a weaker notion of equality between two interviews. + */ public boolean isSameInterview(Interview otherInterview) { boolean applicantMatch = otherInterview.applicant.equals(this.applicant); boolean interviewerMatch = otherInterview.interviewer.equals(this.interviewer); diff --git a/src/main/java/seedu/address/model/interview/UniqueInterviewList.java b/src/main/java/seedu/address/model/interview/UniqueInterviewList.java index b4bca99ff90..2b9262804ce 100644 --- a/src/main/java/seedu/address/model/interview/UniqueInterviewList.java +++ b/src/main/java/seedu/address/model/interview/UniqueInterviewList.java @@ -2,19 +2,21 @@ import static java.util.Objects.requireNonNull; import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; + +import java.util.Iterator; +import java.util.List; + import javafx.collections.FXCollections; import javafx.collections.ObservableList; import seedu.address.model.interview.exceptions.DuplicateInterviewException; import seedu.address.model.interview.exceptions.InterviewNotFoundException; -import java.util.Iterator; -import java.util.List; - /** * A list of interviews that enforces uniqueness between its elements and does not allow nulls. - * An interview is considered unique by comparing using {@code Interview#isSameInterview(Interview)}. As such, adding and updating of - * interviews uses Interview#isSameInterview(Interview) for equality so as to ensure that the interview being added or updated is - * unique in terms of identity in the UniqueInterviewList. However, the removal of an interview uses Interview#equals(Object) so + * An interview is considered unique by comparing using {@code Interview#isSameInterview(Interview)}. As such, + * adding and updating of interviews uses Interview#isSameInterview(Interview) for equality so as to ensure that + * the interview being added or updated is unique in terms of identity in the UniqueInterviewList. + * However, the removal of an interview uses Interview#equals(Object) so * as to ensure that the interview with exactly the same fields will be removed. * * Supports a minimal set of list operations. @@ -41,9 +43,9 @@ public boolean contains(Interview toCheck) { */ public void add(Interview toAdd) { requireNonNull(toAdd); -// if (contains(toAdd)) { -// throw new DuplicateInterviewException(); -// } + //if (contains(toAdd)) { + // throw new DuplicateInterviewException(); + //} internalList.add(toAdd); } @@ -52,7 +54,8 @@ public void add(Interview toAdd) { * {@code target} must exist in the list. * The interview identity of {@code editedInterview} must not be the same as another existing interview in the list. */ - public void setInterview(Interview target, Interview editedInterview) throws DuplicateInterviewException, InterviewNotFoundException { + public void setInterview(Interview target, Interview editedInterview) throws DuplicateInterviewException, + InterviewNotFoundException { requireAllNonNull(target, editedInterview); int index = internalList.indexOf(target); diff --git a/src/main/java/seedu/address/model/interview/exceptions/DuplicateInterviewException.java b/src/main/java/seedu/address/model/interview/exceptions/DuplicateInterviewException.java index fb517d8b6b1..5b318755a33 100644 --- a/src/main/java/seedu/address/model/interview/exceptions/DuplicateInterviewException.java +++ b/src/main/java/seedu/address/model/interview/exceptions/DuplicateInterviewException.java @@ -1,4 +1,8 @@ package seedu.address.model.interview.exceptions; +/** + * Signals that the operation will result in duplicate Interviews (Interviews are considered duplicates if they have + * the same identity). + */ public class DuplicateInterviewException extends Throwable { } diff --git a/src/main/java/seedu/address/model/interview/exceptions/InterviewNotFoundException.java b/src/main/java/seedu/address/model/interview/exceptions/InterviewNotFoundException.java index f8b2e62aedf..c5572512b48 100644 --- a/src/main/java/seedu/address/model/interview/exceptions/InterviewNotFoundException.java +++ b/src/main/java/seedu/address/model/interview/exceptions/InterviewNotFoundException.java @@ -1,4 +1,7 @@ package seedu.address.model.interview.exceptions; +/** + * Signals that the operation is unable to find the specified interview. + */ public class InterviewNotFoundException extends RuntimeException { }