Skip to content

Commit

Permalink
Merge 9885ab7 into 508e2cd
Browse files Browse the repository at this point in the history
  • Loading branch information
LiuXuanIan committed Apr 2, 2019
2 parents 508e2cd + 9885ab7 commit d21ea2d
Show file tree
Hide file tree
Showing 16 changed files with 163 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ public class AddWorkListCommand extends Command {
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Create a WorkList in the Equipment Manager. "
+ "Parameters: "
+ CliSyntax.PREFIX_DATE + "DATE "
+ "[" + CliSyntax.PREFIX_ASSIGNEE + "ASSIGNEE]...\n"
+ CliSyntax.PREFIX_ASSIGNEE + "ASSIGNEE "
+ CliSyntax.PREFIX_ID + "ID \n"
+ "Example: " + COMMAND_WORD + " "
+ CliSyntax.PREFIX_DATE + "2019-02-12 "
+ CliSyntax.PREFIX_ASSIGNEE + "Mei Yen ";
+ CliSyntax.PREFIX_DATE + "12 December 2019 "
+ CliSyntax.PREFIX_ASSIGNEE + "Mei Yen "
+ CliSyntax.PREFIX_ID + "13 ";

public static final String MESSAGE_SUCCESS = "New WorkList created: %1$s";
public static final String MESSAGE_DUPLICATE_EQUIPMENT = "Duplicated WorkList ID, "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import seedu.equipment.logic.commands.AddWorkListCommand;
import seedu.equipment.logic.parser.exceptions.ParseException;
import seedu.equipment.model.WorkList;
import seedu.equipment.model.WorkListId;
import seedu.equipment.model.equipment.Date;

/**
Expand All @@ -20,18 +21,20 @@ public class AddWorkListCommandParser implements Parser<AddWorkListCommand> {
*/
public AddWorkListCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, CliSyntax.PREFIX_DATE, CliSyntax.PREFIX_ASSIGNEE);
ArgumentTokenizer.tokenize(args, CliSyntax.PREFIX_DATE, CliSyntax.PREFIX_ASSIGNEE,
CliSyntax.PREFIX_ID);

if (!arePrefixesPresent(argMultimap, CliSyntax.PREFIX_DATE, CliSyntax.PREFIX_ASSIGNEE)
if (!arePrefixesPresent(argMultimap, CliSyntax.PREFIX_DATE, CliSyntax.PREFIX_ASSIGNEE, CliSyntax.PREFIX_ID)
|| !argMultimap.getPreamble().isEmpty()) {
throw new ParseException(String.format(
Messages.MESSAGE_INVALID_COMMAND_FORMAT, AddWorkListCommand.MESSAGE_USAGE));
}

Date date = ParserUtil.parseDate(argMultimap.getValue(CliSyntax.PREFIX_DATE).get());
String assignee = ParserUtil.parseAssignee(argMultimap.getValue(CliSyntax.PREFIX_ASSIGNEE).get());
WorkListId id = ParserUtil.parseWorkListId(argMultimap.getValue(CliSyntax.PREFIX_ID).get());

WorkList workList = new WorkList(date.value, assignee);
WorkList workList = new WorkList(date.value, assignee, id);

return new AddWorkListCommand(workList);
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/seedu/equipment/logic/parser/CliSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class CliSyntax {
public static final Prefix PREFIX_TAG = new Prefix("t/");
public static final Prefix PREFIX_DATE = new Prefix("d/");
public static final Prefix PREFIX_ASSIGNEE = new Prefix("a/");
public static final Prefix PREFIX_ID = new Prefix("i/");

public static final String DEFAULT_SORT_PARAMETER = "equipment";
public static final String ADDRESS_SORT_PARAMETER = "address";
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/seedu/equipment/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import seedu.equipment.commons.core.index.Index;
import seedu.equipment.commons.util.StringUtil;
import seedu.equipment.logic.parser.exceptions.ParseException;
import seedu.equipment.model.WorkListId;
import seedu.equipment.model.equipment.Address;
import seedu.equipment.model.equipment.Date;
import seedu.equipment.model.equipment.Name;
Expand Down Expand Up @@ -79,6 +80,21 @@ public static Phone parsePhone(String phone) throws ParseException {
return new Phone(trimmedPhone);
}

/**
* Parses a {@code String WorkListId} into a {@code WorkListId}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code WorkListId} is invalid.
*/
public static WorkListId parseWorkListId(String id) throws ParseException {
requireNonNull(id);
String trimmedId = id.trim();
if (!WorkListId.isValidWorkListId(trimmedId)) {
throw new ParseException(WorkListId.MESSAGE_CONSTRAINTS);
}
return new WorkListId(trimmedId);
}

/**
* Parses a {@code String equipment} into an {@code Address}.
* Leading and trailing whitespaces will be trimmed.
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/equipment/model/UniqueWorkListList.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void remove(WorkList toRemove) {
* Sorts the WorkList list by WorkListId.
*/
public void sortById() {
Comparator<WorkList> byId = Comparator.comparing(WorkList -> WorkList.getId().getId());
Comparator<WorkList> byId = Comparator.comparing(WorkList -> WorkList.getId().getIntId());
internalList.sort(byId);
}

Expand All @@ -82,7 +82,7 @@ public boolean areWorkListUnique(List<WorkList> workListList) {
* Returns the backing list as an unmodifiable {@code ObservableList}.
*/
public ObservableList<WorkList> asUnmodifiableObservableList() {
internalList.add(new WorkList("12 May 2019", "Mei Yen"));
internalList.add(new WorkList("12 May 2019", "Mei Yen", new WorkListId("1")));
return FXCollections.unmodifiableObservableList(internalList);
}

Expand Down
11 changes: 7 additions & 4 deletions src/main/java/seedu/equipment/model/WorkList.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ public class WorkList {
/**
* Every field must be present and not null.
*/
public WorkList(String date, String name) {
CollectionUtil.requireAllNonNull(date, name);
public WorkList(String date, String name, WorkListId id) {
CollectionUtil.requireAllNonNull(date, name, id);
this.date = date;
this.assignee = name;
this.equipments = new HashSet<>();
this.id = new WorkListId();
this.id = id;
}

public String getDate() {
Expand Down Expand Up @@ -92,6 +92,9 @@ public boolean isSameWorkList(WorkList otherWorkList) {
return true;
}

return this.getId().getId() == otherWorkList.getId().getId();
return otherWorkList.getAssignee().equals(getAssignee())
&& otherWorkList.getDate().equals(getDate())
&& otherWorkList.getId().equals(getId())
&& otherWorkList.getEquipments().equals(getEquipments());
}
}
57 changes: 40 additions & 17 deletions src/main/java/seedu/equipment/model/WorkListId.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,46 @@
package seedu.equipment.model;

import static java.util.Objects.requireNonNull;

import seedu.equipment.commons.util.AppUtil;

/**
* Representing the worklistid and the id is increasing based on the id history.
*/
public class WorkListId {

private static int idHist = 0;
//private static int idHist = 0;

private int thisId;
//private int thisId;

public static final String MESSAGE_CONSTRAINTS =
"WorkList id should only contain numbers, and it should be at least 1 digits long";
public static final String VALIDATION_REGEX = "[1-9]\\d{0,}";
public final String value;

/**
* Constructing the class, and pass down the ID number.
*/
public WorkListId() {
thisId = idHist + 1;
idHist++;
//public WorkListId() {
// thisId = idHist + 1;
// idHist++;
//}

/**
* Constructing the class, and pass the ID number.
*/
public WorkListId(String id) {
requireNonNull(id);
AppUtil.checkArgument(isValidWorkListId(id), MESSAGE_CONSTRAINTS);
value = id;
}

/**
* Returns true if a given WorkListId is a valid WorkListId.
*/
public static boolean isValidWorkListId(String test) {
//System.out.println("This id " + test + " is " + test.matches(VALIDATION_REGEX));
return test.matches(VALIDATION_REGEX);
}

/**
Expand All @@ -23,19 +49,16 @@ public WorkListId() {
*/
@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}

if (!(other instanceof WorkListId)) {
return false;
}

WorkListId otherWorkListId = (WorkListId) other;
return otherWorkListId.getId() == getId();
return other == this // short circuit if same object
|| (other instanceof WorkListId // instanceof handles nulls
&& value.equals(((WorkListId) other).value)); // state check
}

public int getId() {
return this.thisId;
/**
* Change the String value to integer.
* @return integer equals to value, throw exception is cannot convert.
*/
public int getIntId() throws NumberFormatException {
return Integer.parseInt(this.value);
}
}
2 changes: 1 addition & 1 deletion src/main/java/seedu/equipment/ui/WorkListCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public WorkListCard(WorkList workList, int displayedIndex) {
id.setText(displayedIndex + ". ");
assignee.setText(workList.getAssignee());
date.setText(workList.getDate());
worklistid.setText(String.valueOf(workList.getId().getId()));
worklistid.setText(String.valueOf(workList.getId().value));
workList.getEquipments().forEach(equipment -> {
String equipmentName = equipment.getName().name;
equipments.getChildren().add(new Label(equipmentName));
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/guitests/guihandles/WorkListCardHandle.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public List<String> getEquipments() {
public boolean equals(WorkList workList) {
return getDate().equals(workList.getDate())
&& getAssignee().equals(workList.getAssignee())
&& getworklistid().equals(workList.getId().getId())
&& getworklistid().equals(workList.getId().value)
&& ImmutableMultiset.copyOf(getEquipments()).equals(ImmutableMultiset.copyOf(workList
.getEquipments().stream()
.map(equipment -> equipment.getName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static seedu.equipment.logic.parser.CliSyntax.PREFIX_ADDRESS;
import static seedu.equipment.logic.parser.CliSyntax.PREFIX_ASSIGNEE;
import static seedu.equipment.logic.parser.CliSyntax.PREFIX_DATE;
import static seedu.equipment.logic.parser.CliSyntax.PREFIX_ID;
import static seedu.equipment.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.equipment.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.equipment.logic.parser.CliSyntax.PREFIX_PM;
Expand Down Expand Up @@ -42,10 +43,12 @@ public class CommandTestUtil {
public static final String VALID_TAG_HUSBAND = "husband";
public static final String VALID_TAG_FRIEND = "friend";
public static final String VALID_TAG_UNUSED = "unused"; // do not use this tag when creating a equipment
public static final String VALID_DATE_LISTA = "2019-02-12";
public static final String VALID_ASSIGNEE_LISTA = "Mei Yen";
public static final String VALID_DATE_LISTB = "2019-02-22";
public static final String VALID_ASSIGNEE_LISTB = "Rachel";
public static final String VALID_DATE_LISTA = "07 June 2020";
public static final String VALID_ASSIGNEE_LISTA = "Rachel";
public static final String VALID_ID_LISTA = "2";
public static final String VALID_DATE_LISTB = "08 July 2030";
public static final String VALID_ASSIGNEE_LISTB = "Yiqun";
public static final String VALID_ID_LISTB = "3";

public static final String NAME_DESC_AMY = " " + PREFIX_NAME + VALID_NAME_AMY;
public static final String NAME_DESC_BOB = " " + PREFIX_NAME + VALID_NAME_BOB;
Expand All @@ -61,8 +64,10 @@ public class CommandTestUtil {
public static final String TAG_DESC_HUSBAND = " " + PREFIX_TAG + VALID_TAG_HUSBAND;
public static final String DATE_DESC_LISTA = " " + PREFIX_DATE + VALID_DATE_LISTA;
public static final String ASSIGNEE_DESC_LISTA = " " + PREFIX_ASSIGNEE + VALID_ASSIGNEE_LISTA;
public static final String ID_DESC_LISTA = " " + PREFIX_ID + VALID_ID_LISTA;
public static final String DATE_DESC_LISTB = " " + PREFIX_DATE + VALID_DATE_LISTB;
public static final String ASSIGNEE_DESC_LISTB = " " + PREFIX_ASSIGNEE + VALID_ASSIGNEE_LISTB;
public static final String ID_DESC_LISTB = " " + PREFIX_ID + VALID_ID_LISTB;

public static final String INVALID_NAME_DESC = " " + PREFIX_NAME + "James&"; // '&' not allowed in names
public static final String INVALID_PHONE_DESC = " " + PREFIX_PHONE + "911a"; // 'a' not allowed in phones
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@

import static seedu.equipment.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.equipment.logic.commands.CommandTestUtil.ASSIGNEE_DESC_LISTA;
//import static seedu.equipment.logic.commands.CommandTestUtil.ASSIGNEE_DESC_LISTB;
import static seedu.equipment.logic.commands.CommandTestUtil.ASSIGNEE_DESC_LISTB;
import static seedu.equipment.logic.commands.CommandTestUtil.DATE_DESC_LISTA;
//import static seedu.equipment.logic.commands.CommandTestUtil.DATE_DESC_LISTB;
//import static seedu.equipment.logic.commands.CommandTestUtil.INVALID_ASSIGNEE_DESC;
//import static seedu.equipment.logic.commands.CommandTestUtil.INVALID_DATE_DESC;
//import static seedu.equipment.logic.commands.CommandTestUtil.PREAMBLE_NON_EMPTY;
//import static seedu.equipment.logic.commands.CommandTestUtil.PREAMBLE_WHITESPACE;
import static seedu.equipment.logic.commands.CommandTestUtil.ID_DESC_LISTA;
import static seedu.equipment.logic.commands.CommandTestUtil.PREAMBLE_WHITESPACE;
import static seedu.equipment.logic.commands.CommandTestUtil.VALID_ASSIGNEE_LISTA;
import static seedu.equipment.logic.commands.CommandTestUtil.VALID_DATE_LISTA;
import static seedu.equipment.logic.parser.CommandParserTestUtil.assertParseFailure;
//import static seedu.equipment.logic.parser.CommandParserTestUtil.assertParseSuccess;
import static seedu.equipment.logic.parser.CommandParserTestUtil.assertParseSuccess;
import static seedu.equipment.testutil.TypicalWorkLists.LISTC;

import org.junit.Test;
Expand All @@ -21,6 +22,7 @@
import seedu.equipment.model.WorkList;
//import seedu.equipment.model.equipment.Name;
//import seedu.equipment.model.equipment.Phone;
//import seedu.equipment.model.equipment.Date;
import seedu.equipment.testutil.WorkListBuilder;

public class AddWorkListCommandParserTest {
Expand All @@ -31,16 +33,16 @@ public void parse_allFieldsPresent_success() {
WorkList expectedWorkList = new WorkListBuilder(LISTC).build();

// whitespace only preamble
//assertParseSuccess(parser, PREAMBLE_WHITESPACE + DATE_DESC_LISTA + ASSIGNEE_DESC_LISTA,
//new AddWorkListCommand(expectedWorkList));
assertParseSuccess(parser, PREAMBLE_WHITESPACE + DATE_DESC_LISTA + ASSIGNEE_DESC_LISTA
+ ID_DESC_LISTA, new AddWorkListCommand(expectedWorkList));

// multiple dates - last date accepted
//assertParseSuccess(parser, DATE_DESC_LISTA + DATE_DESC_LISTB + ASSIGNEE_DESC_LISTA,
//new AddWorkListCommand(expectedWorkList));
//assertParseSuccess(parser, DATE_DESC_LISTA + DATE_DESC_LISTB + ASSIGNEE_DESC_LISTA
// + ID_DESC_LISTA, new AddWorkListCommand(expectedWorkList));

// multiple phones - last phone accepted
//assertParseSuccess(parser, DATE_DESC_LISTA + ASSIGNEE_DESC_LISTB + ASSIGNEE_DESC_LISTA,
//new AddWorkListCommand(expectedWorkList));
assertParseSuccess(parser, DATE_DESC_LISTA + ASSIGNEE_DESC_LISTB + ASSIGNEE_DESC_LISTA
+ ID_DESC_LISTA, new AddWorkListCommand(expectedWorkList));
}

@Test
Expand All @@ -60,7 +62,8 @@ public void parse_compulsoryFieldMissing_failure() {
@Test
public void parse_invalidValue_failure() {
// invalid date
//assertParseFailure(parser, INVALID_DATE_DESC + ASSIGNEE_DESC_LISTA, Name.MESSAGE_CONSTRAINTS);
//assertParseFailure(parser, INVALID_DATE_DESC + ASSIGNEE_DESC_LISTA + ID_DESC_LISTA
// , Date.MESSAGE_CONSTRAINTS);

// invalid assignee
//assertParseFailure(parser, DATE_DESC_LISTA + INVALID_ASSIGNEE_DESC, Phone.MESSAGE_CONSTRAINTS);
Expand Down
27 changes: 26 additions & 1 deletion src/test/java/seedu/equipment/model/WorkListIdTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,38 @@

import org.junit.Test;

import seedu.equipment.testutil.Assert;

public class WorkListIdTest {

@Test
public void isValidWorkListId() {
// null WorkListId
Assert.assertThrows(NullPointerException.class, () -> WorkListId.isValidWorkListId(null));

assertFalse(WorkListId.isValidWorkListId("")); //empty String
assertFalse(WorkListId.isValidWorkListId(" ")); //space-only
assertFalse(WorkListId.isValidWorkListId("id")); //non-numeric
assertFalse(WorkListId.isValidWorkListId("999i9")); // alphabets within digits
assertFalse(WorkListId.isValidWorkListId("98 90")); // spaces within digits

assertTrue(WorkListId.isValidWorkListId("1")); // exactly 1 digit
assertTrue(WorkListId.isValidWorkListId("1000"));
}

@Test
public void equals() {
WorkListId id1 = new WorkListId();
WorkListId id1 = new WorkListId("1000");
assertFalse(id1.equals(null));

assertTrue(id1.equals(id1));
}

@Test
public void getIntIdMustFollowFormat() {

WorkListId validId = new WorkListId("1000");

assertTrue(validId.getIntId() == 1000);
}
}
4 changes: 2 additions & 2 deletions src/test/java/seedu/equipment/model/WorkListTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public void deleteEquipmentMustExist() {
@Test
public void isSameWorkList() {

// same id -> same worklist.
assertTrue(LISTA.getId().getId() == LISTA.getId().getId());
// same id, different attributes -> same WorkList.
assertTrue(LISTA.isSameWorkList(LISTA));
}

@Test
Expand Down
Loading

0 comments on commit d21ea2d

Please sign in to comment.