Skip to content

Commit

Permalink
Merge pull request #62 from autumn-sonata/storage-better-models
Browse files Browse the repository at this point in the history
Storage better models
  • Loading branch information
Eclipse-Dominator authored Oct 27, 2022
2 parents de520d0 + ae5cf31 commit a1df632
Show file tree
Hide file tree
Showing 72 changed files with 2,645 additions and 1,182 deletions.
4 changes: 2 additions & 2 deletions docs/DeveloperGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ This section describes some noteworthy details on how certain features are imple

#### Implementation

The Custom Fields mechanism is facilitated by the creation of a new `Field` that is stored within the `Fields` object
that each `Person` object has.
The Custom Fields mechanism is facilitated by the creation of a new `Field` that is stored within the `Fields` object
that each `Person` object has.

To add a custom field, the user should also provide a unique prefix for the `Field`. The prefix is parsed as a `Prefix`
object by `AddFieldCommandParser`, and then matched with the known `Prefix` objects stored in `FieldPrefixes`.
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/seedu/address/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.group.Group;
import seedu.address.model.item.AbstractContainerItem;
import seedu.address.model.item.AbstractSingleItem;
import seedu.address.model.person.Person;
import seedu.address.model.task.Task;

Expand All @@ -19,10 +19,11 @@
public interface Logic {
/**
* Executes the command and returns the result.
*
* @param commandText The command as entered by the user.
* @return the result of the command execution.
* @throws CommandException If an error occurs during command execution.
* @throws ParseException If an error occurs during parsing.
* @throws ParseException If an error occurs during parsing.
*/
CommandResult execute(String commandText) throws CommandException, ParseException;

Expand Down Expand Up @@ -57,5 +58,5 @@ public interface Logic {
*/
void setGuiSettings(GuiSettings guiSettings);

AbstractContainerItem getContainer();
AbstractSingleItem getContainer();
}
4 changes: 2 additions & 2 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.model.Model;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.group.Group;
import seedu.address.model.item.AbstractContainerItem;
import seedu.address.model.item.AbstractSingleItem;
import seedu.address.model.person.Person;
import seedu.address.model.task.Task;
import seedu.address.storage.Storage;
Expand Down Expand Up @@ -89,7 +89,7 @@ public ObservableList<Group> getFilteredGroupList() {
}

@Override
public AbstractContainerItem getContainer() {
public AbstractSingleItem getContainer() {
return model.getContextContainer();
}

Expand Down
34 changes: 22 additions & 12 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
import seedu.address.commons.util.CollectionUtil;
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.attribute.Address;
import seedu.address.model.attribute.Email;
import seedu.address.model.attribute.Name;
import seedu.address.model.attribute.Phone;
import seedu.address.model.person.Fields;
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;
import seedu.address.model.tag.Tag;

/**
Expand Down Expand Up @@ -55,7 +55,7 @@ public class EditCommand extends Command {
private final EditPersonDescriptor editPersonDescriptor;

/**
* @param index of the person in the filtered person list to edit
* @param index of the person in the filtered person list to edit
* @param editPersonDescriptor details to edit the person with
*/
public EditCommand(Index index, EditPersonDescriptor editPersonDescriptor) {
Expand Down Expand Up @@ -95,13 +95,20 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript
assert personToEdit != null;

Name updatedName = editPersonDescriptor.getName().orElse(personToEdit.getName());
Phone updatedPhone = editPersonDescriptor.getPhone().orElse(personToEdit.getPhone());
Email updatedEmail = editPersonDescriptor.getEmail().orElse(personToEdit.getEmail());
Address updatedAddress = editPersonDescriptor.getAddress().orElse(personToEdit.getAddress());
// Phone updatedPhone =
// editPersonDescriptor.getPhone().orElse(personToEdit.getPhone());
// Email updatedEmail =
// editPersonDescriptor.getEmail().orElse(personToEdit.getEmail());
// Address updatedAddress =
// editPersonDescriptor.getAddress().orElse(personToEdit.getAddress());
Set<Tag> updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags());
Fields updatedFields = editPersonDescriptor.getFields().orElse(personToEdit.getFields());

return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedTags, updatedFields);
// return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress,
// updatedTags, updatedFields);
Person person = new Person(updatedName.fullName, updatedFields);
person.setTags(updatedTags);
return person;
}

@Override
Expand All @@ -123,7 +130,8 @@ public boolean equals(Object other) {
}

/**
* Stores the details to edit the person with. Each non-empty field value will replace the
* Stores the details to edit the person with. Each non-empty field value will
* replace the
* corresponding field value of the person.
*/
public static class EditPersonDescriptor {
Expand All @@ -134,7 +142,8 @@ public static class EditPersonDescriptor {
private Set<Tag> tags;
private Fields fields;

public EditPersonDescriptor() {}
public EditPersonDescriptor() {
}

/**
* Copy constructor.
Expand Down Expand Up @@ -205,7 +214,8 @@ public void setTags(Set<Tag> tags) {
}

/**
* Returns an unmodifiable tag set, which throws {@code UnsupportedOperationException}
* Returns an unmodifiable tag set, which throws
* {@code UnsupportedOperationException}
* if modification is attempted.
* Returns {@code Optional#empty()} if {@code tags} is null.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.group.Group;
import seedu.address.model.item.AbstractContainerItem;
import seedu.address.model.item.AbstractSingleItem;

//@@author autumn-sonata
/**
Expand All @@ -38,7 +38,7 @@ public ChangeTeamCommand(Index targetIndex) {
@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
AbstractContainerItem toSwitch;
AbstractSingleItem toSwitch;
if (targetIndex == null) {
if (model.getContextContainer() != null) {
toSwitch = model.getContextContainer().getParent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.item.AbstractContainerItem;
import seedu.address.model.item.AbstractSingleItem;
import seedu.address.model.person.Person;

/**
Expand All @@ -36,7 +36,7 @@ public RemoveUserFromTeamCommand(Index targetIndex) {
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
Person toRemove;
AbstractContainerItem currContext = model.getContextContainer();
AbstractSingleItem currContext = model.getContextContainer();
if (currContext == null) {
return new CommandResult("You are not in any team scope right now!");
}
Expand Down
37 changes: 24 additions & 13 deletions src/main/java/seedu/address/logic/parser/AddCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@

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.Fields;
import seedu.address.model.person.Name;
import seedu.address.model.attribute.Address;
import seedu.address.model.attribute.Email;
import seedu.address.model.attribute.Name;
import seedu.address.model.attribute.Phone;
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;
import seedu.address.model.tag.Tag;

/**
Expand All @@ -28,30 +27,42 @@ public class AddCommandParser implements Parser<AddCommand> {
/**
* Parses the given {@code String} of arguments in the context of the AddCommand
* and returns an AddCommand object for execution.
*
* @throws ParseException if the user input does not conform the expected format
*/
public AddCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_TAG);
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)
if (!arePrefixesPresent(argMultimap, PREFIX_NAME)
|| !argMultimap.getPreamble().isEmpty()) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE));
}

Name name = ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get());
Phone phone = ParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE).get());
Email email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get());
Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get());
Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG));

Person person = new Person(name, phone, email, address, tagList, new Fields());
// Person person = new Person(name, phone, email, address, tagList, new
// Fields());
Person person = new Person(argMultimap.getValue(PREFIX_NAME).get());
person.setTags(tagList);
argMultimap.getValue(PREFIX_PHONE)
.map(str -> new Phone(str))
.ifPresent(phone -> person.addAttribute(phone));

argMultimap.getValue(PREFIX_EMAIL)
.map(str -> new Email(str))
.ifPresent(email -> person.addAttribute(email));

argMultimap.getValue(PREFIX_ADDRESS)
.map(str -> new Address(str))
.ifPresent(email -> person.addAttribute(email));
return new AddCommand(person);
}

/**
* Returns true if none of the prefixes contains empty {@code Optional} values in the given
* Returns true if none of the prefixes contains empty {@code Optional} values
* in the given
* {@code ArgumentMultimap}.
*/
private static boolean arePrefixesPresent(ArgumentMultimap argumentMultimap, Prefix... prefixes) {
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/seedu/address/logic/parser/EditCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@
public class EditCommandParser implements Parser<EditCommand> {

/**
* Parses the given {@code String} of arguments in the context of the EditCommand
* Parses the given {@code String} of arguments in the context of the
* EditCommand
* and returns an EditCommand object for execution.
*
* @throws ParseException if the user input does not conform the expected format
*/
public EditCommand parse(String args) throws ParseException {
requireNonNull(args);
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_TAG);
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_TAG);

Index index;

Expand Down Expand Up @@ -65,8 +66,10 @@ public EditCommand parse(String args) throws ParseException {
}

/**
* Parses {@code Collection<String> tags} into a {@code Set<Tag>} if {@code tags} is non-empty.
* If {@code tags} contain only one element which is an empty string, it will be parsed into a
* Parses {@code Collection<String> tags} into a {@code Set<Tag>} if
* {@code tags} is non-empty.
* If {@code tags} contain only one element which is an empty string, it will be
* parsed into a
* {@code Set<Tag>} containing zero tags.
*/
private Optional<Set<Tag>> parseTagsForEdit(Collection<String> tags) throws ParseException {
Expand Down
10 changes: 5 additions & 5 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,13 @@
import seedu.address.commons.core.index.Index;
import seedu.address.commons.util.StringUtil;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.attribute.Address;
import seedu.address.model.attribute.Email;
import seedu.address.model.attribute.Field;
import seedu.address.model.attribute.Name;
import seedu.address.model.attribute.Phone;
import seedu.address.model.group.Group;
import seedu.address.model.group.Path;
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.model.person.field.Field;
import seedu.address.model.tag.Tag;

/**
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/seedu/address/model/AccessDisplayFlags.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package seedu.address.model;

/**
* Enum to denote the binary bit flag of access and print permission of
* attributes and DisplayItems.
*/
public final class AccessDisplayFlags {
// flags for storage and display permissions
public static final int DISPLAY_OK = 1;
public static final int MENU_OK = 1 << 1;
public static final int GROUP = 1 << 2;
public static final int TASK = 1 << 3;
public static final int PERSON = 1 << 4;
public static final int ACCESS_OK = 0b11100;
public static final int HIDE_TYPE = 1 << 5;
public static final int DEFAULT = 0b111111;

// flags for style and formatting of labels
public static final int BOLD = 1;
public static final int ITALIC = 1 << 1;
public static final int UNDERLINE = 1 << 2;
public static final int STRIKETHROUGH = 1 << 3;
public static final int DROPSHADOW = 1 << 4;

// where there is a conflict, left > center > right
public static final int LEFT_JUSTIFY = 1 << 5;
public static final int CENTER_JUSTIFY = 1 << 6;
public static final int RIGHT_JUSTIFY = 1 << 7;

// where there is a conflict, normal > big > small
// big font will show as normal when in menu view !
public static final int FONT_SIZE_NORMAL = 1 << 8;
public static final int FONT_SIZE_BIG = 1 << 9;
public static final int FONT_SIZE_SMALL = 1 << 10;

// public static final int DEFAULT_STYLE = 0b00100100000;
public static final int DEFAULT_STYLE = 0b00100100000;
public static final int HEADER_STYLE = 0b01001010101;
}
12 changes: 11 additions & 1 deletion src/main/java/seedu/address/model/AddressBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public void resetData(ReadOnlyAddressBook newData) {

setPersons(newData.getPersonList());
setGroups(newData.getTeamsList());
setTasks(newData.getTasksList());
}

//// person-level operations
Expand Down Expand Up @@ -186,6 +187,14 @@ public void addTask(Task task) {
tasks.add(task);
}

/**
* Replaces the contents of the task list with {@code tasks}. {@code tasks}
* must not contain duplicate tasks.
*/
public void setTasks(List<Task> tasks) {
this.tasks.setItems(tasks);
}

/**
* Removes {@code task} from its group. Task must exist in address book.
*/
Expand Down Expand Up @@ -243,7 +252,8 @@ public ObservableList<Person> getPersonList() {
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof AddressBook // instanceof handles nulls
&& persons.equals(((AddressBook) other).persons) && teams.equals(((AddressBook) other).teams));
&& persons.equals(((AddressBook) other).persons) && teams.equals(((AddressBook) other).teams)
&& tasks.equals(((AddressBook) other).tasks));
}

@Override
Expand Down
Loading

0 comments on commit a1df632

Please sign in to comment.