Skip to content

Commit

Permalink
Merge pull request #65 from CS2103-AY1819S2-W10-3/WorkListAndTest
Browse files Browse the repository at this point in the history
Added list-w command
  • Loading branch information
racheltanxueqi committed Mar 19, 2019
2 parents 3906035 + 0d2bc2f commit d2ca28b
Show file tree
Hide file tree
Showing 21 changed files with 511 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* Lists all equipments in the equipment manager to the user.
*/
public class ListCommand extends Command {
public class ListEquipmentCommand extends Command {

public static final String COMMAND_WORD = "list-e";

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_WORKLISTS;

import seedu.address.logic.CommandHistory;
import seedu.address.model.Model;

/**
* Lists all equipments in the equipment manager to the user.
*/
public class ListWorkListCommand extends Command {

public static final String COMMAND_WORD = "list-w";

public static final String MESSAGE_SUCCESS = "Listed all worklists";

@Override
public CommandResult execute(Model model, CommandHistory history) {
requireNonNull(model);
model.updateFilteredWorkListList(PREDICATE_SHOW_ALL_WORKLISTS);
return new CommandResult(MESSAGE_SUCCESS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
import seedu.address.logic.commands.FindCommand;
import seedu.address.logic.commands.HelpCommand;
import seedu.address.logic.commands.HistoryCommand;
import seedu.address.logic.commands.ListCommand;
import seedu.address.logic.commands.ListEquipmentCommand;
import seedu.address.logic.commands.ListWorkListCommand;
import seedu.address.logic.commands.RedoCommand;
import seedu.address.logic.commands.SelectCommand;
import seedu.address.logic.commands.SortCommand;
Expand Down Expand Up @@ -70,8 +71,11 @@ public Command parseCommand(String userInput) throws ParseException {
case FindCommand.COMMAND_WORD:
return new FindCommandParser().parse(arguments);

case ListCommand.COMMAND_WORD:
return new ListCommand();
case ListEquipmentCommand.COMMAND_WORD:
return new ListEquipmentCommand();

case ListWorkListCommand.COMMAND_WORD:
return new ListWorkListCommand();

case HistoryCommand.COMMAND_WORD:
return new HistoryCommand();
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/seedu/address/model/EquipmentManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import seedu.address.commons.util.InvalidationListenerManager;
import seedu.address.model.equipment.Equipment;
import seedu.address.model.equipment.UniqueEquipmentList;
import seedu.address.model.equipment.UniqueWorkListList;
import seedu.address.model.equipment.WorkList;
import seedu.address.model.tag.Tag;

/**
Expand All @@ -20,6 +22,7 @@
public class EquipmentManager implements ReadOnlyEquipmentManager {

private final UniqueEquipmentList equipment;
private final UniqueWorkListList worklist;
private final InvalidationListenerManager invalidationListenerManager = new InvalidationListenerManager();

/*
Expand All @@ -31,6 +34,7 @@ public class EquipmentManager implements ReadOnlyEquipmentManager {
*/
{
equipment = new UniqueEquipmentList();
worklist = new UniqueWorkListList();
}

public EquipmentManager() {}
Expand Down Expand Up @@ -73,6 +77,14 @@ public boolean hasPerson(Equipment equipment) {
return this.equipment.contains(equipment);
}

/**
* Returns true if a WorkList with the same WorkListId as {@code WorkList} exists in the Equipment Manager.
*/
public boolean hasWorkList(WorkList worklist) {
requireNonNull(worklist);
return this.worklist.contains(worklist);
}

/**
* Adds a equipment to the address book.
* The equipment must not already exist in the address book.
Expand All @@ -82,6 +94,15 @@ public void addPerson(Equipment p) {
indicateModified();
}

/**
* Adds a WorkList to the Equipment Manager.
* The WorkList must not already exist in the Equipment Manager.
*/
public void addWorkList(WorkList w) {
worklist.add(w);
indicateModified();;
}

/**
* Replaces the given equipment {@code target} in the list with {@code editedEquipment}.
* {@code target} must exist in the address book.
Expand All @@ -108,6 +129,16 @@ public void removePerson(Equipment key) {
indicateModified();
}

/**
* Removes {@code key} from this {@code EquipmentManager}.
* {@code key} must exist in the Equipment Manager.
*/
public void removeWorkList(WorkList key) {
requireNonNull(key);
worklist.remove(key);
indicateModified();
}

/**
* Replaces the given equipment {@code target} in the list with {@code editedEquipment}.
* {@code target} must exist in the address book.
Expand Down Expand Up @@ -174,6 +205,10 @@ public ObservableList<Equipment> getPersonList() {
return equipment.asUnmodifiableObservableList();
}

public ObservableList<WorkList> getWorkListList() {
return worklist.asUnmodifiableObservableList();
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import javafx.collections.ObservableList;
import seedu.address.commons.core.GuiSettings;
import seedu.address.model.equipment.Equipment;
import seedu.address.model.equipment.WorkList;
import seedu.address.model.tag.Tag;

/**
Expand All @@ -16,6 +17,9 @@ public interface Model {
/** {@code Predicate} that always evaluate to true */
Predicate<Equipment> PREDICATE_SHOW_ALL_PERSONS = unused -> true;

/** {@code Predicate} that always evaluate to true */
Predicate<WorkList> PREDICATE_SHOW_ALL_WORKLISTS = unused -> true;

/**
* Replaces user prefs data with the data in {@code userPrefs}.
*/
Expand Down Expand Up @@ -82,12 +86,21 @@ public interface Model {
/** Returns an unmodifiable view of the filtered equipment list */
ObservableList<Equipment> getFilteredPersonList();

/** Returns an unmodifiable view of the filtered worklist list */
ObservableList<WorkList> getFilteredWorkListList();

/**
* Updates the filter of the filtered equipment list to filter by the given {@code predicate}.
* @throws NullPointerException if {@code predicate} is null.
*/
void updateFilteredPersonList(Predicate<Equipment> predicate);

/**
* Updates the filter of the filtered WorkList list to filter by the given {@code predicate}.
* @throws NullPointerException if {@code predicate} is null.
*/
void updateFilteredWorkListList(Predicate<WorkList> predicate);

/**
* Returns true if the model has previous address book states to restore.
*/
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import seedu.address.commons.core.GuiSettings;
import seedu.address.commons.core.LogsCenter;
import seedu.address.model.equipment.Equipment;
import seedu.address.model.equipment.WorkList;
import seedu.address.model.equipment.exceptions.EquipmentNotFoundException;
import seedu.address.model.tag.Tag;

Expand All @@ -28,6 +29,7 @@ public class ModelManager implements Model {
private final VersionedEquipmentManager versionedEquipmentManager;
private final UserPrefs userPrefs;
private final FilteredList<Equipment> filteredEquipments;
private final FilteredList<WorkList> filteredWorkList;
private final SimpleObjectProperty<Equipment> selectedPerson = new SimpleObjectProperty<>();

/**
Expand All @@ -43,6 +45,8 @@ public ModelManager(ReadOnlyEquipmentManager equipmentManager, ReadOnlyUserPrefs
this.userPrefs = new UserPrefs(userPrefs);
filteredEquipments = new FilteredList<>(versionedEquipmentManager.getPersonList());
filteredEquipments.addListener(this::ensureSelectedPersonIsValid);
filteredWorkList = new FilteredList<>(versionedEquipmentManager.getWorkListList());
//filteredWorkList.addListener(this::ensureSelectedworkListIsValid);
}

public ModelManager() {
Expand Down Expand Up @@ -127,6 +131,22 @@ public void updatePerson(Equipment target, Equipment editedEquipment) {
versionedEquipmentManager.updatePerson(target, editedEquipment);
}

//=========== Filtered WorkList List Accessors =============================================================

/**
* Returns an unmodifiable view of the list of {@code WorkList} backed by the internal list of
* {@code versionedEquipmentManager}
*/
public ObservableList<WorkList> getFilteredWorkListList() {
return filteredWorkList;
}

@Override
public void updateFilteredWorkListList(Predicate<WorkList> predicate) {
requireNonNull(predicate);
filteredWorkList.setPredicate(predicate);
}

//=========== Filtered Equipment List Accessors =============================================================

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

import static java.util.Objects.requireNonNull;
//import static seedu.address.commons.util.CollectionUtil.requireAllNonNull;

import java.util.Comparator;
import java.util.Iterator;
import java.util.List;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import seedu.address.model.equipment.exceptions.DuplicateEquipmentException;
import seedu.address.model.equipment.exceptions.EquipmentNotFoundException;

/**
* A list of worklists that enforces uniqueness between its elements and does not allow nulls.
* A WorkList is considered unique by comparing using {@code WorkList#isSameWorkList(WorkList)}.
* As such, adding and updating of worklists uses WorkList#isSameWorkList(WorkList) for equality so as to ensure
* that the WorkList being added or updated is unique in terms of identity in the UniqueWorkListList.
* However, the removal of a WorkList uses WorkList#equals(Object) so as to ensure that the WorkList
* with exactly the same fields will be removed.
*
* Supports a minimal set of list operations.
*
* @see WorkList#isSameWorkList(WorkList)
*/
public class UniqueWorkListList implements Iterable<WorkList> {

private final ObservableList<WorkList> internalList = FXCollections.observableArrayList();
private final ObservableList<WorkList> internalUnmodifiableList =
FXCollections.unmodifiableObservableList(internalList);

/**
* Returns true if the list contains an equivalent WorkList as the given argument.
*/
public boolean contains(WorkList toCheck) {
requireNonNull(toCheck);
return internalList.stream().anyMatch(toCheck::isSameWorkList);
}

/**
* Adds a WorkList to the list.
* The WorkList must not already exist in the list.
*/
public void add(WorkList toAdd) {
requireNonNull(toAdd);
if (contains(toAdd)) {
throw new DuplicateEquipmentException();
}
internalList.add(toAdd);
}

/**
* Removes the equivalent WorkList from the list.
* The WorkList must exist in the list.
*/
public void remove(WorkList toRemove) {
requireNonNull(toRemove);
if (!internalList.remove(toRemove)) {
throw new EquipmentNotFoundException();
}
}

/**
* Sorts the WorkList list by WorkListId.
*/
public void sortById() {
Comparator<WorkList> byId = Comparator.comparing(WorkList -> WorkList.getId().getId());
internalList.sort(byId);
}

/**
* See whether the given list of WorkList is unique,
* @param workListList a list of WorkList
* @return true if the list of WorkList contains unique WorkLists.
*/
public boolean areWorkListUnique(List<WorkList> workListList) {
return this.workListAreUnique(workListList);
}

/**
* Returns the backing list as an unmodifiable {@code ObservableList}.
*/
public ObservableList<WorkList> asUnmodifiableObservableList() {
return internalUnmodifiableList;
}

@Override
public Iterator<WorkList> iterator() {
return internalList.iterator();
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof UniqueWorkListList // instanceof handles nulls
&& internalList.equals(((UniqueWorkListList) other).internalList));
}

@Override
public int hashCode() {
return internalList.hashCode();
}

/**
* Returns true if {@code worklist} contains only unique WorkList.
*/
private boolean workListAreUnique(List<WorkList> worklist) {
for (int i = 0; i < worklist.size() - 1; i++) {
for (int j = i + 1; j < worklist.size(); j++) {
if (worklist.get(i).isSameWorkList(worklist.get(j))) {
return false;
}
}
}
return true;
}
}
15 changes: 13 additions & 2 deletions src/main/java/seedu/address/model/equipment/WorkList.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,18 @@ public void deleteEquipment(Equipment e) {
}

//List all the equipments in the work list.
public Equipment[] listEquipment() {
return (Equipment[]) this.equipments.toArray();
//public Equipment[] listEquipment() {
// return (Equipment[]) this.equipments.toArray();
//}

/**
* Returns true if both worklists have the same WorkListId.
*/
public boolean isSameWorkList(WorkList otherWorkList) {
if (otherWorkList == this) {
return true;
}

return this.getId().getId() == otherWorkList.getId().getId();
}
}
6 changes: 3 additions & 3 deletions src/test/java/seedu/address/logic/LogicManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import seedu.address.logic.commands.AddCommand;
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.HistoryCommand;
import seedu.address.logic.commands.ListCommand;
import seedu.address.logic.commands.ListEquipmentCommand;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.Model;
Expand Down Expand Up @@ -73,8 +73,8 @@ public void execute_commandExecutionError_throwsCommandException() {

@Test
public void execute_validCommand_success() {
String listCommand = ListCommand.COMMAND_WORD;
assertCommandSuccess(listCommand, ListCommand.MESSAGE_SUCCESS, model);
String listCommand = ListEquipmentCommand.COMMAND_WORD;
assertCommandSuccess(listCommand, ListEquipmentCommand.MESSAGE_SUCCESS, model);
assertHistoryCorrect(listCommand);
}

Expand Down
Loading

0 comments on commit d2ca28b

Please sign in to comment.