Skip to content

Commit

Permalink
Merge pull request #205
Browse files Browse the repository at this point in the history
Enhance TaskList and Children Manager
  • Loading branch information
NereusWB922 authored Nov 2, 2023
2 parents 932313f + 93d11ea commit 6bf2ce0
Show file tree
Hide file tree
Showing 19 changed files with 284 additions and 311 deletions.
5 changes: 3 additions & 2 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import seedu.address.model.profbook.Phone;
import seedu.address.model.profbook.Student;
import seedu.address.model.task.ReadOnlyTaskList;
import seedu.address.model.task.TaskListManager;

/**
* EditCommand is a class representing a command to edit the details of a person (either a student or a group) in
Expand Down Expand Up @@ -239,7 +240,7 @@ private static Student createEditedStudent(Student studentToEdit, EditStudentDes
Email updatedEmail = editStudentDescriptor.getEmail().orElse(studentToEdit.getEmail());
Address updatedAddress = editStudentDescriptor.getAddress().orElse(studentToEdit.getAddress());
StudentId updatedId = editStudentDescriptor.getId().orElse(studentToEdit.getId());
ReadOnlyTaskList taskList = new ReadOnlyTaskList(studentToEdit.getAllTasks());
ReadOnlyTaskList taskList = new TaskListManager(studentToEdit.getAllTasks());
return new Student(taskList, updatedName, updatedEmail, updatedPhone, updatedAddress, updatedId);
}

Expand All @@ -251,7 +252,7 @@ private static Group createEditedGroup(Group groupToEdit, EditGroupDescriptor ed
assert groupToEdit != null;
Name updatedName = editGroupDescriptor.getName().orElse(groupToEdit.getName());
GroupId updatedId = editGroupDescriptor.getId().orElse(groupToEdit.getId());
ReadOnlyTaskList taskList = new ReadOnlyTaskList(groupToEdit.getAllTask());
ReadOnlyTaskList taskList = new TaskListManager(groupToEdit.getAllTasks());
Map<Id, Student> students = groupToEdit.getChildren();
return new Group(taskList, students, updatedName, updatedId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import seedu.address.model.profbook.Name;
import seedu.address.model.profbook.Phone;
import seedu.address.model.profbook.Student;
import seedu.address.model.task.ReadOnlyTaskList;
import seedu.address.model.task.TaskListManager;

/**
* Parses input arguments and creates a new CreateStudentCommand object
Expand Down Expand Up @@ -78,7 +78,7 @@ public CreateStudentCommand parse(String args, AbsolutePath currPath) throws Par
? ParserUtil.parseAddress(argMultimap.getValue(OPTION_ADDRESS).get())
: Address.PLACEHOLDER;

Student student = new Student(new ReadOnlyTaskList(new ArrayList<>()), name, email, phone, address, id);
Student student = new Student(new TaskListManager(new ArrayList<>()), name, email, phone, address, id);

return new CreateStudentCommand(targetPath, student);
}
Expand Down
60 changes: 19 additions & 41 deletions src/main/java/seedu/address/model/ChildOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
import seedu.address.commons.core.LogsCenter;
import seedu.address.model.id.Id;
import seedu.address.model.profbook.ChildrenAndTaskListManager;
import seedu.address.model.profbook.ChildrenManager;
import seedu.address.model.profbook.IChildElement;
import seedu.address.model.profbook.IChildrenManager;
import seedu.address.model.profbook.exceptions.DuplicateChildException;
import seedu.address.model.profbook.exceptions.NoSuchChildException;
import seedu.address.model.task.ITaskListManager;
import seedu.address.model.task.Task;
import seedu.address.model.task.TaskListManager;

/**
* Encapsulates the logic to perform a generic child operation for child manager
Expand All @@ -22,11 +22,11 @@
*/
public class ChildOperation<T extends IChildElement<T>> implements IChildOperation<T> {

private final ChildrenManager<T> baseDir;
private final IChildrenManager<T> baseDir;

private final Logger logger = LogsCenter.getLogger(ChildOperation.class);

public ChildOperation(ChildrenManager<T> baseDir) {
public ChildOperation(IChildrenManager<T> baseDir) {
this.baseDir = baseDir;
}

Expand Down Expand Up @@ -124,25 +124,15 @@ public void addTaskToAllChildren(Task task, int level) {

for (IChildElement<?> child : children) {
Task clonedTask = task.clone();
if (!(child instanceof TaskListManager) && !(child instanceof ChildrenAndTaskListManager)) {
if (!(child instanceof ITaskListManager)) {
throw new IllegalArgumentException("All children must be task list manager.");
}

if (child instanceof TaskListManager) {
TaskListManager tlm = (TaskListManager) child;
if (tlm.contains(task)) {
continue;
}
tlm.addTask(clonedTask);
}

if (child instanceof ChildrenAndTaskListManager) {
ChildrenAndTaskListManager<?, ?> ctlm = (ChildrenAndTaskListManager<?, ?>) child;
if (ctlm.contains(task)) {
continue;
}
ctlm.addTask(clonedTask);
ITaskListManager tlm = (ITaskListManager) child;
if (tlm.contains(task)) {
continue;
}
tlm.addTask(clonedTask);
}
}

Expand All @@ -151,19 +141,13 @@ public boolean checkIfAllChildrenHaveTask(Task task, int level) {
List<IChildElement<?>> children = getAllTaskListManagerChildrenAtLevel(level);

for (IChildElement<?> child : children) {
if (child instanceof TaskListManager) {
TaskListManager tlm = (TaskListManager) child;
if (!tlm.contains(task)) {
return false;
}
} else if (child instanceof ChildrenAndTaskListManager) {
ChildrenAndTaskListManager<?, ?> ctlm = (ChildrenAndTaskListManager<?, ?>) child;
if (!ctlm.contains(task)) {
return false;
}
} else {
if (!(child instanceof ITaskListManager)) {
throw new IllegalArgumentException("All children must be task list manager.");
}
ITaskListManager tlm = (ITaskListManager) child;
if (!tlm.contains(task)) {
return false;
}
}

return true;
Expand All @@ -174,19 +158,13 @@ public boolean checkIfAnyChildHasTask(Task task, int level) {
List<IChildElement<?>> children = getAllTaskListManagerChildrenAtLevel(level);

for (IChildElement<?> child : children) {
if (child instanceof TaskListManager) {
TaskListManager tlm = (TaskListManager) child;
if (tlm.contains(task)) {
return true;
}
} else if (child instanceof ChildrenAndTaskListManager) {
ChildrenAndTaskListManager<?, ?> ctlm = (ChildrenAndTaskListManager<?, ?>) child;
if (ctlm.contains(task)) {
return true;
}
} else {
if (!(child instanceof ITaskListManager)) {
throw new IllegalArgumentException("All children must be task list manager.");
}
ITaskListManager tlm = (ITaskListManager) child;
if (tlm.contains(task)) {
return true;
}
}

return false;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ public ChildOperation<Student> groupChildOperation(AbsolutePath path) {
String.format(MESSAGE_INTERNAL_ERROR, "Path must have group information"));
checkArgument(hasGroup(path),
String.format(MESSAGE_INTERNAL_ERROR, "Group must exist in ProfBook"));
return new ChildOperation<>(getGroupFromPath(path).getChildrenManger());
return new ChildOperation<>(getGroupFromPath(path));
}

@Override
Expand All @@ -307,7 +307,7 @@ public TaskOperation taskOperation(AbsolutePath path) {
String.format(MESSAGE_INTERNAL_ERROR, "Path must exist in ProfBook"));

if (path.isGroupDirectory()) {
return new TaskOperation(getGroupFromPath(path).getTaskListManager());
return new TaskOperation(getGroupFromPath(path));
}

return new TaskOperation(getStudentFromPath(path));
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/seedu/address/model/TaskOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@

import seedu.address.commons.core.LogsCenter;
import seedu.address.commons.util.JsonUtil;
import seedu.address.model.task.ITaskListManager;
import seedu.address.model.task.Task;
import seedu.address.model.task.TaskListManager;

/**
* Encapsulates the required logic for task operation
*/
public class TaskOperation implements ITaskOperations {
private static final String MESSAGE_DUPLICATE_TASK = "Task must not exist in task list.";
private static final String MESSAGE_TASK_NOT_FOUND = "Task not found in task list.";
private final TaskListManager baseDir;
private final ITaskListManager baseDir;
private final Logger logger = LogsCenter.getLogger(JsonUtil.class);

public TaskOperation(TaskListManager baseDir) {
public TaskOperation(ITaskListManager baseDir) {
this.baseDir = baseDir;
}

Expand Down
Loading

0 comments on commit 6bf2ce0

Please sign in to comment.