Skip to content

Commit

Permalink
Merge branch 'master' into branch-update-add-command
Browse files Browse the repository at this point in the history
  • Loading branch information
Sherwyn Ng committed Mar 21, 2024
2 parents c97adee + be298d3 commit cf1b70d
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 26 deletions.
30 changes: 15 additions & 15 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ It is optimized for a _Command Line Interface_ (CLI), but you can still use the

* `list` : Lists all contacts.

* `add Company -e [email protected] -n 61234567`: Adds a company contact with name ``Company``, email ``[email protected]`` and number ``61234567``.
* `add -n Company -e [email protected] -t Role`: Adds a company contact with name ``Company``, email ``[email protected]`` and tag ``Role``.

* `del Company` : Deletes the contact with name ``'Company'``.
* `delete 1` : Deletes the contact with index ``1``.

* `exit` : Exits the app.<br><br>

Expand All @@ -59,16 +59,16 @@ It is optimized for a _Command Line Interface_ (CLI), but you can still use the
**Notes about the command format:**<br>

* Words in `UPPER_CASE` are the parameters to be supplied by the user.<br>
e.g. in `add n/NAME`, `NAME` is a parameter which can be used as `add n/John Doe`.
e.g. in `add -n COMPANY`, `COMPANY` is a parameter which can be used as `add -n DBS`.

* Items in square brackets are optional.<br>
e.g `n/NAME [t/TAG]` can be used as `n/John Doe t/friend` or as `n/John Doe`.
e.g `-n COMPANY [-p PHONE_NUMBER]` can be used as `-n DBS -p 61234567` or as `-n DBS`.

* Items with ``​ after them can be used multiple times including zero times.<br>
e.g. `[t/TAG]…​` can be used as ` ` (i.e. 0 times), `t/friend`, `t/friend t/family` etc.
* Items with ``​ after them can be used multiple times.<br>
e.g. `-t TAG…​` can be used as `-t Software Engineer`, `-t Software Engineer -t Data Analyst` etc.

* Parameters can be in any order.<br>
e.g. if the command specifies `n/NAME p/PHONE_NUMBER`, `p/PHONE_NUMBER n/NAME` is also acceptable.
e.g. if the command specifies `-n COMPANY -t Software Engineer`, `-t Software Engineer -n COMPANY` is also acceptable.

* Extraneous parameters for commands that do not take in parameters (such as `help`, `list`, `exit` and `clear`) will be ignored.<br>
e.g. if the command specifies `help 123`, it will be interpreted as `help`.
Expand All @@ -89,16 +89,16 @@ Format: `help`

Adds a company to the address book.

Format: `add n/NAME p/PHONE_NUMBER e/EMAIL a/ADDRESS [t/TAG]…​`
Format: `add -n COMPANY -e EMAIL -t TAG…​ [-p PHONE_NUMBER]`

<box type="tip" seamless>

**Tip:** A company can have any number of tags (including 0)
**Tip:** A company can have a phone number (optional) and multiple tags.
</box>

Examples:
* `add n/John Doe p/98765432 e/johnd@example.com a/John street, block 123, #01-01`
* `add n/Betsy Crowe t/friend e/betsycrowe@example.com a/Newgate Prison p/1234567 t/criminal`
* `add -n DBS -t Software Engineer -e dbs@example.com`
* `add -n Tiktok -t Data Analyst -e tiktok@example.com -p 61234567 -t AI Engineer`

### Listing all companies : `list`

Expand All @@ -110,18 +110,18 @@ Format: `list`

Edits an existing company in the address book.

Format: `edit INDEX [n/NAME] [p/PHONE] [e/EMAIL] [a/ADDRESS] [t/TAG]…​`
Format: `edit INDEX [-n NAME] [-p PHONE] [-e EMAIL] [-t TAG]…​`

* Edits the company at the specified `INDEX`. The index refers to the index number shown in the displayed company list. The index **must be a positive integer** 1, 2, 3, …​
* At least one of the optional fields must be provided.
* Existing values will be updated to the input values.
* When editing tags, the existing tags of the company will be removed i.e adding of tags is not cumulative.
* You can remove all the company’s tags by typing `t/` without
* You can remove all the company’s tags by typing `-t` without
specifying any tags after it.

Examples:
* `edit 1 p/91234567 e/johndoe@example.com` Edits the phone number and email address of the 1st company to be `91234567` and `johndoe@example.com` respectively.
* `edit 2 n/Betsy Crower t/` Edits the name of the 2nd company to be `Betsy Crower` and clears all existing tags.
* `edit 1 -p 91234567 -e dbs_hr@example.com` Edits the phone number and email address of the 1st company to be `91234567` and `dbs_hr@example.com` respectively.
* `edit 2 -n Meta -t` Edits the name of the 2nd company to be `Meta` and clears all existing tags.

### Locating companies by name: `find`

Expand Down
32 changes: 26 additions & 6 deletions src/main/java/seedu/address/model/tag/Tag.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
*/
public class Tag {

public static final String MESSAGE_CONSTRAINTS = "Tags names should be alphanumeric";
public static final String VALIDATION_REGEX = "\\p{Alnum}+";
public static final String MESSAGE_CONSTRAINTS = "Tags names should be alphanumeric and "
+ "contain only single space";
public static final String VALIDATION_REGEX = "\\b\\p{Alnum}+(?: \\p{Alnum}+)*\\b";

public final String tagName;
private final String tagName;

/**
* Constructs a {@code Tag}.
Expand Down Expand Up @@ -44,19 +45,38 @@ public boolean equals(Object other) {
}

Tag otherTag = (Tag) other;
return tagName.equals(otherTag.tagName);
return tagName.equalsIgnoreCase(otherTag.tagName);
}

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

/**
* Returns the tag name.
*/
public String getTagName() {
return tagName;
}

/**
* Format state as text for viewing.
*/
public String toString() {
return '[' + tagName + ']';
return '[' + capitalise() + ']';
}

/**
* Capitalises the first letter of each word in the tag name.
*/
public String capitalise() {
String[] words = tagName.split(" ");
StringBuilder result = new StringBuilder();
for (String word : words) {
result.append(word.substring(0, 1).toUpperCase()
+ word.substring(1).toLowerCase() + " ");
}
return result.toString().trim();
}
}
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/storage/JsonAdaptedTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public JsonAdaptedTag(String tagName) {
* Converts a given {@code Tag} into this class for Jackson use.
*/
public JsonAdaptedTag(Tag source) {
tagName = source.tagName;
tagName = source.getTagName();
}

@JsonValue
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/seedu/address/ui/CompanyCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import javafx.scene.layout.HBox;
import javafx.scene.layout.Region;
import seedu.address.model.person.Company;
import seedu.address.model.tag.Tag;

/**
* An UI component that displays information of a {@code Company}.
Expand Down Expand Up @@ -51,8 +52,8 @@ public CompanyCard(Company company, int displayedIndex) {
setPhone();

Check warning on line 52 in src/main/java/seedu/address/ui/CompanyCard.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/ui/CompanyCard.java#L52

Added line #L52 was not covered by tests
email.setText(company.getEmail().value);
company.getTags().stream()
.sorted(Comparator.comparing(tag -> tag.tagName))
.forEach(tag -> tags.getChildren().add(new Label(tag.tagName)));
.sorted(Comparator.comparing(Tag::getTagName))
.forEach(tag -> tags.getChildren().add(new Label(tag.capitalise())));
}

public void setPhone() {
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/seedu/address/model/tag/TagTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,14 @@ public void isValidTagName() {
assertThrows(NullPointerException.class, () -> Tag.isValidTagName(null));
}

@Test
public void capitaliseTest() {
Tag tag = new Tag("software engineer");
assert(tag.capitalise().equals("Software Engineer"));

tag = new Tag("softWare EnginEEr");
assert(tag.capitalise().equals("Software Engineer"));

}

}
4 changes: 2 additions & 2 deletions src/test/java/seedu/address/testutil/CompanyUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static String getPersonDetails(Company company) {
sb.append(PREFIX_PHONE + company.getPhone().value + " ");
sb.append(PREFIX_EMAIL + company.getEmail().value + " ");
company.getTags().stream().forEach(
s -> sb.append(PREFIX_TAG + s.tagName + " ")
s -> sb.append(PREFIX_TAG + s.getTagName() + " ")
);
return sb.toString();
}
Expand All @@ -51,7 +51,7 @@ public static String getEditPersonDescriptorDetails(EditCommand.EditCompanyDescr
if (tags.isEmpty()) {
sb.append(PREFIX_TAG);
} else {
tags.forEach(s -> sb.append(PREFIX_TAG).append(s.tagName).append(" "));
tags.forEach(s -> sb.append(PREFIX_TAG).append(s.getTagName()).append(" "));
}
}
return sb.toString();
Expand Down

0 comments on commit cf1b70d

Please sign in to comment.