Skip to content

Commit

Permalink
Merge pull request #99 from marquestye/fix-problems
Browse files Browse the repository at this point in the history
Update for more Module support
  • Loading branch information
xCOLOURx authored Oct 13, 2023
2 parents b00f1dc + bfcfac6 commit 8c9b7be
Show file tree
Hide file tree
Showing 21 changed files with 230 additions and 96 deletions.
6 changes: 3 additions & 3 deletions src/main/java/seedu/address/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.person.Person;
import seedu.address.model.module.Module;

/**
* API of the Logic component
Expand All @@ -30,8 +30,8 @@ public interface Logic {
*/
ReadOnlyAddressBook getAddressBook();

/** Returns an unmodifiable view of the filtered list of persons */
ObservableList<Person> getFilteredPersonList();
/** Returns an unmodifiable view of the filtered list of modules */
ObservableList<Module> getFilteredModuleList();

/**
* Returns the user prefs' address book file path.
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.Model;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.person.Person;
import seedu.address.model.module.Module;
import seedu.address.storage.Storage;

/**
Expand Down Expand Up @@ -67,8 +67,8 @@ public ReadOnlyAddressBook getAddressBook() {
}

@Override
public ObservableList<Person> getFilteredPersonList() {
return model.getFilteredPersonList();
public ObservableList<Module> getFilteredModuleList() {
return model.getFilteredModuleList();
}

@Override
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/seedu/address/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public class Messages {

public static final String MESSAGE_UNKNOWN_COMMAND = "Unknown command";
public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format! \n%1$s";
public static final String MESSAGE_INVALID_PERSON_DISPLAYED_INDEX = "The person index provided is invalid";
public static final String MESSAGE_PERSONS_LISTED_OVERVIEW = "%1$d persons listed!";
public static final String MESSAGE_INVALID_MODULE_DISPLAYED_INDEX = "The module index provided is invalid";
public static final String MESSAGE_MODULES_LISTED_OVERVIEW = "%1$d modules listed!";
public static final String MESSAGE_DUPLICATE_FIELDS =
"Multiple values specified for the following single-valued field(s): ";

Expand Down Expand Up @@ -49,6 +49,9 @@ public static String format(Person person) {
return builder.toString();
}

/**
* Formats the {@code module} for display to the user.
*/
public static String format(Module module) {
final StringBuilder builder = new StringBuilder();
builder.append((module.getModuleCode()))
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/seedu/address/logic/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public DeleteCommand(Index targetIndex) {

@Override
public CommandResult execute(Model model) throws CommandException {
throw new CommandException("DeleteCommand not implemented yet");
/*
requireNonNull(model);
List<Person> lastShownList = model.getFilteredPersonList();
Expand All @@ -43,6 +45,7 @@ public CommandResult execute(Model model) throws CommandException {
Person personToDelete = lastShownList.get(targetIndex.getZeroBased());
model.deletePerson(personToDelete);
return new CommandResult(String.format(MESSAGE_DELETE_PERSON_SUCCESS, Messages.format(personToDelete)));
*/
}

@Override
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
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 static seedu.address.model.Model.PREDICATE_SHOW_ALL_MODULES;

import java.util.Collections;
import java.util.HashSet;
Expand All @@ -27,6 +27,7 @@
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;
import seedu.address.model.tag.Tag;
import seedu.address.model.module.Module;

/**
* Edits the details of an existing person in the address book.
Expand Down Expand Up @@ -69,6 +70,8 @@ public EditCommand(Index index, EditPersonDescriptor editPersonDescriptor) {

@Override
public CommandResult execute(Model model) throws CommandException {
throw new CommandException("EditCommand not implemented yet");
/*
requireNonNull(model);
List<Person> lastShownList = model.getFilteredPersonList();
Expand All @@ -86,6 +89,7 @@ public CommandResult execute(Model model) throws CommandException {
model.setPerson(personToEdit, editedPerson);
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);
return new CommandResult(String.format(MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson)));
*/
}

/**
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/seedu/address/logic/commands/FindCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

import seedu.address.commons.util.ToStringBuilder;
import seedu.address.logic.Messages;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.person.NameContainsKeywordsPredicate;
import seedu.address.model.module.NameContainsKeywordsPredicate;

/**
* Finds and lists all persons in address book whose name contains any of the argument keywords.
* Finds and lists all modules in address book whose name contains any of the argument keywords.
* Keyword matching is case insensitive.
*/
public class FindCommand extends Command {
Expand All @@ -27,11 +28,14 @@ public FindCommand(NameContainsKeywordsPredicate predicate) {
}

@Override
public CommandResult execute(Model model) {
public CommandResult execute(Model model) throws CommandException {
throw new CommandException("FindCommand not implemented yet");
/*
requireNonNull(model);
model.updateFilteredPersonList(predicate);
return new CommandResult(
String.format(Messages.MESSAGE_PERSONS_LISTED_OVERVIEW, model.getFilteredPersonList().size()));
*/
}

@Override
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/seedu/address/logic/commands/ListCommand.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
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_MODULES;

import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;

/**
Expand All @@ -16,9 +17,9 @@ public class ListCommand extends Command {


@Override
public CommandResult execute(Model model) {
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);
model.updateFilteredModuleList(PREDICATE_SHOW_ALL_MODULES);
return new CommandResult(MESSAGE_SUCCESS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public AddCommand parse(String args) throws ParseException {
}

argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_CODE, PREFIX_YEAR, PREFIX_SEMESTER, PREFIX_GRADE);
ModuleCode code = ParserUtil.parseCode(argMultimap.getValue(PREFIX_CODE).get());
ModuleCode code = ParserUtil.parseModuleCode(argMultimap.getValue(PREFIX_CODE).get());
Year year = ParserUtil.parseYear(argMultimap.getValue(PREFIX_YEAR).get());
Semester semester = ParserUtil.parseSem(argMultimap.getValue(PREFIX_SEMESTER).get());
Semester semester = ParserUtil.parseSemester(argMultimap.getValue(PREFIX_SEMESTER).get());
Grade grade = ParserUtil.parseGrade(argMultimap.getValue(PREFIX_GRADE).get());

Module module = new Module(code, year, semester, grade);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.module.NameContainsKeywordsPredicate;

/**
* Parses input arguments and creates a new FindCommand object
Expand Down
95 changes: 81 additions & 14 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
import seedu.address.commons.core.index.Index;
import seedu.address.commons.util.StringUtil;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.Model;
import seedu.address.model.module.Description;
import seedu.address.model.module.ModuleCode;
import seedu.address.model.module.ModuleName;
import seedu.address.model.module.Year;
import seedu.address.model.module.Semester;
import seedu.address.model.module.Grade;
import seedu.address.model.module.ModuleName;
import seedu.address.model.module.Description;
import seedu.address.model.module.ModularCredit;
import seedu.address.model.person.Name;
import seedu.address.model.person.Address;
import seedu.address.model.person.Email;
import seedu.address.model.person.Phone;
Expand Down Expand Up @@ -48,7 +49,6 @@ public static Index parseIndex(String oneBasedIndex) throws ParseException {
*
* @throws ParseException if the given {@code name} is invalid.
*/
/*
public static Name parseName(String name) throws ParseException {
requireNonNull(name);
String trimmedName = name.trim();
Expand All @@ -58,8 +58,6 @@ public static Name parseName(String name) throws ParseException {
return new Name(trimmedName);
}

*/

/**
* Parses a {@code String phone} into a {@code Phone}.
* Leading and trailing whitespaces will be trimmed.
Expand Down Expand Up @@ -132,15 +130,27 @@ public static Set<Tag> parseTags(Collection<String> tags) throws ParseException
return tagSet;
}

public static ModuleCode parseCode(String code) throws ParseException {
requireNonNull(code);
String trimmedCode = code.trim();
/**
* Parses a {@code String moduleCode} into an {@code ModuleCode}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code moduleCode} is invalid.
*/
public static ModuleCode parseModuleCode(String moduleCode) throws ParseException {
requireNonNull(moduleCode);
String trimmedCode = moduleCode.trim();
if (!ModuleCode.isValidModuleCode(trimmedCode)) {
throw new ParseException(ModuleCode.MESSAGE_CONSTRAINTS);
}
return new ModuleCode(trimmedCode);
}

/**
* Parses a {@code String year} into an {@code Year}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code year} is invalid.
*/
public static Year parseYear(String year) throws ParseException {
requireNonNull(year);
String trimmedYear = year.trim();
Expand All @@ -150,15 +160,27 @@ public static Year parseYear(String year) throws ParseException {
return new Year(trimmedYear);
}

public static Semester parseSem(String sem) throws ParseException {
requireNonNull(sem);
String trimmedSem = sem.trim();
if (!Semester.isValidSemester(trimmedSem)) {
/**
* Parses a {@code String semester} into an {@code Semester}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code semester} is invalid.
*/
public static Semester parseSemester(String semester) throws ParseException {
requireNonNull(semester);
String trimmedSemester = semester.trim();
if (!Semester.isValidSemester(trimmedSemester)) {
throw new ParseException(Semester.MESSAGE_CONSTRAINTS);
}
return new Semester(trimmedSem);
return new Semester(trimmedSemester);
}

/**
* Parses a {@code String grade} into an {@code Grade}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code grade} is invalid.
*/
public static Grade parseGrade(String grade) throws ParseException {
requireNonNull(grade);
String trimmedGrade = grade.trim();
Expand All @@ -167,4 +189,49 @@ public static Grade parseGrade(String grade) throws ParseException {
}
return new Grade(trimmedGrade);
}

/**
* Parses a {@code String moduleName} into an {@code ModuleName}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code moduleName} is invalid.
*/
public static ModuleName parseModuleName(String moduleName) throws ParseException {
requireNonNull(moduleName);
String trimmedModuleName = moduleName.trim();
if (!ModuleName.isValidName(trimmedModuleName)) {
throw new ParseException(ModuleName.MESSAGE_CONSTRAINTS);
}
return new ModuleName(trimmedModuleName);
}

/**
* Parses a {@code String description} into an {@code Description}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code description} is invalid.
*/
public static Description parseDescription(String description) throws ParseException {
requireNonNull(description);
String trimmedDescription = description.trim();
if (!Description.isValidDescription(trimmedDescription)) {
throw new ParseException(Grade.MESSAGE_CONSTRAINTS);
}
return new Description(trimmedDescription);
}

/**
* Parses a {@code String modularCredit} into an {@code ModularCredit}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code modularCredit} is invalid.
*/
public static ModularCredit parseModularCredit(String modularCredit) throws ParseException {
requireNonNull(modularCredit);
String trimmedModularCredit = modularCredit.trim();
if (!ModularCredit.isValidModularCredit(trimmedModularCredit)) {
throw new ParseException(ModularCredit.MESSAGE_CONSTRAINTS);
}
return new ModularCredit(trimmedModularCredit);
}
}
21 changes: 10 additions & 11 deletions src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import javafx.collections.ObservableList;
import seedu.address.commons.core.GuiSettings;
import seedu.address.model.module.Module;
import seedu.address.model.person.Person;

/**
* The API of the Model component.
Expand Down Expand Up @@ -54,34 +53,34 @@ public interface Model {
ReadOnlyAddressBook getAddressBook();

/**
* Returns true if a person with the same identity as {@code person} exists in the address book.
* Returns true if a module with the same identity as {@code module} exists in the address book.
*/

boolean hasModule(Module module);

/**
* Deletes the given person.
* The person must exist in the address book.
* Deletes the given module.
* The module must exist in the address book.
*/
void deleteModule(Module module);

/**
* Adds the given person.
* {@code person} must not already exist in the address book.
* Adds the given module.
* {@code module} must not already exist in the address book.
*/
void addModule(Module module);

/**
* Replaces the given person {@code target} with {@code editedPerson}.
* Replaces the given module {@code target} with {@code editedModule}.
* {@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.
* The module identity of {@code editedModule} must not be the same as another existing module in the address book.
*/
void setModule(Module target, Module editedPerson);

/** Returns an unmodifiable view of the filtered person list */
/** Returns an unmodifiable view of the filtered module list */
ObservableList<Module> getFilteredModuleList();

/**
* Updates the filter of the filtered person list to filter by the given {@code predicate}.
* Updates the filter of the filtered module list to filter by the given {@code predicate}.
* @throws NullPointerException if {@code predicate} is null.
*/
void updateFilteredModuleList(Predicate<Module> predicate);
Expand Down
Loading

0 comments on commit 8c9b7be

Please sign in to comment.