forked from nus-cs2103-AY1819S2/addressbook-level4
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from CS2103-AY1819S2-W10-3/WorkListAndTest
Added list-w command
- Loading branch information
Showing
21 changed files
with
511 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/main/java/seedu/address/logic/commands/ListWorkListCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
src/main/java/seedu/address/model/equipment/UniqueWorkListList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.