diff --git a/src/main/java/seedu/address/MainApp.java b/src/main/java/seedu/address/MainApp.java index 813b027050a..b3a3c33cf60 100644 --- a/src/main/java/seedu/address/MainApp.java +++ b/src/main/java/seedu/address/MainApp.java @@ -21,6 +21,7 @@ import seedu.address.model.ReadOnlyAddressBook; import seedu.address.model.ReadOnlyUserPrefs; import seedu.address.model.UserPrefs; +import seedu.address.model.internshipapplication.InternshipApplication; import seedu.address.model.util.SampleDataUtil; import seedu.address.storage.AddressBookStorage; import seedu.address.storage.JsonAddressBookStorage; @@ -43,7 +44,7 @@ public class MainApp extends Application { protected Ui ui; protected Logic logic; protected Storage storage; - protected Model model; + protected Model model; protected Config config; @Override @@ -72,11 +73,11 @@ public void init() throws Exception { * The data from the sample address book will be used instead if {@code storage}'s address book is not found, * or an empty address book will be used instead if errors occur when reading {@code storage}'s address book. */ - private Model initModelManager(Storage storage, ReadOnlyUserPrefs userPrefs) { + private Model initModelManager(Storage storage, ReadOnlyUserPrefs userPrefs) { logger.info("Using data file : " + storage.getAddressBookFilePath()); - Optional addressBookOptional; - ReadOnlyAddressBook initialData; + Optional> addressBookOptional; + ReadOnlyAddressBook initialData; try { addressBookOptional = storage.readAddressBook(); if (!addressBookOptional.isPresent()) { @@ -87,10 +88,10 @@ private Model initModelManager(Storage storage, ReadOnlyUserPrefs userPrefs) { } catch (DataLoadingException e) { logger.warning("Data file at " + storage.getAddressBookFilePath() + " could not be loaded." + " Will be starting with an empty AddressBook."); - initialData = new AddressBook(); + initialData = new AddressBook<>(); } - return new ModelManager(initialData, userPrefs); + return new ModelManager(initialData, userPrefs); } private void initLogging(Config config) { diff --git a/src/main/java/seedu/address/logic/Logic.java b/src/main/java/seedu/address/logic/Logic.java index 92cd8fa605a..41977ddc317 100644 --- a/src/main/java/seedu/address/logic/Logic.java +++ b/src/main/java/seedu/address/logic/Logic.java @@ -7,13 +7,13 @@ import seedu.address.logic.commands.CommandResult; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.HireMeComparable; import seedu.address.model.ReadOnlyAddressBook; -import seedu.address.model.person.Person; /** * API of the Logic component */ -public interface Logic { +public interface Logic> { /** * Executes the command and returns the result. * @param commandText The command as entered by the user. @@ -28,10 +28,10 @@ public interface Logic { * * @see seedu.address.model.Model#getAddressBook() */ - ReadOnlyAddressBook getAddressBook(); + ReadOnlyAddressBook getAddressBook(); /** Returns an unmodifiable view of the filtered list of persons */ - ObservableList getFilteredPersonList(); + ObservableList getFilteredList(); /** * Returns the user prefs' address book file path. diff --git a/src/main/java/seedu/address/logic/LogicManager.java b/src/main/java/seedu/address/logic/LogicManager.java index 648b69cb43e..6435e95d266 100644 --- a/src/main/java/seedu/address/logic/LogicManager.java +++ b/src/main/java/seedu/address/logic/LogicManager.java @@ -13,15 +13,15 @@ import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.logic.parser.AddressBookParser; import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.HireMeComparable; import seedu.address.model.Model; import seedu.address.model.ReadOnlyAddressBook; -import seedu.address.model.person.Person; import seedu.address.storage.Storage; /** * The main LogicManager of the app. */ -public class LogicManager implements Logic { +public class LogicManager> implements Logic { public static final String FILE_OPS_ERROR_FORMAT = "Could not save data due to the following error: %s"; public static final String FILE_OPS_PERMISSION_ERROR_FORMAT = @@ -29,14 +29,14 @@ public class LogicManager implements Logic { private final Logger logger = LogsCenter.getLogger(LogicManager.class); - private final Model model; - private final Storage storage; + private final Model model; + private final Storage storage; private final AddressBookParser addressBookParser; /** * Constructs a {@code LogicManager} with the given {@code Model} and {@code Storage}. */ - public LogicManager(Model model, Storage storage) { + public LogicManager(Model model, Storage storage) { this.model = model; this.storage = storage; addressBookParser = new AddressBookParser(); @@ -47,7 +47,7 @@ public CommandResult execute(String commandText) throws CommandException, ParseE logger.info("----------------[USER COMMAND][" + commandText + "]"); CommandResult commandResult; - Command command = addressBookParser.parseCommand(commandText); + Command command = addressBookParser.parseCommand(commandText); commandResult = command.execute(model); try { @@ -62,13 +62,13 @@ public CommandResult execute(String commandText) throws CommandException, ParseE } @Override - public ReadOnlyAddressBook getAddressBook() { + public ReadOnlyAddressBook getAddressBook() { return model.getAddressBook(); } @Override - public ObservableList getFilteredPersonList() { - return model.getFilteredPersonList(); + public ObservableList getFilteredList() { + return model.getFilteredList(); } @Override diff --git a/src/main/java/seedu/address/logic/Messages.java b/src/main/java/seedu/address/logic/Messages.java index ecd32c31b53..c5891579e28 100644 --- a/src/main/java/seedu/address/logic/Messages.java +++ b/src/main/java/seedu/address/logic/Messages.java @@ -5,7 +5,7 @@ import java.util.stream.Stream; import seedu.address.logic.parser.Prefix; -import seedu.address.model.person.Person; +import seedu.address.model.internshipapplication.InternshipApplication; /** * Container for user visible messages. @@ -34,17 +34,13 @@ public static String getErrorMessageForDuplicatePrefixes(Prefix... duplicatePref /** * Formats the {@code person} for display to the user. */ - public static String format(Person person) { + public static String format(InternshipApplication internship) { final StringBuilder builder = new StringBuilder(); - builder.append(person.getName()) - .append("; Phone: ") - .append(person.getPhone()) - .append("; Email: ") - .append(person.getEmail()) - .append("; Address: ") - .append(person.getAddress()) - .append("; Tags: "); - person.getTags().forEach(builder::append); + builder.append(internship.getCompany()) + .append("; Role: ") + .append(internship.getRole()) + .append("; Date: ") + .append(internship.getDateOfApplication()); return builder.toString(); } diff --git a/src/main/java/seedu/address/logic/commands/AddCommand.java b/src/main/java/seedu/address/logic/commands/AddCommand.java index 192872abd19..6698f5edabd 100644 --- a/src/main/java/seedu/address/logic/commands/AddCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddCommand.java @@ -10,14 +10,14 @@ import seedu.address.logic.Messages; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; -import seedu.address.model.person.Person; +import seedu.address.model.internshipapplication.InternshipApplication; /** * Adds a person to the address book. */ -public class AddCommand extends Command { +public class AddCommand extends Command { - public static final String COMMAND_WORD = "add"; + public static final String COMMAND_WORD = "/a"; public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds an internship application to the address book. " + "Parameters: " @@ -35,25 +35,25 @@ public class AddCommand extends Command { public static final String MESSAGE_DUPLICATE_PERSON = "This internship application already exists in the address book"; - private final Person toAdd; + private final InternshipApplication toAdd; /** * Creates an AddCommand to add the specified {@code Person} */ - public AddCommand(Person person) { - requireNonNull(person); - toAdd = person; + public AddCommand(InternshipApplication internship) { + requireNonNull(internship); + toAdd = internship; } @Override - public CommandResult execute(Model model) throws CommandException { + public CommandResult execute(Model model) throws CommandException { requireNonNull(model); - if (model.hasPerson(toAdd)) { + if (model.hasItem(toAdd)) { throw new CommandException(MESSAGE_DUPLICATE_PERSON); } - model.addPerson(toAdd); + model.addItem(toAdd); return new CommandResult(String.format(MESSAGE_SUCCESS, Messages.format(toAdd))); } diff --git a/src/main/java/seedu/address/logic/commands/Command.java b/src/main/java/seedu/address/logic/commands/Command.java index 64f18992160..f8a49ebae2f 100644 --- a/src/main/java/seedu/address/logic/commands/Command.java +++ b/src/main/java/seedu/address/logic/commands/Command.java @@ -6,7 +6,7 @@ /** * Represents a command with hidden internal logic and the ability to be executed. */ -public abstract class Command { +public abstract class Command { /** * Executes the command and returns the result message. @@ -15,6 +15,6 @@ public abstract class Command { * @return feedback message of the operation result for display * @throws CommandException If an error occurs during command execution. */ - public abstract CommandResult execute(Model model) throws CommandException; + public abstract CommandResult execute(Model model) throws CommandException; } diff --git a/src/main/java/seedu/address/logic/commands/DeleteCommand.java b/src/main/java/seedu/address/logic/commands/DeleteCommand.java index 3dbfdd0c008..a4d55ab00c5 100644 --- a/src/main/java/seedu/address/logic/commands/DeleteCommand.java +++ b/src/main/java/seedu/address/logic/commands/DeleteCommand.java @@ -9,12 +9,12 @@ import seedu.address.logic.Messages; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; -import seedu.address.model.person.Person; +import seedu.address.model.internshipapplication.InternshipApplication; /** * Deletes an internship application identified using it's displayed index from the address book. */ -public class DeleteCommand extends Command { +public class DeleteCommand extends Command { public static final String COMMAND_WORD = "delete"; @@ -32,16 +32,16 @@ public DeleteCommand(Index targetIndex) { } @Override - public CommandResult execute(Model model) throws CommandException { + public CommandResult execute(Model model) throws CommandException { requireNonNull(model); - List lastShownList = model.getFilteredPersonList(); + List lastShownList = model.getFilteredList(); if (targetIndex.getZeroBased() >= lastShownList.size()) { throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); } - Person internshipApplicationToDelete = lastShownList.get(targetIndex.getZeroBased()); - model.deletePerson(internshipApplicationToDelete); + InternshipApplication internshipApplicationToDelete = lastShownList.get(targetIndex.getZeroBased()); + model.deleteItem(internshipApplicationToDelete); return new CommandResult(String.format(MESSAGE_DELETE_PERSON_SUCCESS, Messages.format(internshipApplicationToDelete))); } diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java index 4b581c7331e..7a78eaa5e2e 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditCommand.java @@ -6,7 +6,6 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; -import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; import java.util.Collections; import java.util.HashSet; @@ -21,17 +20,13 @@ import seedu.address.logic.Messages; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; -import seedu.address.model.person.Address; -import seedu.address.model.person.Email; -import seedu.address.model.person.Name; -import seedu.address.model.person.Person; -import seedu.address.model.person.Phone; +import seedu.address.model.internshipapplication.*; import seedu.address.model.tag.Tag; /** * Edits the details of an existing person in the address book. */ -public class EditCommand extends Command { +public class EditCommand extends Command { public static final String COMMAND_WORD = "edit"; @@ -68,24 +63,26 @@ public EditCommand(Index index, EditPersonDescriptor editPersonDescriptor) { } @Override - public CommandResult execute(Model model) throws CommandException { + public CommandResult execute(Model model) throws CommandException { requireNonNull(model); - List lastShownList = model.getFilteredPersonList(); + List lastShownList = model.getFilteredList(); if (index.getZeroBased() >= lastShownList.size()) { throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); } - Person personToEdit = lastShownList.get(index.getZeroBased()); - Person editedPerson = createEditedPerson(personToEdit, editPersonDescriptor); - if (!personToEdit.isSamePerson(editedPerson) && model.hasPerson(editedPerson)) { - throw new CommandException(MESSAGE_DUPLICATE_PERSON); - } - - model.setPerson(personToEdit, editedPerson); - model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); - return new CommandResult(String.format(MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson))); +// Internship personToEdit = lastShownList.get(index.getZeroBased()); +// Internship editedPerson = createEditedPerson(personToEdit, editPersonDescriptor); +// +// if (!personToEdit.isSame(editedPerson) && model.hasItem(editedPerson)) { +// throw new CommandException(MESSAGE_DUPLICATE_PERSON); +// } +// +// model.setItem(personToEdit, editedPerson); +// model.updateFilteredList((Predicate) PREDICATE_SHOW_ALL); +// return new CommandResult(String.format(MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson))); + return new CommandResult(String.format(MESSAGE_EDIT_PERSON_SUCCESS, "")); } /** diff --git a/src/main/java/seedu/address/logic/commands/FindCommand.java b/src/main/java/seedu/address/logic/commands/FindCommand.java index 72b9eddd3a7..e9c4575e5cb 100644 --- a/src/main/java/seedu/address/logic/commands/FindCommand.java +++ b/src/main/java/seedu/address/logic/commands/FindCommand.java @@ -5,7 +5,7 @@ import seedu.address.commons.util.ToStringBuilder; import seedu.address.logic.Messages; import seedu.address.model.Model; -import seedu.address.model.person.NameContainsKeywordsPredicate; +import seedu.address.model.internshipapplication.NameContainsKeywordsPredicate; /** * Finds and lists all persons in address book whose name contains any of the argument keywords. @@ -29,9 +29,9 @@ public FindCommand(NameContainsKeywordsPredicate predicate) { @Override public CommandResult execute(Model model) { requireNonNull(model); - model.updateFilteredPersonList(predicate); + model.updateFilteredList(predicate); return new CommandResult( - String.format(Messages.MESSAGE_PERSONS_LISTED_OVERVIEW, model.getFilteredPersonList().size())); + String.format(Messages.MESSAGE_PERSONS_LISTED_OVERVIEW, model.getFilteredList().size())); } @Override diff --git a/src/main/java/seedu/address/logic/commands/ListCommand.java b/src/main/java/seedu/address/logic/commands/ListCommand.java index 5a5a514430c..e41f9300a0d 100644 --- a/src/main/java/seedu/address/logic/commands/ListCommand.java +++ b/src/main/java/seedu/address/logic/commands/ListCommand.java @@ -1,7 +1,7 @@ package seedu.address.logic.commands; import static java.util.Objects.requireNonNull; -import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; +import static seedu.address.model.Model.PREDICATE_SHOW_ALL; import seedu.address.model.Model; @@ -18,7 +18,7 @@ public class ListCommand extends Command { @Override public CommandResult execute(Model model) { requireNonNull(model); - model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); + model.updateFilteredList(PREDICATE_SHOW_ALL); return new CommandResult(MESSAGE_SUCCESS); } } diff --git a/src/main/java/seedu/address/logic/parser/AddCommandParser.java b/src/main/java/seedu/address/logic/parser/AddCommandParser.java index 4ff1a97ed77..5b78a8c28ba 100644 --- a/src/main/java/seedu/address/logic/parser/AddCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddCommandParser.java @@ -1,23 +1,16 @@ package seedu.address.logic.parser; import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; -import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS; +import static seedu.address.logic.parser.CliSyntax.PREFIX_COMPANY; +import static seedu.address.logic.parser.CliSyntax.PREFIX_DATE; import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; -import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; -import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; -import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; +import static seedu.address.logic.parser.CliSyntax.PREFIX_ROLE; -import java.util.Set; import java.util.stream.Stream; import seedu.address.logic.commands.AddCommand; import seedu.address.logic.parser.exceptions.ParseException; -import seedu.address.model.person.Address; -import seedu.address.model.person.Email; -import seedu.address.model.person.Name; -import seedu.address.model.person.Person; -import seedu.address.model.person.Phone; -import seedu.address.model.tag.Tag; +import seedu.address.model.internshipapplication.*; /** * Parses input arguments and creates a new AddCommand object @@ -31,23 +24,21 @@ public class AddCommandParser implements Parser { */ public AddCommand parse(String args) throws ParseException { ArgumentMultimap argMultimap = - ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_TAG); - - if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_PHONE, PREFIX_EMAIL) + ArgumentTokenizer.tokenize(args, PREFIX_COMPANY, PREFIX_ROLE, PREFIX_EMAIL, PREFIX_DATE); + if (!arePrefixesPresent(argMultimap, PREFIX_COMPANY, PREFIX_ROLE, PREFIX_EMAIL, PREFIX_DATE) || !argMultimap.getPreamble().isEmpty()) { throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE)); } - argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS); - Name name = ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get()); - Phone phone = ParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE).get()); + argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_COMPANY, PREFIX_ROLE, PREFIX_EMAIL, PREFIX_DATE); + Name name = ParserUtil.parseName(argMultimap.getValue(PREFIX_COMPANY).get()); Email email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get()); - Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get()); - Set tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG)); + Role role = ParserUtil.parseRole(argMultimap.getValue(PREFIX_ROLE).get()); + Date date = ParserUtil.parseDate(argMultimap.getValue(PREFIX_DATE).get()); - Person person = new Person(name, phone, email, address, tagList); + Company company = new Company(email, name); - return new AddCommand(person); + return new AddCommand(new InternshipApplication(company, date, role)); } /** diff --git a/src/main/java/seedu/address/logic/parser/FindCommandParser.java b/src/main/java/seedu/address/logic/parser/FindCommandParser.java index 2867bde857b..9791883ecee 100644 --- a/src/main/java/seedu/address/logic/parser/FindCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/FindCommandParser.java @@ -6,7 +6,7 @@ import seedu.address.logic.commands.FindCommand; import seedu.address.logic.parser.exceptions.ParseException; -import seedu.address.model.person.NameContainsKeywordsPredicate; +import seedu.address.model.internshipapplication.NameContainsKeywordsPredicate; /** * Parses input arguments and creates a new FindCommand object diff --git a/src/main/java/seedu/address/logic/parser/ParserUtil.java b/src/main/java/seedu/address/logic/parser/ParserUtil.java index 38770bc9eaf..6f13c793abc 100644 --- a/src/main/java/seedu/address/logic/parser/ParserUtil.java +++ b/src/main/java/seedu/address/logic/parser/ParserUtil.java @@ -2,6 +2,8 @@ import static java.util.Objects.requireNonNull; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; import java.util.Collection; import java.util.HashSet; import java.util.Set; @@ -9,10 +11,11 @@ import seedu.address.commons.core.index.Index; import seedu.address.commons.util.StringUtil; import seedu.address.logic.parser.exceptions.ParseException; -import seedu.address.model.person.Address; -import seedu.address.model.person.Email; -import seedu.address.model.person.Name; -import seedu.address.model.person.Phone; +import seedu.address.logic.validator.DateValidator; +import seedu.address.logic.validator.EmailValidator; +import seedu.address.logic.validator.NameValidator; +import seedu.address.logic.validator.RoleValidator; +import seedu.address.model.internshipapplication.*; import seedu.address.model.tag.Tag; /** @@ -44,12 +47,30 @@ public static Index parseIndex(String oneBasedIndex) throws ParseException { public static Name parseName(String name) throws ParseException { requireNonNull(name); String trimmedName = name.trim(); - if (!Name.validate(trimmedName)) { + if (!NameValidator.of().validate(trimmedName)) { throw new ParseException(Name.MESSAGE_CONSTRAINTS); } return new Name(trimmedName); } + public static Role parseRole(String name) throws ParseException { + requireNonNull(name); + String trimmedName = name.trim(); + if (!RoleValidator.of().validate(trimmedName)) { + throw new ParseException(Role.MESSAGE_CONSTRAINTS); + } + return new Role(trimmedName); + } + + public static Date parseDate(String name) throws ParseException { + requireNonNull(name); + String trimmedName = name.trim(); + if (!DateValidator.of().validate(trimmedName)) { + throw new ParseException(Date.MESSAGE_CONSTRAINTS); + } + return new Date(LocalDate.parse(trimmedName, DateTimeFormatter.ofPattern("dd/MM/yy"))); + } + /** * Parses a {@code String phone} into a {@code Phone}. * Leading and trailing whitespaces will be trimmed. @@ -89,7 +110,7 @@ public static Address parseAddress(String address) throws ParseException { public static Email parseEmail(String email) throws ParseException { requireNonNull(email); String trimmedEmail = email.trim(); - if (!Email.validate(trimmedEmail)) { + if (!EmailValidator.of().validate(trimmedEmail)) { throw new ParseException(Email.MESSAGE_CONSTRAINTS); } return new Email(trimmedEmail); diff --git a/src/main/java/seedu/address/logic/validator/DateValidator.java b/src/main/java/seedu/address/logic/validator/DateValidator.java new file mode 100644 index 00000000000..b6691fa0695 --- /dev/null +++ b/src/main/java/seedu/address/logic/validator/DateValidator.java @@ -0,0 +1,26 @@ +package seedu.address.logic.validator; + +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; + +public class DateValidator extends Validator { + private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("dd/MM/yy"); + private static DateValidator instance; + public static DateValidator of() { + if (instance == null) { + instance = new DateValidator(); + } + return instance; + } + private DateValidator() {} + @Override + public boolean validate(String input) { + try { + LocalDate.parse(input, FORMATTER); + return true; + } catch (DateTimeParseException e) { + return false; + } + } +} diff --git a/src/main/java/seedu/address/logic/validator/EmailValidator.java b/src/main/java/seedu/address/logic/validator/EmailValidator.java new file mode 100644 index 00000000000..d66f3ab0457 --- /dev/null +++ b/src/main/java/seedu/address/logic/validator/EmailValidator.java @@ -0,0 +1,25 @@ +package seedu.address.logic.validator; + +public class EmailValidator extends Validator { + private static final String SPECIAL_CHARACTERS = "+_.-"; + private static final String ALPHANUMERIC_NO_UNDERSCORE = "[^\\W_]+"; // alphanumeric characters except underscore + private static final String LOCAL_PART_REGEX = "^" + ALPHANUMERIC_NO_UNDERSCORE + "([" + SPECIAL_CHARACTERS + "]" + + ALPHANUMERIC_NO_UNDERSCORE + ")*"; + private static final String DOMAIN_PART_REGEX = ALPHANUMERIC_NO_UNDERSCORE + + "(-" + ALPHANUMERIC_NO_UNDERSCORE + ")*"; + private static final String DOMAIN_LAST_PART_REGEX = "(" + DOMAIN_PART_REGEX + "){2,}$"; // At least two chars + private static final String DOMAIN_REGEX = "(" + DOMAIN_PART_REGEX + "\\.)+" + DOMAIN_LAST_PART_REGEX; + public static final String VALIDATION_REGEX = LOCAL_PART_REGEX + "@" + DOMAIN_REGEX; + private static EmailValidator instance; + public static EmailValidator of() { + if (instance == null) { + instance = new EmailValidator(); + } + return instance; + } + private EmailValidator() {} + @Override + public boolean validate(String input) { + return input.matches(VALIDATION_REGEX); + } +} diff --git a/src/main/java/seedu/address/logic/validator/NameValidator.java b/src/main/java/seedu/address/logic/validator/NameValidator.java new file mode 100644 index 00000000000..39eca5e3b93 --- /dev/null +++ b/src/main/java/seedu/address/logic/validator/NameValidator.java @@ -0,0 +1,17 @@ +package seedu.address.logic.validator; + +public class NameValidator extends Validator { + public static final String VALIDATION_REGEX = "[\\p{Alnum}][\\p{Alnum} ]*"; + private static NameValidator instance; + public static NameValidator of() { + if (instance == null) { + instance = new NameValidator(); + } + return instance; + } + private NameValidator() {} + @Override + public boolean validate(String input) { + return input.matches(VALIDATION_REGEX); + } +} diff --git a/src/main/java/seedu/address/logic/validator/RoleValidator.java b/src/main/java/seedu/address/logic/validator/RoleValidator.java new file mode 100644 index 00000000000..1601d1cf0c3 --- /dev/null +++ b/src/main/java/seedu/address/logic/validator/RoleValidator.java @@ -0,0 +1,17 @@ +package seedu.address.logic.validator; + +public class RoleValidator extends Validator { + public static final String VALIDATION_REGEX = "^[\\p{Alnum}][\\p{Alnum} ]*(?: [\\p{Alnum} ]+)*$"; + private static RoleValidator instance; + public static RoleValidator of() { + if (instance == null) { + instance = new RoleValidator(); + } + return instance; + } + private RoleValidator() {} + @Override + public boolean validate(String input) { + return input.matches(VALIDATION_REGEX); + } +} diff --git a/src/main/java/seedu/address/logic/validator/Validator.java b/src/main/java/seedu/address/logic/validator/Validator.java new file mode 100644 index 00000000000..5a7ea96a3fd --- /dev/null +++ b/src/main/java/seedu/address/logic/validator/Validator.java @@ -0,0 +1,5 @@ +package seedu.address.logic.validator; + +public abstract class Validator { + public abstract boolean validate(T input); +} diff --git a/src/main/java/seedu/address/model/AddressBook.java b/src/main/java/seedu/address/model/AddressBook.java index 73397161e84..5ee952f086b 100644 --- a/src/main/java/seedu/address/model/AddressBook.java +++ b/src/main/java/seedu/address/model/AddressBook.java @@ -6,16 +6,15 @@ import javafx.collections.ObservableList; import seedu.address.commons.util.ToStringBuilder; -import seedu.address.model.person.Person; -import seedu.address.model.person.UniquePersonList; +import seedu.address.model.internshipapplication.UniqueList; /** * Wraps all data at the address-book level * Duplicates are not allowed (by .isSamePerson comparison) */ -public class AddressBook implements ReadOnlyAddressBook { +public class AddressBook> implements ReadOnlyAddressBook { - private final UniquePersonList persons; + private final UniqueList items; /* * The 'unusual' code block below is a non-static initialization block, sometimes used to avoid duplication @@ -25,7 +24,7 @@ public class AddressBook implements ReadOnlyAddressBook { * among constructors. */ { - persons = new UniquePersonList(); + items = new UniqueList<>(); } public AddressBook() {} @@ -33,7 +32,7 @@ public AddressBook() {} /** * Creates an AddressBook using the Persons in the {@code toBeCopied} */ - public AddressBook(ReadOnlyAddressBook toBeCopied) { + public AddressBook(ReadOnlyAddressBook toBeCopied) { this(); resetData(toBeCopied); } @@ -44,17 +43,17 @@ public AddressBook(ReadOnlyAddressBook toBeCopied) { * Replaces the contents of the person list with {@code persons}. * {@code persons} must not contain duplicate persons. */ - public void setPersons(List persons) { - this.persons.setPersons(persons); + public void setItems(List items) { + this.items.setItems(items); } /** * Resets the existing data of this {@code AddressBook} with {@code newData}. */ - public void resetData(ReadOnlyAddressBook newData) { + public void resetData(ReadOnlyAddressBook newData) { requireNonNull(newData); - setPersons(newData.getPersonList()); + setItems(newData.getList()); } //// person-level operations @@ -62,17 +61,17 @@ public void resetData(ReadOnlyAddressBook newData) { /** * Returns true if a person with the same identity as {@code person} exists in the address book. */ - public boolean hasPerson(Person person) { - requireNonNull(person); - return persons.contains(person); + public boolean hasItem(T item) { + requireNonNull(item); + return items.contains(item); } /** * Adds a person to the address book. * The person must not already exist in the address book. */ - public void addPerson(Person p) { - persons.add(p); + public void addItem(T p) { + items.add(p); } /** @@ -80,18 +79,18 @@ public void addPerson(Person p) { * {@code target} must exist in the address book. * The person identity of {@code editedPerson} must not be the same as another existing person in the address book. */ - public void setPerson(Person target, Person editedPerson) { - requireNonNull(editedPerson); + public void setItem(T target, T edited) { + requireNonNull(edited); - persons.setPerson(target, editedPerson); + items.setItem(target, edited); } /** * Removes {@code key} from this {@code AddressBook}. * {@code key} must exist in the address book. */ - public void removePerson(Person key) { - persons.remove(key); + public void removeItem(T key) { + items.remove(key); } //// util methods @@ -99,13 +98,13 @@ public void removePerson(Person key) { @Override public String toString() { return new ToStringBuilder(this) - .add("persons", persons) + .add("items", items) .toString(); } @Override - public ObservableList getPersonList() { - return persons.asUnmodifiableObservableList(); + public ObservableList getList() { + return items.asUnmodifiableObservableList(); } @Override @@ -115,16 +114,15 @@ public boolean equals(Object other) { } // instanceof handles nulls - if (!(other instanceof AddressBook)) { + if (!(other instanceof AddressBook otherAddressBook)) { return false; } - AddressBook otherAddressBook = (AddressBook) other; - return persons.equals(otherAddressBook.persons); + return items.equals(otherAddressBook.items); } @Override public int hashCode() { - return persons.hashCode(); + return items.hashCode(); } } diff --git a/src/main/java/seedu/address/model/HireMeComparable.java b/src/main/java/seedu/address/model/HireMeComparable.java new file mode 100644 index 00000000000..473bad4b773 --- /dev/null +++ b/src/main/java/seedu/address/model/HireMeComparable.java @@ -0,0 +1,5 @@ +package seedu.address.model; + +public interface HireMeComparable { + boolean isSame(T other); +} diff --git a/src/main/java/seedu/address/model/Model.java b/src/main/java/seedu/address/model/Model.java index 0221e1e667f..284b14467f8 100644 --- a/src/main/java/seedu/address/model/Model.java +++ b/src/main/java/seedu/address/model/Model.java @@ -5,14 +5,13 @@ import javafx.collections.ObservableList; import seedu.address.commons.core.GuiSettings; -import seedu.address.model.person.Person; /** * The API of the Model component. */ -public interface Model { +public interface Model { /** {@code Predicate} that always evaluate to true */ - Predicate PREDICATE_SHOW_ALL_PERSONS = unused -> true; + Predicate PREDICATE_SHOW_ALL = unused -> true; /** * Replaces user prefs data with the data in {@code userPrefs}. @@ -47,41 +46,41 @@ public interface Model { /** * Replaces address book data with the data in {@code addressBook}. */ - void setAddressBook(ReadOnlyAddressBook addressBook); + void setAddressBook(ReadOnlyAddressBook addressBook); /** Returns the AddressBook */ - ReadOnlyAddressBook getAddressBook(); + ReadOnlyAddressBook getAddressBook(); /** * Returns true if a person with the same identity as {@code person} exists in the address book. */ - boolean hasPerson(Person person); + boolean hasItem(T item); /** * Deletes the given person. * The person must exist in the address book. */ - void deletePerson(Person target); + void deleteItem(T target); /** * Adds the given person. * {@code person} must not already exist in the address book. */ - void addPerson(Person person); + void addItem(T item); /** * Replaces the given person {@code target} with {@code editedPerson}. * {@code target} must exist in the address book. * The person identity of {@code editedPerson} must not be the same as another existing person in the address book. */ - void setPerson(Person target, Person editedPerson); + void setItem(T target, T edited); /** Returns an unmodifiable view of the filtered person list */ - ObservableList getFilteredPersonList(); + ObservableList getFilteredList(); /** * Updates the filter of the filtered person list to filter by the given {@code predicate}. * @throws NullPointerException if {@code predicate} is null. */ - void updateFilteredPersonList(Predicate predicate); + void updateFilteredList(Predicate predicate); } diff --git a/src/main/java/seedu/address/model/ModelManager.java b/src/main/java/seedu/address/model/ModelManager.java index a0a2da7ea1f..2eb2a53f546 100644 --- a/src/main/java/seedu/address/model/ModelManager.java +++ b/src/main/java/seedu/address/model/ModelManager.java @@ -11,33 +11,32 @@ import javafx.collections.transformation.FilteredList; import seedu.address.commons.core.GuiSettings; import seedu.address.commons.core.LogsCenter; -import seedu.address.model.person.Person; + /** * Represents the in-memory model of the address book data. */ -public class ModelManager implements Model { +public class ModelManager> implements Model { private static final Logger logger = LogsCenter.getLogger(ModelManager.class); - - private final AddressBook addressBook; + private final AddressBook addressBook; private final UserPrefs userPrefs; - private final FilteredList filteredPersons; + private final FilteredList filtered; /** * Initializes a ModelManager with the given addressBook and userPrefs. */ - public ModelManager(ReadOnlyAddressBook addressBook, ReadOnlyUserPrefs userPrefs) { + public ModelManager(ReadOnlyAddressBook addressBook, ReadOnlyUserPrefs userPrefs) { requireAllNonNull(addressBook, userPrefs); logger.fine("Initializing with address book: " + addressBook + " and user prefs " + userPrefs); - this.addressBook = new AddressBook(addressBook); + this.addressBook = new AddressBook<>(addressBook); this.userPrefs = new UserPrefs(userPrefs); - filteredPersons = new FilteredList<>(this.addressBook.getPersonList()); + filtered = new FilteredList<>(this.addressBook.getList()); } public ModelManager() { - this(new AddressBook(), new UserPrefs()); + this(new AddressBook<>(), new UserPrefs()); } //=========== UserPrefs ================================================================================== @@ -78,37 +77,39 @@ public void setHireMeFilePath(Path hireMeFilePath) { //=========== AddressBook ================================================================================ @Override - public void setAddressBook(ReadOnlyAddressBook addressBook) { + public void setAddressBook(ReadOnlyAddressBook addressBook) { this.addressBook.resetData(addressBook); } @Override - public ReadOnlyAddressBook getAddressBook() { + public ReadOnlyAddressBook getAddressBook() { return addressBook; } @Override - public boolean hasPerson(Person person) { - requireNonNull(person); - return addressBook.hasPerson(person); + public boolean hasItem(T item) { + requireNonNull(item); + return addressBook.hasItem(item); } @Override - public void deletePerson(Person target) { - addressBook.removePerson(target); + public void deleteItem(T target) { + addressBook.removeItem(target); } @Override - public void addPerson(Person person) { - addressBook.addPerson(person); - updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); + public void addItem(T item) { + addressBook.addItem(item); + @SuppressWarnings("unchecked") + Predicate showAll = (Predicate) PREDICATE_SHOW_ALL; + updateFilteredList(showAll); } @Override - public void setPerson(Person target, Person editedPerson) { - requireAllNonNull(target, editedPerson); + public void setItem(T target, T edited) { + requireAllNonNull(target, edited); - addressBook.setPerson(target, editedPerson); + addressBook.setItem(target, edited); } //=========== Filtered Person List Accessors ============================================================= @@ -118,14 +119,14 @@ public void setPerson(Person target, Person editedPerson) { * {@code versionedAddressBook} */ @Override - public ObservableList getFilteredPersonList() { - return filteredPersons; + public ObservableList getFilteredList() { + return filtered; } @Override - public void updateFilteredPersonList(Predicate predicate) { + public void updateFilteredList(Predicate predicate) { requireNonNull(predicate); - filteredPersons.setPredicate(predicate); + filtered.setPredicate(predicate); } @Override @@ -135,14 +136,13 @@ public boolean equals(Object other) { } // instanceof handles nulls - if (!(other instanceof ModelManager)) { + if (!(other instanceof ModelManager otherModelManager)) { return false; } - ModelManager otherModelManager = (ModelManager) other; return addressBook.equals(otherModelManager.addressBook) && userPrefs.equals(otherModelManager.userPrefs) - && filteredPersons.equals(otherModelManager.filteredPersons); + && filtered.equals(otherModelManager.filtered); } } diff --git a/src/main/java/seedu/address/model/ReadOnlyAddressBook.java b/src/main/java/seedu/address/model/ReadOnlyAddressBook.java index 027574a5f84..1339cdaea81 100644 --- a/src/main/java/seedu/address/model/ReadOnlyAddressBook.java +++ b/src/main/java/seedu/address/model/ReadOnlyAddressBook.java @@ -1,17 +1,16 @@ package seedu.address.model; import javafx.collections.ObservableList; -import seedu.address.model.person.Person; /** * Unmodifiable view of a book */ -public interface ReadOnlyAddressBook { +public interface ReadOnlyAddressBook { /** * Returns an unmodifiable view of the persons list. * This list will not contain any duplicate persons. */ - ObservableList getPersonList(); + ObservableList getList(); } diff --git a/src/main/java/seedu/address/model/ReadOnlyHireMe.java b/src/main/java/seedu/address/model/ReadOnlyHireMe.java deleted file mode 100644 index 23d8678b18e..00000000000 --- a/src/main/java/seedu/address/model/ReadOnlyHireMe.java +++ /dev/null @@ -1,10 +0,0 @@ -package seedu.address.model; - -/** - * Unmodifiable view of hire me app - */ -public interface ReadOnlyHireMe { - - //ObservableList getInternshipList(); - -} diff --git a/src/main/java/seedu/address/model/person/Address.java b/src/main/java/seedu/address/model/internshipapplication/Address.java similarity index 96% rename from src/main/java/seedu/address/model/person/Address.java rename to src/main/java/seedu/address/model/internshipapplication/Address.java index 469a2cc9a1e..9c451c33dcf 100644 --- a/src/main/java/seedu/address/model/person/Address.java +++ b/src/main/java/seedu/address/model/internshipapplication/Address.java @@ -1,4 +1,4 @@ -package seedu.address.model.person; +package seedu.address.model.internshipapplication; import static java.util.Objects.requireNonNull; import static seedu.address.commons.util.AppUtil.checkArgument; diff --git a/src/main/java/seedu/address/model/person/Company.java b/src/main/java/seedu/address/model/internshipapplication/Company.java similarity index 82% rename from src/main/java/seedu/address/model/person/Company.java rename to src/main/java/seedu/address/model/internshipapplication/Company.java index 5372f9e5f65..e08a8eba345 100644 --- a/src/main/java/seedu/address/model/person/Company.java +++ b/src/main/java/seedu/address/model/internshipapplication/Company.java @@ -1,8 +1,11 @@ -package seedu.address.model.person; +package seedu.address.model.internshipapplication; import static java.util.Objects.requireNonNull; import static seedu.address.commons.util.AppUtil.checkArgument; +import seedu.address.logic.validator.EmailValidator; +import seedu.address.logic.validator.NameValidator; + /** * Represents a Company in the internship book. * Guarantees: immutable; the email and name are valid as declared in their respective validation methods. @@ -10,7 +13,7 @@ public class Company { private final Email email; - private final NameO name; + private final Name name; /** * Constructs a {@code Company} with a valid email and name. @@ -20,11 +23,11 @@ public class Company { * @throws NullPointerException if the {@code email} or {@code name} is null. * @throws IllegalArgumentException if the {@code email} or {@code name} do not satisfy their constraints. */ - public Company(Email email, NameO name) { + public Company(Email email, Name name) { requireNonNull(email); requireNonNull(name); - checkArgument(email.validate(email.getValue()), Email.MESSAGE_CONSTRAINTS); - checkArgument(name.validate(name.getValue()), NameO.MESSAGE_CONSTRAINTS); + checkArgument(EmailValidator.of().validate(email.getValue()), Email.MESSAGE_CONSTRAINTS); + checkArgument(NameValidator.of().validate(name.getValue()), Name.MESSAGE_CONSTRAINTS); this.email = email; this.name = name; } @@ -43,7 +46,7 @@ public Email getEmail() { * * @return the name object. */ - public NameO getName() { + public Name getName() { return name; } diff --git a/src/main/java/seedu/address/model/person/Date.java b/src/main/java/seedu/address/model/internshipapplication/Date.java similarity index 78% rename from src/main/java/seedu/address/model/person/Date.java rename to src/main/java/seedu/address/model/internshipapplication/Date.java index 57d4d3d7f0f..307bceccc63 100644 --- a/src/main/java/seedu/address/model/person/Date.java +++ b/src/main/java/seedu/address/model/internshipapplication/Date.java @@ -1,11 +1,12 @@ -package seedu.address.model.person; +package seedu.address.model.internshipapplication; import static java.util.Objects.requireNonNull; import static seedu.address.commons.util.AppUtil.checkArgument; import java.time.LocalDate; import java.time.format.DateTimeFormatter; -import java.time.format.DateTimeParseException; + +import seedu.address.logic.validator.DateValidator; /** * Represents a Date in the internship book. @@ -14,7 +15,7 @@ public class Date { public static final String MESSAGE_CONSTRAINTS = - "Dates should be in the format 'yyyy-MM-dd' and must be valid."; + "Dates should be in the format 'dd/MM/yy' and must be valid."; private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd"); @@ -41,7 +42,7 @@ public Date(LocalDate date) { */ public Date(String dateString) { requireNonNull(dateString); - checkArgument(Date.validate(dateString), MESSAGE_CONSTRAINTS); + checkArgument(DateValidator.of().validate(dateString), MESSAGE_CONSTRAINTS); this.date = LocalDate.parse(dateString, FORMATTER); } @@ -93,20 +94,4 @@ public boolean equals(Object other) { public int hashCode() { return date.hashCode(); } - - /** - * Validates the given string as a date. - * The string must be in the format 'yyyy-MM-dd'. - * - * @param test the string to be validated. - * @return true if the string is a valid date, false otherwise. - */ - public static boolean validate(String test) { - try { - LocalDate.parse(test, FORMATTER); - return true; - } catch (DateTimeParseException e) { - return false; - } - } } diff --git a/src/main/java/seedu/address/model/person/Email.java b/src/main/java/seedu/address/model/internshipapplication/Email.java similarity index 67% rename from src/main/java/seedu/address/model/person/Email.java rename to src/main/java/seedu/address/model/internshipapplication/Email.java index 5dd97febf63..439b6318f14 100644 --- a/src/main/java/seedu/address/model/person/Email.java +++ b/src/main/java/seedu/address/model/internshipapplication/Email.java @@ -1,8 +1,10 @@ -package seedu.address.model.person; +package seedu.address.model.internshipapplication; import static java.util.Objects.requireNonNull; import static seedu.address.commons.util.AppUtil.checkArgument; +import seedu.address.logic.validator.EmailValidator; + /** * Represents a Person's email in the network book. * Guarantees: immutable; is valid as declared in {@link #isValidEmail(String)} @@ -21,15 +23,6 @@ public class Email { + " - end with a domain label at least 2 characters long\n" + " - have each domain label start and end with alphanumeric characters\n" + " - have each domain label consist of alphanumeric characters, separated only by hyphens, if any."; - // alphanumeric and special characters - private static final String ALPHANUMERIC_NO_UNDERSCORE = "[^\\W_]+"; // alphanumeric characters except underscore - private static final String LOCAL_PART_REGEX = "^" + ALPHANUMERIC_NO_UNDERSCORE + "([" + SPECIAL_CHARACTERS + "]" - + ALPHANUMERIC_NO_UNDERSCORE + ")*"; - private static final String DOMAIN_PART_REGEX = ALPHANUMERIC_NO_UNDERSCORE - + "(-" + ALPHANUMERIC_NO_UNDERSCORE + ")*"; - private static final String DOMAIN_LAST_PART_REGEX = "(" + DOMAIN_PART_REGEX + "){2,}$"; // At least two chars - private static final String DOMAIN_REGEX = "(" + DOMAIN_PART_REGEX + "\\.)+" + DOMAIN_LAST_PART_REGEX; - public static final String VALIDATION_REGEX = LOCAL_PART_REGEX + "@" + DOMAIN_REGEX; private final String value; @@ -40,17 +33,10 @@ public class Email { */ public Email(String email) { requireNonNull(email); - checkArgument(validate(email), MESSAGE_CONSTRAINTS); + checkArgument(EmailValidator.of().validate(email), MESSAGE_CONSTRAINTS); value = email; } - /** - * Returns if a given string is a valid email. - */ - public static boolean validate(String test) { - return test.matches(VALIDATION_REGEX); - } - public String getValue() { return this.value; } diff --git a/src/main/java/seedu/address/model/person/Internship.java b/src/main/java/seedu/address/model/internshipapplication/InternshipApplication.java similarity index 86% rename from src/main/java/seedu/address/model/person/Internship.java rename to src/main/java/seedu/address/model/internshipapplication/InternshipApplication.java index 50eca3858a5..06c9a2699c6 100644 --- a/src/main/java/seedu/address/model/person/Internship.java +++ b/src/main/java/seedu/address/model/internshipapplication/InternshipApplication.java @@ -1,16 +1,17 @@ -package seedu.address.model.person; +package seedu.address.model.internshipapplication; import static java.util.Objects.requireNonNull; import java.util.Objects; import seedu.address.commons.util.ToStringBuilder; +import seedu.address.model.HireMeComparable; /** * Represents an Internship in the network book. * Guarantees: details are present and not null, field values are validated, immutable. */ -public class Internship { +public class InternshipApplication implements HireMeComparable { // Identity fields private final Company company; @@ -21,7 +22,7 @@ public class Internship { * Constructs an {@code Internship} with a company, date of application, and role. * Company, date of application, and role must be present and not null. */ - public Internship(Company company, Date dateOfApplication, Role role) { + public InternshipApplication(Company company, Date dateOfApplication, Role role) { requireNonNull(company); requireNonNull(dateOfApplication); requireNonNull(role); @@ -61,7 +62,8 @@ public Role getRole() { * Returns true if both internships have the same company, date of application, and role. * This defines a weaker notion of equality between two internships. */ - public boolean isSame(Internship otherInternship) { + @Override + public boolean isSame(InternshipApplication otherInternship) { if (otherInternship == this) { return true; } @@ -82,11 +84,11 @@ public boolean equals(Object other) { return true; } - if (!(other instanceof Internship)) { + if (!(other instanceof InternshipApplication)) { return false; } - Internship otherInternship = (Internship) other; + InternshipApplication otherInternship = (InternshipApplication) other; return company.equals(otherInternship.company) && dateOfApplication.equals(otherInternship.dateOfApplication) && role.equals(otherInternship.role); diff --git a/src/main/java/seedu/address/model/person/Name.java b/src/main/java/seedu/address/model/internshipapplication/Name.java similarity index 83% rename from src/main/java/seedu/address/model/person/Name.java rename to src/main/java/seedu/address/model/internshipapplication/Name.java index dd2de94b8ec..12df2a4fd16 100644 --- a/src/main/java/seedu/address/model/person/Name.java +++ b/src/main/java/seedu/address/model/internshipapplication/Name.java @@ -1,8 +1,10 @@ -package seedu.address.model.person; +package seedu.address.model.internshipapplication; import static java.util.Objects.requireNonNull; import static seedu.address.commons.util.AppUtil.checkArgument; +import seedu.address.logic.validator.NameValidator; + /** * Represents a Company's name in the internship book. * Guarantees: immutable; the name is valid as declared in {@link #validate(String)}. @@ -29,7 +31,7 @@ public class Name { */ public Name(String name) { requireNonNull(name); - checkArgument(Name.validate(name), MESSAGE_CONSTRAINTS); + checkArgument(NameValidator.of().validate(name), MESSAGE_CONSTRAINTS); this.value = name; } @@ -42,15 +44,6 @@ public String getValue() { return this.value; } - /** - * Static validation method to check if a given string is a valid company name. - * - * @param test the string to be validated. - * @return true if the string is a valid company name, false otherwise. - */ - public static boolean validate(String test) { - return test.matches(VALIDATION_REGEX); - } /** * Returns a string representation of the company name. diff --git a/src/main/java/seedu/address/model/person/NameContainsKeywordsPredicate.java b/src/main/java/seedu/address/model/internshipapplication/NameContainsKeywordsPredicate.java similarity index 96% rename from src/main/java/seedu/address/model/person/NameContainsKeywordsPredicate.java rename to src/main/java/seedu/address/model/internshipapplication/NameContainsKeywordsPredicate.java index ad767b01812..58e94e64278 100644 --- a/src/main/java/seedu/address/model/person/NameContainsKeywordsPredicate.java +++ b/src/main/java/seedu/address/model/internshipapplication/NameContainsKeywordsPredicate.java @@ -1,4 +1,4 @@ -package seedu.address.model.person; +package seedu.address.model.internshipapplication; import java.util.List; import java.util.function.Predicate; diff --git a/src/main/java/seedu/address/model/person/Person.java b/src/main/java/seedu/address/model/internshipapplication/Person.java similarity index 98% rename from src/main/java/seedu/address/model/person/Person.java rename to src/main/java/seedu/address/model/internshipapplication/Person.java index abe8c46b535..9b6d9664e65 100644 --- a/src/main/java/seedu/address/model/person/Person.java +++ b/src/main/java/seedu/address/model/internshipapplication/Person.java @@ -1,4 +1,4 @@ -package seedu.address.model.person; +package seedu.address.model.internshipapplication; import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; diff --git a/src/main/java/seedu/address/model/person/Phone.java b/src/main/java/seedu/address/model/internshipapplication/Phone.java similarity index 96% rename from src/main/java/seedu/address/model/person/Phone.java rename to src/main/java/seedu/address/model/internshipapplication/Phone.java index d733f63d739..581ab3b7914 100644 --- a/src/main/java/seedu/address/model/person/Phone.java +++ b/src/main/java/seedu/address/model/internshipapplication/Phone.java @@ -1,4 +1,4 @@ -package seedu.address.model.person; +package seedu.address.model.internshipapplication; import static java.util.Objects.requireNonNull; import static seedu.address.commons.util.AppUtil.checkArgument; diff --git a/src/main/java/seedu/address/model/person/Role.java b/src/main/java/seedu/address/model/internshipapplication/Role.java similarity index 84% rename from src/main/java/seedu/address/model/person/Role.java rename to src/main/java/seedu/address/model/internshipapplication/Role.java index ae34b005aaf..8de4886bffd 100644 --- a/src/main/java/seedu/address/model/person/Role.java +++ b/src/main/java/seedu/address/model/internshipapplication/Role.java @@ -1,8 +1,10 @@ -package seedu.address.model.person; +package seedu.address.model.internshipapplication; import static java.util.Objects.requireNonNull; import static seedu.address.commons.util.AppUtil.checkArgument; +import seedu.address.logic.validator.RoleValidator; + /** * Represents an Internship's role in the internship book. * Guarantees: immutable; the role is valid as declared in {@link #validate(String)}. @@ -30,7 +32,7 @@ public class Role { */ public Role(String role) { requireNonNull(role); - checkArgument(Role.validate(role), MESSAGE_CONSTRAINTS); + checkArgument(RoleValidator.of().validate(role), MESSAGE_CONSTRAINTS); this.value = role; } @@ -43,16 +45,6 @@ public String getValue() { return this.value; } - /** - * Static validation method to check if a given string is a valid role. - * - * @param test the string to be validated. - * @return true if the string is a valid role, false otherwise. - */ - public static boolean validate(String test) { - return test.matches(VALIDATION_REGEX); - } - /** * Returns a string representation of the role. * diff --git a/src/main/java/seedu/address/model/person/UniquePersonList.java b/src/main/java/seedu/address/model/internshipapplication/UniqueList.java similarity index 70% rename from src/main/java/seedu/address/model/person/UniquePersonList.java rename to src/main/java/seedu/address/model/internshipapplication/UniqueList.java index cc0a68d79f9..176edbd6962 100644 --- a/src/main/java/seedu/address/model/person/UniquePersonList.java +++ b/src/main/java/seedu/address/model/internshipapplication/UniqueList.java @@ -1,4 +1,4 @@ -package seedu.address.model.person; +package seedu.address.model.internshipapplication; import static java.util.Objects.requireNonNull; import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; @@ -8,8 +8,9 @@ import javafx.collections.FXCollections; import javafx.collections.ObservableList; -import seedu.address.model.person.exceptions.DuplicatePersonException; -import seedu.address.model.person.exceptions.PersonNotFoundException; +import seedu.address.model.HireMeComparable; +import seedu.address.model.internshipapplication.exceptions.DuplicatePersonException; +import seedu.address.model.internshipapplication.exceptions.PersonNotFoundException; /** * A list of persons that enforces uniqueness between its elements and does not allow nulls. @@ -22,25 +23,25 @@ * * @see Person#isSamePerson(Person) */ -public class UniquePersonList implements Iterable { +public class UniqueList> implements Iterable { - private final ObservableList internalList = FXCollections.observableArrayList(); - private final ObservableList internalUnmodifiableList = + private final ObservableList internalList = FXCollections.observableArrayList(); + private final ObservableList internalUnmodifiableList = FXCollections.unmodifiableObservableList(internalList); /** * Returns true if the list contains an equivalent person as the given argument. */ - public boolean contains(Person toCheck) { + public boolean contains(T toCheck) { requireNonNull(toCheck); - return internalList.stream().anyMatch(toCheck::isSamePerson); + return internalList.stream().anyMatch(toCheck::isSame); } /** * Adds a person to the list. * The person must not already exist in the list. */ - public void add(Person toAdd) { + public void add(T toAdd) { requireNonNull(toAdd); if (contains(toAdd)) { throw new DuplicatePersonException(); @@ -53,33 +54,33 @@ public void add(Person toAdd) { * {@code target} must exist in the list. * The person identity of {@code editedPerson} must not be the same as another existing person in the list. */ - public void setPerson(Person target, Person editedPerson) { - requireAllNonNull(target, editedPerson); + public void setItem(T target, T edited) { + requireAllNonNull(target, edited); int index = internalList.indexOf(target); if (index == -1) { throw new PersonNotFoundException(); } - if (!target.isSamePerson(editedPerson) && contains(editedPerson)) { + if (!target.isSame(edited) && contains(edited)) { throw new DuplicatePersonException(); } - internalList.set(index, editedPerson); + internalList.set(index, edited); } /** * Removes the equivalent person from the list. * The person must exist in the list. */ - public void remove(Person toRemove) { + public void remove(T toRemove) { requireNonNull(toRemove); if (!internalList.remove(toRemove)) { throw new PersonNotFoundException(); } } - public void setPersons(UniquePersonList replacement) { + public void setItems(UniqueList replacement) { requireNonNull(replacement); internalList.setAll(replacement.internalList); } @@ -88,24 +89,24 @@ public void setPersons(UniquePersonList replacement) { * Replaces the contents of this list with {@code persons}. * {@code persons} must not contain duplicate persons. */ - public void setPersons(List persons) { - requireAllNonNull(persons); - if (!personsAreUnique(persons)) { + public void setItems(List items) { + requireAllNonNull(items); + if (!areUnique(items)) { throw new DuplicatePersonException(); } - internalList.setAll(persons); + internalList.setAll(items); } /** * Returns the backing list as an unmodifiable {@code ObservableList}. */ - public ObservableList asUnmodifiableObservableList() { + public ObservableList asUnmodifiableObservableList() { return internalUnmodifiableList; } @Override - public Iterator iterator() { + public Iterator iterator() { return internalList.iterator(); } @@ -116,11 +117,10 @@ public boolean equals(Object other) { } // instanceof handles nulls - if (!(other instanceof UniquePersonList)) { + if (!(other instanceof UniqueList otherUniquePersonList)) { return false; } - UniquePersonList otherUniquePersonList = (UniquePersonList) other; return internalList.equals(otherUniquePersonList.internalList); } @@ -137,10 +137,10 @@ public String toString() { /** * Returns true if {@code persons} contains only unique persons. */ - private boolean personsAreUnique(List persons) { + private boolean areUnique(List persons) { for (int i = 0; i < persons.size() - 1; i++) { for (int j = i + 1; j < persons.size(); j++) { - if (persons.get(i).isSamePerson(persons.get(j))) { + if (persons.get(i).isSame(persons.get(j))) { return false; } } diff --git a/src/main/java/seedu/address/model/person/exceptions/DuplicateInternshipException.java b/src/main/java/seedu/address/model/internshipapplication/exceptions/DuplicateInternshipException.java similarity index 84% rename from src/main/java/seedu/address/model/person/exceptions/DuplicateInternshipException.java rename to src/main/java/seedu/address/model/internshipapplication/exceptions/DuplicateInternshipException.java index c5d35770934..23ed2a5037b 100644 --- a/src/main/java/seedu/address/model/person/exceptions/DuplicateInternshipException.java +++ b/src/main/java/seedu/address/model/internshipapplication/exceptions/DuplicateInternshipException.java @@ -1,4 +1,4 @@ -package seedu.address.model.person.exceptions; +package seedu.address.model.internshipapplication.exceptions; /** * Signals that the operation will result in duplicate Internships diff --git a/src/main/java/seedu/address/model/person/exceptions/DuplicatePersonException.java b/src/main/java/seedu/address/model/internshipapplication/exceptions/DuplicatePersonException.java similarity index 83% rename from src/main/java/seedu/address/model/person/exceptions/DuplicatePersonException.java rename to src/main/java/seedu/address/model/internshipapplication/exceptions/DuplicatePersonException.java index d7290f59442..021bfb2487a 100644 --- a/src/main/java/seedu/address/model/person/exceptions/DuplicatePersonException.java +++ b/src/main/java/seedu/address/model/internshipapplication/exceptions/DuplicatePersonException.java @@ -1,4 +1,4 @@ -package seedu.address.model.person.exceptions; +package seedu.address.model.internshipapplication.exceptions; /** * Signals that the operation will result in duplicate Persons (Persons are considered duplicates if they have the same diff --git a/src/main/java/seedu/address/model/person/exceptions/InternshipNotFoundException.java b/src/main/java/seedu/address/model/internshipapplication/exceptions/InternshipNotFoundException.java similarity index 71% rename from src/main/java/seedu/address/model/person/exceptions/InternshipNotFoundException.java rename to src/main/java/seedu/address/model/internshipapplication/exceptions/InternshipNotFoundException.java index 31dee04ea2e..22184dc8145 100644 --- a/src/main/java/seedu/address/model/person/exceptions/InternshipNotFoundException.java +++ b/src/main/java/seedu/address/model/internshipapplication/exceptions/InternshipNotFoundException.java @@ -1,4 +1,4 @@ -package seedu.address.model.person.exceptions; +package seedu.address.model.internshipapplication.exceptions; /** * Signals that the operation is unable to find the specified internship. diff --git a/src/main/java/seedu/address/model/person/exceptions/PersonNotFoundException.java b/src/main/java/seedu/address/model/internshipapplication/exceptions/PersonNotFoundException.java similarity index 69% rename from src/main/java/seedu/address/model/person/exceptions/PersonNotFoundException.java rename to src/main/java/seedu/address/model/internshipapplication/exceptions/PersonNotFoundException.java index fa764426ca7..a46df84156c 100644 --- a/src/main/java/seedu/address/model/person/exceptions/PersonNotFoundException.java +++ b/src/main/java/seedu/address/model/internshipapplication/exceptions/PersonNotFoundException.java @@ -1,4 +1,4 @@ -package seedu.address.model.person.exceptions; +package seedu.address.model.internshipapplication.exceptions; /** * Signals that the operation is unable to find the specified person. diff --git a/src/main/java/seedu/address/model/person/NameO.java b/src/main/java/seedu/address/model/person/NameO.java deleted file mode 100644 index 5dcae340763..00000000000 --- a/src/main/java/seedu/address/model/person/NameO.java +++ /dev/null @@ -1,97 +0,0 @@ -package seedu.address.model.person; - -import static java.util.Objects.requireNonNull; -import static seedu.address.commons.util.AppUtil.checkArgument; - -/** - * Represents a Company's name in the internship book. - * Guarantees: immutable; the name is valid as declared in {@link #validate(String)}. - */ -public class NameO { - - public static final String MESSAGE_CONSTRAINTS = - "Name should only contain alphanumeric characters, single spaces between words, " - + "and certain symbols like '&', '-', '\'', and '.', " - + "and it should not start or end with special characters or spaces."; - - /* - * Company names should start with an alphanumeric character, - * and can contain the characters &, ', -, . and single spaces between words. - * No leading/trailing spaces or special characters, and no multiple consecutive spaces are allowed. - */ - public static final String VALIDATION_REGEX = "^[\\p{Alnum}][\\p{Alnum}&'.-]*(?: [\\p{Alnum}&'.-]+)*$"; - - private final String value; - - /** - * Constructs a {@code Name}. - * - * @param name A valid company name. - * @throws NullPointerException if the {@code name} is null. - * @throws IllegalArgumentException if the {@code name} does not satisfy the constraints. - */ - public NameO(String name) { - requireNonNull(name); - checkArgument(NameO.validate(name), MESSAGE_CONSTRAINTS); - this.value = name; - } - - /** - * Returns the string representation of this company name. - * - * @return the company name as a string. - */ - public String getValue() { - return this.value; - } - - /** - * Static validation method to check if a given string is a valid company name. - * - * @param test the string to be validated. - * @return true if the string is a valid company name, false otherwise. - */ - public static boolean validate(String test) { - return test.matches(VALIDATION_REGEX); - } - - /** - * Returns a string representation of the company name. - * - * @return the name as a string. - */ - @Override - public String toString() { - return value; - } - - /** - * Compares this company name to another object. - * - * @param other the object to compare. - * @return true if the object is an instance of {@code Name} and has the same value, false otherwise. - */ - @Override - public boolean equals(Object other) { - if (other == this) { - return true; - } - - if (!(other instanceof NameO)) { - return false; - } - - NameO otherName = (NameO) other; - return value.equalsIgnoreCase(otherName.value); - } - - /** - * Returns the hash code of the company name. - * - * @return the hash code of the company name value. - */ - @Override - public int hashCode() { - return value.hashCode(); - } -} diff --git a/src/main/java/seedu/address/model/person/UniqueInternshipList.java b/src/main/java/seedu/address/model/person/UniqueInternshipList.java deleted file mode 100644 index b764b769fb8..00000000000 --- a/src/main/java/seedu/address/model/person/UniqueInternshipList.java +++ /dev/null @@ -1,170 +0,0 @@ -package seedu.address.model.person; - -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.person.exceptions.DuplicateInternshipException; -import seedu.address.model.person.exceptions.InternshipNotFoundException; - -/** - * A list of internships that enforces uniqueness between its elements and does not allow nulls. - * An internship is considered unique by comparing using {@code Internship#isSame(Internship)}. - * Adding, updating, or removing of internships follows this uniqueness constraint. - */ -public class UniqueInternshipList implements Iterable { - - private final ObservableList internalList = FXCollections.observableArrayList(); - private final ObservableList internalUnmodifiableList = - FXCollections.unmodifiableObservableList(internalList); - - /** - * Returns true if the list contains an equivalent internship as the given argument. - */ - public boolean contains(Internship toCheck) { - assert toCheck != null : "Internship toCheck should not be null"; - return internalList.stream().anyMatch(toCheck::isSame); - } - - /** - * Adds an internship to the list. - * The internship must not already exist in the list. - * @throws DuplicateInternshipException if the internship to add already exists. - */ - public void add(Internship toAdd) { - assert toAdd != null : "Internship toAdd should not be null"; - - if (contains(toAdd)) { - throw new DuplicateInternshipException(); - } - internalList.add(toAdd); - } - - /** - * Replaces the internship {@code target} in the list with {@code editedInternship}. - * {@code target} must exist in the list. - * The internship identity of {@code editedInternship} must not be the same - * as another existing internship in the list. - * @throws InternshipNotFoundException if {@code target} is not found in the list. - * @throws DuplicateInternshipException if the internship identity conflicts with another in the list. - */ - public void setInternship(Internship target, Internship editedInternship) { - requireAllNonNull(target, editedInternship); - - int index = internalList.indexOf(target); - if (index == -1) { - throw new InternshipNotFoundException(); - } - - if (!target.isSame(editedInternship) && contains(editedInternship)) { - throw new DuplicateInternshipException(); - } - - internalList.set(index, editedInternship); - } - - /** - * Removes the equivalent internship from the list. - * The internship must exist in the list. - * @throws InternshipNotFoundException if the internship to remove is not found in the list. - */ - public void remove(Internship toRemove) { - assert toRemove != null : "Internship to remove should not be null"; - if (!internalList.remove(toRemove)) { - throw new InternshipNotFoundException(); - } - } - - /** - * Checks if this list is empty. - */ - public boolean isEmpty() { - return internalList.isEmpty(); - } - - /** - * Returns the size of this list. - */ - public int size() { - return internalList.size(); - } - - /** - * Replaces the contents of this list with {@code internships}. - * {@code internships} must not contain duplicate internships. - * @throws DuplicateInternshipException if there are duplicates in the new list. - */ - public UniqueInternshipList setInternships(List internships) { - requireAllNonNull(internships); - assert internshipsAreUnique(internships) : "All internships in the list should be unique"; - - if (!internshipsAreUnique(internships)) { - throw new DuplicateInternshipException(); - } - - internalList.setAll(internships); - return this; - } - - /** - * Replaces the contents of this list with the contents of {@code internships}. - */ - public UniqueInternshipList setInternships(UniqueInternshipList internships) { - assert internships != null : "Internships list should not be null"; - internalList.setAll(internships.internalList); - return this; - } - - /** - * Returns the backing list as an unmodifiable {@code ObservableList}. - */ - public ObservableList asUnmodifiableObservableList() { - return internalUnmodifiableList; - } - - @Override - public Iterator iterator() { - return internalList.iterator(); - } - - @Override - public boolean equals(Object other) { - if (other == this) { - return true; - } - - if (!(other instanceof UniqueInternshipList)) { - return false; - } - - UniqueInternshipList otherList = (UniqueInternshipList) other; - return internalList.equals(otherList.internalList); - } - - @Override - public int hashCode() { - return internalList.hashCode(); - } - - @Override - public String toString() { - return internalList.toString(); - } - - /** - * Returns true if {@code internships} contains only unique internships. - */ - private boolean internshipsAreUnique(List internships) { - for (int i = 0; i < internships.size() - 1; i++) { - for (int j = i + 1; j < internships.size(); j++) { - if (internships.get(i).isSame(internships.get(j))) { - return false; - } - } - } - return true; - } -} diff --git a/src/main/java/seedu/address/model/util/SampleDataUtil.java b/src/main/java/seedu/address/model/util/SampleDataUtil.java index 1806da4facf..0ddd6532ca4 100644 --- a/src/main/java/seedu/address/model/util/SampleDataUtil.java +++ b/src/main/java/seedu/address/model/util/SampleDataUtil.java @@ -1,49 +1,31 @@ package seedu.address.model.util; +import java.time.LocalDate; import java.util.Arrays; import java.util.Set; import java.util.stream.Collectors; import seedu.address.model.AddressBook; import seedu.address.model.ReadOnlyAddressBook; -import seedu.address.model.person.Address; -import seedu.address.model.person.Email; -import seedu.address.model.person.Name; -import seedu.address.model.person.Person; -import seedu.address.model.person.Phone; +import seedu.address.model.internshipapplication.*; import seedu.address.model.tag.Tag; /** * Contains utility methods for populating {@code AddressBook} with sample data. */ public class SampleDataUtil { - public static Person[] getSamplePersons() { - return new Person[] { - new Person(new Name("Alex Yeoh"), new Phone("87438807"), new Email("alexyeoh@example.com"), - new Address("Blk 30 Geylang Street 29, #06-40"), - getTagSet("friends")), - new Person(new Name("Bernice Yu"), new Phone("99272758"), new Email("berniceyu@example.com"), - new Address("Blk 30 Lorong 3 Serangoon Gardens, #07-18"), - getTagSet("colleagues", "friends")), - new Person(new Name("Charlotte Oliveiro"), new Phone("93210283"), new Email("charlotte@example.com"), - new Address("Blk 11 Ang Mo Kio Street 74, #11-04"), - getTagSet("neighbours")), - new Person(new Name("David Li"), new Phone("91031282"), new Email("lidavid@example.com"), - new Address("Blk 436 Serangoon Gardens Street 26, #16-43"), - getTagSet("family")), - new Person(new Name("Irfan Ibrahim"), new Phone("92492021"), new Email("irfan@example.com"), - new Address("Blk 47 Tampines Street 20, #17-35"), - getTagSet("classmates")), - new Person(new Name("Roy Balakrishnan"), new Phone("92624417"), new Email("royb@example.com"), - new Address("Blk 45 Aljunied Street 85, #11-31"), - getTagSet("colleagues")) + public static InternshipApplication[] getSampleInternships() { + return new InternshipApplication[] { + new InternshipApplication(new Company( + new Email("company1@mail.com"),new Name("Company 1")), + new Date(LocalDate.now()), new Role("role 1")) }; } - public static ReadOnlyAddressBook getSampleAddressBook() { - AddressBook sampleAb = new AddressBook(); - for (Person samplePerson : getSamplePersons()) { - sampleAb.addPerson(samplePerson); + public static ReadOnlyAddressBook getSampleAddressBook() { + AddressBook sampleAb = new AddressBook<>(); + for (InternshipApplication sampleInternship : getSampleInternships()) { + sampleAb.addItem(sampleInternship); } return sampleAb; } diff --git a/src/main/java/seedu/address/storage/AddressBookStorage.java b/src/main/java/seedu/address/storage/AddressBookStorage.java index f2e015105ae..569a53fa93d 100644 --- a/src/main/java/seedu/address/storage/AddressBookStorage.java +++ b/src/main/java/seedu/address/storage/AddressBookStorage.java @@ -5,12 +5,13 @@ import java.util.Optional; import seedu.address.commons.exceptions.DataLoadingException; +import seedu.address.model.HireMeComparable; import seedu.address.model.ReadOnlyAddressBook; /** * Represents a storage for {@link seedu.address.model.AddressBook}. */ -public interface AddressBookStorage { +public interface AddressBookStorage> { /** * Returns the file path of the data file. @@ -23,23 +24,23 @@ public interface AddressBookStorage { * * @throws DataLoadingException if loading the data from storage failed. */ - Optional readAddressBook() throws DataLoadingException; + Optional> readAddressBook() throws DataLoadingException; /** * @see #getAddressBookFilePath() */ - Optional readAddressBook(Path filePath) throws DataLoadingException; + Optional> readAddressBook(Path filePath) throws DataLoadingException; /** * Saves the given {@link ReadOnlyAddressBook} to the storage. * @param addressBook cannot be null. * @throws IOException if there was any problem writing to the file. */ - void saveAddressBook(ReadOnlyAddressBook addressBook) throws IOException; + void saveAddressBook(ReadOnlyAddressBook addressBook) throws IOException; /** * @see #saveAddressBook(ReadOnlyAddressBook) */ - void saveAddressBook(ReadOnlyAddressBook addressBook, Path filePath) throws IOException; + void saveAddressBook(ReadOnlyAddressBook addressBook, Path filePath) throws IOException; } diff --git a/src/main/java/seedu/address/storage/HireMeStorage.java b/src/main/java/seedu/address/storage/HireMeStorage.java deleted file mode 100644 index c82d1771687..00000000000 --- a/src/main/java/seedu/address/storage/HireMeStorage.java +++ /dev/null @@ -1,44 +0,0 @@ -package seedu.address.storage; - -import java.io.IOException; -import java.nio.file.Path; -import java.util.Optional; - -import seedu.address.commons.exceptions.DataLoadingException; -import seedu.address.model.ReadOnlyHireMe; - -/** - * Represents a storage for HireMe - */ -public interface HireMeStorage { - /** - * Returns the file path of the data file. - */ - Path getHireMeFilePath(); - - /** - * Returns HireMe data as a {@link ReadOnlyHireMe}. - * Returns {@code Optional.empty()} if storage file is not found. - * - * @throws DataLoadingException if loading the data from storage failed. - */ - Optional readHireMe() throws DataLoadingException; - - /** - * @see #getHireMeFilePath() - */ - Optional readHireMe(Path filePath) throws DataLoadingException; - - /** - * Saves the given {@link ReadOnlyHireMe} to the storage. - * @param hireMe cannot be null. - * @throws IOException if there was any problem writing to the file. - */ - void saveHireMe(ReadOnlyHireMe hireMe) throws IOException; - - /** - * @see #saveHireMe(ReadOnlyHireMe) - */ - void saveHireMe(ReadOnlyHireMe hireMe, Path filePath) throws IOException; - -} diff --git a/src/main/java/seedu/address/storage/JsonAdaptedInternship.java b/src/main/java/seedu/address/storage/JsonAdaptedInternship.java new file mode 100644 index 00000000000..40d165951fa --- /dev/null +++ b/src/main/java/seedu/address/storage/JsonAdaptedInternship.java @@ -0,0 +1,60 @@ +package seedu.address.storage; + +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +import seedu.address.commons.exceptions.IllegalValueException; +import seedu.address.model.internshipapplication.*; + +/** + * Jackson-friendly version of {@link Person}. + */ +class JsonAdaptedInternship { + + public static final String MISSING_FIELD_MESSAGE_FORMAT = "Person's %s field is missing!"; + + private final String companyName; + private final String companyEmail; + private final String role; + private final LocalDate date; + + /** + * Constructs a {@code JsonAdaptedPerson} with the given person details. + */ + @JsonCreator + public JsonAdaptedInternship(@JsonProperty("companyName") String companyName, @JsonProperty("companyEmail") String companyEmail, + @JsonProperty("role") String role, @JsonProperty("date") String date ) { + this.companyName = companyName; + this.companyEmail = companyEmail; + this.role = role; + this.date = LocalDate.parse(date, DateTimeFormatter.ofPattern("yyyy-MM-dd")); + } + + /** + * Converts a given {@code Person} into this class for Jackson use. + */ + public JsonAdaptedInternship(InternshipApplication source) { + companyName = source.getCompany().getName().getValue(); + companyEmail = source.getCompany().getEmail().getValue(); + role = source.getRole().getValue(); + date = source.getDateOfApplication().getValue(); + } + + /** + * Converts this Jackson-friendly adapted person object into the model's {@code Person} object. + * + * @throws IllegalValueException if there were any data constraints violated in the adapted person. + */ + public InternshipApplication toModelType() throws IllegalValueException { + Name name = new Name(companyName); + Email email = new Email(companyEmail); + Company company = new Company(email, name); + Role role = new Role(this.role); + Date date = new Date(this.date); + return new InternshipApplication(company, date, role); + } + +} diff --git a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java b/src/main/java/seedu/address/storage/JsonAdaptedPerson.java deleted file mode 100644 index f51780d841c..00000000000 --- a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java +++ /dev/null @@ -1,110 +0,0 @@ -package seedu.address.storage; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; - -import seedu.address.commons.exceptions.IllegalValueException; -import seedu.address.model.person.Address; -import seedu.address.model.person.Email; -import seedu.address.model.person.Name; -import seedu.address.model.person.Person; -import seedu.address.model.person.Phone; -import seedu.address.model.tag.Tag; - -/** - * Jackson-friendly version of {@link Person}. - */ -class JsonAdaptedPerson { - - public static final String MISSING_FIELD_MESSAGE_FORMAT = "Person's %s field is missing!"; - - private final String name; - private final String phone; - private final String email; - private final String address; - private final List tags = new ArrayList<>(); - - /** - * Constructs a {@code JsonAdaptedPerson} with the given person details. - */ - @JsonCreator - public JsonAdaptedPerson(@JsonProperty("name") String name, @JsonProperty("phone") String phone, - @JsonProperty("email") String email, @JsonProperty("address") String address, - @JsonProperty("tags") List tags) { - this.name = name; - this.phone = phone; - this.email = email; - this.address = address; - if (tags != null) { - this.tags.addAll(tags); - } - } - - /** - * Converts a given {@code Person} into this class for Jackson use. - */ - public JsonAdaptedPerson(Person source) { - name = source.getName().getValue(); - phone = source.getPhone().value; - email = source.getEmail().getValue(); - address = source.getAddress().value; - tags.addAll(source.getTags().stream() - .map(JsonAdaptedTag::new) - .collect(Collectors.toList())); - } - - /** - * Converts this Jackson-friendly adapted person object into the model's {@code Person} object. - * - * @throws IllegalValueException if there were any data constraints violated in the adapted person. - */ - public Person toModelType() throws IllegalValueException { - final List personTags = new ArrayList<>(); - for (JsonAdaptedTag tag : tags) { - personTags.add(tag.toModelType()); - } - - if (name == null) { - throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Name.class.getSimpleName())); - } - if (!Name.validate(name)) { - throw new IllegalValueException(Name.MESSAGE_CONSTRAINTS); - } - final Name modelName = new Name(name); - - if (phone == null) { - throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Phone.class.getSimpleName())); - } - if (!Phone.isValidPhone(phone)) { - throw new IllegalValueException(Phone.MESSAGE_CONSTRAINTS); - } - final Phone modelPhone = new Phone(phone); - - if (email == null) { - throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, - Email.class.getSimpleName())); - } - if (!Email.validate(email)) { - throw new IllegalValueException(Email.MESSAGE_CONSTRAINTS); - } - final Email modelEmail = new Email(email); - - if (address == null) { - throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Address.class.getSimpleName())); - } - if (!Address.isValidAddress(address)) { - throw new IllegalValueException(Address.MESSAGE_CONSTRAINTS); - } - final Address modelAddress = new Address(address); - - final Set modelTags = new HashSet<>(personTags); - return new Person(modelName, modelPhone, modelEmail, modelAddress, modelTags); - } - -} diff --git a/src/main/java/seedu/address/storage/JsonAddressBookStorage.java b/src/main/java/seedu/address/storage/JsonAddressBookStorage.java index 0668dd97015..621a201dfe1 100644 --- a/src/main/java/seedu/address/storage/JsonAddressBookStorage.java +++ b/src/main/java/seedu/address/storage/JsonAddressBookStorage.java @@ -12,6 +12,7 @@ import seedu.address.commons.exceptions.IllegalValueException; import seedu.address.commons.util.FileUtil; import seedu.address.commons.util.JsonUtil; +import seedu.address.model.HireMeComparable; import seedu.address.model.ReadOnlyAddressBook; /** diff --git a/src/main/java/seedu/address/storage/JsonSerializableAddressBook.java b/src/main/java/seedu/address/storage/JsonSerializableAddressBook.java index 5efd834091d..b67d67ea52d 100644 --- a/src/main/java/seedu/address/storage/JsonSerializableAddressBook.java +++ b/src/main/java/seedu/address/storage/JsonSerializableAddressBook.java @@ -11,7 +11,7 @@ import seedu.address.commons.exceptions.IllegalValueException; import seedu.address.model.AddressBook; import seedu.address.model.ReadOnlyAddressBook; -import seedu.address.model.person.Person; +import seedu.address.model.internshipapplication.InternshipApplication; /** * An Immutable AddressBook that is serializable to JSON format. @@ -21,14 +21,14 @@ class JsonSerializableAddressBook { public static final String MESSAGE_DUPLICATE_PERSON = "Persons list contains duplicate person(s)."; - private final List persons = new ArrayList<>(); + private final List internships = new ArrayList<>(); /** * Constructs a {@code JsonSerializableAddressBook} with the given persons. */ @JsonCreator - public JsonSerializableAddressBook(@JsonProperty("persons") List persons) { - this.persons.addAll(persons); + public JsonSerializableAddressBook(@JsonProperty("internships") List internships) { + this.internships.addAll(internships); } /** @@ -36,8 +36,8 @@ public JsonSerializableAddressBook(@JsonProperty("persons") List source) { + internships.addAll(source.getList().stream().map(JsonAdaptedInternship::new).collect(Collectors.toList())); } /** @@ -45,14 +45,14 @@ public JsonSerializableAddressBook(ReadOnlyAddressBook source) { * * @throws IllegalValueException if there were any data constraints violated. */ - public AddressBook toModelType() throws IllegalValueException { - AddressBook addressBook = new AddressBook(); - for (JsonAdaptedPerson jsonAdaptedPerson : persons) { - Person person = jsonAdaptedPerson.toModelType(); - if (addressBook.hasPerson(person)) { + public AddressBook toModelType() throws IllegalValueException { + AddressBook addressBook = new AddressBook<>(); + for (JsonAdaptedInternship jsonAdaptedInternship : internships) { + InternshipApplication internship = jsonAdaptedInternship.toModelType(); + if (addressBook.hasItem(internship)) { throw new IllegalValueException(MESSAGE_DUPLICATE_PERSON); } - addressBook.addPerson(person); + addressBook.addItem(internship); } return addressBook; } diff --git a/src/main/java/seedu/address/storage/Storage.java b/src/main/java/seedu/address/storage/Storage.java index 9fba0c7a1d6..bfae16e2dee 100644 --- a/src/main/java/seedu/address/storage/Storage.java +++ b/src/main/java/seedu/address/storage/Storage.java @@ -5,6 +5,7 @@ import java.util.Optional; import seedu.address.commons.exceptions.DataLoadingException; +import seedu.address.model.HireMeComparable; import seedu.address.model.ReadOnlyAddressBook; import seedu.address.model.ReadOnlyUserPrefs; import seedu.address.model.UserPrefs; @@ -12,7 +13,7 @@ /** * API of the Storage component */ -public interface Storage extends AddressBookStorage, UserPrefsStorage { +public interface Storage> extends AddressBookStorage, UserPrefsStorage { @Override Optional readUserPrefs() throws DataLoadingException; @@ -24,9 +25,9 @@ public interface Storage extends AddressBookStorage, UserPrefsStorage { Path getAddressBookFilePath(); @Override - Optional readAddressBook() throws DataLoadingException; + Optional> readAddressBook() throws DataLoadingException; @Override - void saveAddressBook(ReadOnlyAddressBook addressBook) throws IOException; + void saveAddressBook(ReadOnlyAddressBook addressBook) throws IOException; } diff --git a/src/main/java/seedu/address/storage/StorageManager.java b/src/main/java/seedu/address/storage/StorageManager.java index 8b84a9024d5..7f105e84806 100644 --- a/src/main/java/seedu/address/storage/StorageManager.java +++ b/src/main/java/seedu/address/storage/StorageManager.java @@ -7,6 +7,7 @@ import seedu.address.commons.core.LogsCenter; import seedu.address.commons.exceptions.DataLoadingException; +import seedu.address.model.HireMeComparable; import seedu.address.model.ReadOnlyAddressBook; import seedu.address.model.ReadOnlyUserPrefs; import seedu.address.model.UserPrefs; @@ -14,16 +15,16 @@ /** * Manages storage of AddressBook data in local storage. */ -public class StorageManager implements Storage { +public class StorageManager> implements Storage { private static final Logger logger = LogsCenter.getLogger(StorageManager.class); - private AddressBookStorage addressBookStorage; + private AddressBookStorage addressBookStorage; private UserPrefsStorage userPrefsStorage; /** * Creates a {@code StorageManager} with the given {@code AddressBookStorage} and {@code UserPrefStorage}. */ - public StorageManager(AddressBookStorage addressBookStorage, UserPrefsStorage userPrefsStorage) { + public StorageManager(AddressBookStorage addressBookStorage, UserPrefsStorage userPrefsStorage) { this.addressBookStorage = addressBookStorage; this.userPrefsStorage = userPrefsStorage; } @@ -54,23 +55,23 @@ public Path getAddressBookFilePath() { } @Override - public Optional readAddressBook() throws DataLoadingException { + public Optional> readAddressBook() throws DataLoadingException { return readAddressBook(addressBookStorage.getAddressBookFilePath()); } @Override - public Optional readAddressBook(Path filePath) throws DataLoadingException { + public Optional> readAddressBook(Path filePath) throws DataLoadingException { logger.fine("Attempting to read data from file: " + filePath); return addressBookStorage.readAddressBook(filePath); } @Override - public void saveAddressBook(ReadOnlyAddressBook addressBook) throws IOException { + public void saveAddressBook(ReadOnlyAddressBook addressBook) throws IOException { saveAddressBook(addressBook, addressBookStorage.getAddressBookFilePath()); } @Override - public void saveAddressBook(ReadOnlyAddressBook addressBook, Path filePath) throws IOException { + public void saveAddressBook(ReadOnlyAddressBook addressBook, Path filePath) throws IOException { logger.fine("Attempting to write to data file: " + filePath); addressBookStorage.saveAddressBook(addressBook, filePath); } diff --git a/src/main/java/seedu/address/ui/PersonCard.java b/src/main/java/seedu/address/ui/InternshipCard.java similarity index 53% rename from src/main/java/seedu/address/ui/PersonCard.java rename to src/main/java/seedu/address/ui/InternshipCard.java index 52817fa3b9c..935d5eb8b82 100644 --- a/src/main/java/seedu/address/ui/PersonCard.java +++ b/src/main/java/seedu/address/ui/InternshipCard.java @@ -1,20 +1,17 @@ package seedu.address.ui; -import java.util.Comparator; - import javafx.fxml.FXML; import javafx.scene.control.Label; -import javafx.scene.layout.FlowPane; import javafx.scene.layout.HBox; import javafx.scene.layout.Region; -import seedu.address.model.person.Person; +import seedu.address.model.internshipapplication.InternshipApplication; /** * An UI component that displays information of a {@code Person}. */ -public class PersonCard extends UiPart { +public class InternshipCard extends UiPart { - private static final String FXML = "PersonListCard.fxml"; + private static final String FXML = "InternshipListCard.fxml"; /** * Note: Certain keywords such as "location" and "resources" are reserved keywords in JavaFX. @@ -24,7 +21,7 @@ public class PersonCard extends UiPart { * @see The issue on AddressBook level 4 */ - public final Person person; + public final InternshipApplication internship; @FXML private HBox cardPane; @@ -33,27 +30,22 @@ public class PersonCard extends UiPart { @FXML private Label id; @FXML - private Label phone; + private Label role; @FXML - private Label address; + private Label date; @FXML private Label email; - @FXML - private FlowPane tags; /** * Creates a {@code PersonCode} with the given {@code Person} and index to display. */ - public PersonCard(Person person, int displayedIndex) { + public InternshipCard(InternshipApplication internship, int displayedIndex) { super(FXML); - this.person = person; + this.internship = internship; id.setText(displayedIndex + ". "); - name.setText(person.getName().getValue()); - phone.setText(person.getPhone().value); - address.setText(person.getAddress().value); - email.setText(person.getEmail().getValue()); - person.getTags().stream() - .sorted(Comparator.comparing(tag -> tag.tagName)) - .forEach(tag -> tags.getChildren().add(new Label(tag.tagName))); + name.setText(internship.getCompany().getName().getValue()); + email.setText(internship.getCompany().getName().getValue()); + role.setText(internship.getRole().getValue()); + date.setText(internship.getDateOfApplication().getValue().toString()); } } diff --git a/src/main/java/seedu/address/ui/InternshipListPanel.java b/src/main/java/seedu/address/ui/InternshipListPanel.java new file mode 100644 index 00000000000..7043f94f109 --- /dev/null +++ b/src/main/java/seedu/address/ui/InternshipListPanel.java @@ -0,0 +1,49 @@ +package seedu.address.ui; + +import java.util.logging.Logger; + +import javafx.collections.ObservableList; +import javafx.fxml.FXML; +import javafx.scene.control.ListCell; +import javafx.scene.control.ListView; +import javafx.scene.layout.Region; +import seedu.address.commons.core.LogsCenter; +import seedu.address.model.internshipapplication.InternshipApplication; + +/** + * Panel containing the list of persons. + */ +public class InternshipListPanel extends UiPart { + private static final String FXML = "InternshipListPanel.fxml"; + private final Logger logger = LogsCenter.getLogger(InternshipListPanel.class); + + @FXML + private ListView internshipListView; + + /** + * Creates a {@code PersonListPanel} with the given {@code ObservableList}. + */ + public InternshipListPanel(ObservableList internshipList) { + super(FXML); + internshipListView.setItems(internshipList); + internshipListView.setCellFactory(listView -> new InternshipListViewCell()); + } + + /** + * Custom {@code ListCell} that displays the graphics of a {@code Person} using a {@code PersonCard}. + */ + class InternshipListViewCell extends ListCell { + @Override + protected void updateItem(InternshipApplication internship, boolean empty) { + super.updateItem(internship, empty); + + if (empty || internship == null) { + setGraphic(null); + setText(null); + } else { + setGraphic(new InternshipCard(internship, getIndex() + 1).getRoot()); + } + } + } + +} diff --git a/src/main/java/seedu/address/ui/MainWindow.java b/src/main/java/seedu/address/ui/MainWindow.java index 79e74ef37c0..d435b235175 100644 --- a/src/main/java/seedu/address/ui/MainWindow.java +++ b/src/main/java/seedu/address/ui/MainWindow.java @@ -16,6 +16,7 @@ import seedu.address.logic.commands.CommandResult; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.internshipapplication.InternshipApplication; /** * The Main Window. Provides the basic application layout containing @@ -28,10 +29,10 @@ public class MainWindow extends UiPart { private final Logger logger = LogsCenter.getLogger(getClass()); private Stage primaryStage; - private Logic logic; + private Logic logic; // Independent Ui parts residing in this Ui container - private PersonListPanel personListPanel; + private InternshipListPanel internshipListPanel; private ResultDisplay resultDisplay; private HelpWindow helpWindow; @@ -110,8 +111,8 @@ private void setAccelerator(MenuItem menuItem, KeyCombination keyCombination) { * Fills up all the placeholders of this window. */ void fillInnerParts() { - personListPanel = new PersonListPanel(logic.getFilteredPersonList()); - personListPanelPlaceholder.getChildren().add(personListPanel.getRoot()); + internshipListPanel = new InternshipListPanel(logic.getFilteredList()); + personListPanelPlaceholder.getChildren().add(internshipListPanel.getRoot()); resultDisplay = new ResultDisplay(); resultDisplayPlaceholder.getChildren().add(resultDisplay.getRoot()); @@ -163,8 +164,8 @@ private void handleExit() { primaryStage.hide(); } - public PersonListPanel getPersonListPanel() { - return personListPanel; + public InternshipListPanel getInternshipListPanel() { + return internshipListPanel; } /** diff --git a/src/main/java/seedu/address/ui/PersonListPanel.java b/src/main/java/seedu/address/ui/PersonListPanel.java deleted file mode 100644 index f4c501a897b..00000000000 --- a/src/main/java/seedu/address/ui/PersonListPanel.java +++ /dev/null @@ -1,49 +0,0 @@ -package seedu.address.ui; - -import java.util.logging.Logger; - -import javafx.collections.ObservableList; -import javafx.fxml.FXML; -import javafx.scene.control.ListCell; -import javafx.scene.control.ListView; -import javafx.scene.layout.Region; -import seedu.address.commons.core.LogsCenter; -import seedu.address.model.person.Person; - -/** - * Panel containing the list of persons. - */ -public class PersonListPanel extends UiPart { - private static final String FXML = "PersonListPanel.fxml"; - private final Logger logger = LogsCenter.getLogger(PersonListPanel.class); - - @FXML - private ListView personListView; - - /** - * Creates a {@code PersonListPanel} with the given {@code ObservableList}. - */ - public PersonListPanel(ObservableList personList) { - super(FXML); - personListView.setItems(personList); - personListView.setCellFactory(listView -> new PersonListViewCell()); - } - - /** - * Custom {@code ListCell} that displays the graphics of a {@code Person} using a {@code PersonCard}. - */ - class PersonListViewCell extends ListCell { - @Override - protected void updateItem(Person person, boolean empty) { - super.updateItem(person, empty); - - if (empty || person == null) { - setGraphic(null); - setText(null); - } else { - setGraphic(new PersonCard(person, getIndex() + 1).getRoot()); - } - } - } - -} diff --git a/src/main/java/seedu/address/ui/UiManager.java b/src/main/java/seedu/address/ui/UiManager.java index fdf024138bc..bba55536fb8 100644 --- a/src/main/java/seedu/address/ui/UiManager.java +++ b/src/main/java/seedu/address/ui/UiManager.java @@ -11,6 +11,7 @@ import seedu.address.commons.core.LogsCenter; import seedu.address.commons.util.StringUtil; import seedu.address.logic.Logic; +import seedu.address.model.internshipapplication.InternshipApplication; /** * The manager of the UI component. @@ -22,13 +23,13 @@ public class UiManager implements Ui { private static final Logger logger = LogsCenter.getLogger(UiManager.class); private static final String ICON_APPLICATION = "/images/address_book_32.png"; - private Logic logic; + private Logic logic; private MainWindow mainWindow; /** * Creates a {@code UiManager} with the given {@code Logic}. */ - public UiManager(Logic logic) { + public UiManager(Logic logic) { this.logic = logic; } diff --git a/src/main/resources/view/PersonListCard.fxml b/src/main/resources/view/InternshipListCard.fxml similarity index 84% rename from src/main/resources/view/PersonListCard.fxml rename to src/main/resources/view/InternshipListCard.fxml index 84e09833a87..5621a3aabd5 100644 --- a/src/main/resources/view/PersonListCard.fxml +++ b/src/main/resources/view/InternshipListCard.fxml @@ -3,7 +3,6 @@ - @@ -27,10 +26,9 @@