From 4a91a8cb077296b0fd427e4676faf0ad6e2db612 Mon Sep 17 00:00:00 2001 From: De Zhang Lee Date: Mon, 16 Dec 2019 00:17:46 +0800 Subject: [PATCH] proposed enhancements for issue #233 --- src/seedu/addressbook/common/Messages.java | 2 +- .../data/person/ReadOnlyPerson.java | 10 ++ src/seedu/addressbook/ui/TextUi.java | 15 ++- test/EXPECTED.TXT | 96 +++++++++---------- 4 files changed, 72 insertions(+), 51 deletions(-) diff --git a/src/seedu/addressbook/common/Messages.java b/src/seedu/addressbook/common/Messages.java index c19f9ea4b..5d4ecb90e 100644 --- a/src/seedu/addressbook/common/Messages.java +++ b/src/seedu/addressbook/common/Messages.java @@ -7,7 +7,7 @@ public class Messages { public static final String MESSAGE_GOODBYE = "Good bye!"; public static final String MESSAGE_INIT_FAILED = "Failed to initialise address book application. Exiting..."; - public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format! \n%1$s"; + public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format!\n%1$s"; public static final String MESSAGE_INVALID_PERSON_DISPLAYED_INDEX = "The person index provided is invalid"; public static final String MESSAGE_PERSON_NOT_IN_ADDRESSBOOK = "Person could not be found in address book"; public static final String MESSAGE_PERSONS_LISTED_OVERVIEW = "%1$d persons listed!"; diff --git a/src/seedu/addressbook/data/person/ReadOnlyPerson.java b/src/seedu/addressbook/data/person/ReadOnlyPerson.java index 1493f0a2b..1cc2ee584 100644 --- a/src/seedu/addressbook/data/person/ReadOnlyPerson.java +++ b/src/seedu/addressbook/data/person/ReadOnlyPerson.java @@ -68,8 +68,13 @@ default String getAsTextShowAll() { } builder.append(getAddress()) .append(" Tags: "); + boolean hasTags = false; for (Tag tag : getTags()) { builder.append(tag); + hasTags = true; + } + if (hasTags == false) { + builder.append("[NONE]"); } return builder.toString(); } @@ -90,8 +95,13 @@ default String getAsTextHidePrivate() { builder.append(" Address: ").append(getAddress()); } builder.append(" Tags: "); + boolean hasTags = false; for (Tag tag : getTags()) { builder.append(tag); + hasTags = true; + } + if (hasTags == false) { + builder.append("[NONE]"); } return builder.toString(); } diff --git a/src/seedu/addressbook/ui/TextUi.java b/src/seedu/addressbook/ui/TextUi.java index 04a8bc57a..96c6a8df8 100644 --- a/src/seedu/addressbook/ui/TextUi.java +++ b/src/seedu/addressbook/ui/TextUi.java @@ -27,6 +27,9 @@ public class TextUi { /** A decorative prefix added to the beginning of lines printed by AddressBook */ private static final String LINE_PREFIX = "|| "; + /** Same as LINE_PREFIX but no space */ + private static final String LINE_PREFIX_NO_SPACE = "||"; + /** A platform independent line separator. */ private static final String LS = System.lineSeparator(); @@ -118,8 +121,16 @@ public void showInitFailedMessage() { /** Shows message(s) to the user */ public void showToUser(String... message) { - for (String m : message) { - out.println(LINE_PREFIX + m.replace("\n", LS + LINE_PREFIX)); + int noOfMessages = message.length; + for (int i = 0; i < noOfMessages; i++) { + String m = message[i]; + String finalPrefix; + if (i == noOfMessages - DISPLAYED_INDEX_OFFSET) { + finalPrefix = LINE_PREFIX_NO_SPACE; + } else { + finalPrefix = LINE_PREFIX; + } + out.println(LINE_PREFIX + m.replace("\n", LS + finalPrefix)); } } diff --git a/test/EXPECTED.TXT b/test/EXPECTED.TXT index 56fe5fcac..e9a0da562 100644 --- a/test/EXPECTED.TXT +++ b/test/EXPECTED.TXT @@ -47,25 +47,25 @@ || 0 persons listed! || =================================================== || Enter command: || [Command entered: add wrong args wrong args] -|| Invalid command format! +|| Invalid command format! || add: Adds a person to the address book. Contact details can be marked private by prepending 'p' to the prefix. || Parameters: NAME [p]p/PHONE [p]e/EMAIL [p]a/ADDRESS [t/TAG]... || Example: add John Doe p/98765432 e/johnd@gmail.com a/311, Clementi Ave 2, #02-25 t/friends t/owesMoney || =================================================== || Enter command: || [Command entered: add Valid Name 12345 e/valid@email.butNoPhonePrefix a/valid, address] -|| Invalid command format! +|| Invalid command format! || add: Adds a person to the address book. Contact details can be marked private by prepending 'p' to the prefix. || Parameters: NAME [p]p/PHONE [p]e/EMAIL [p]a/ADDRESS [t/TAG]... || Example: add John Doe p/98765432 e/johnd@gmail.com a/311, Clementi Ave 2, #02-25 t/friends t/owesMoney || =================================================== || Enter command: || [Command entered: add Valid Name p/12345 valid@email.butNoPrefix a/valid, address] -|| Invalid command format! +|| Invalid command format! || add: Adds a person to the address book. Contact details can be marked private by prepending 'p' to the prefix. || Parameters: NAME [p]p/PHONE [p]e/EMAIL [p]a/ADDRESS [t/TAG]... || Example: add John Doe p/98765432 e/johnd@gmail.com a/311, Clementi Ave 2, #02-25 t/friends t/owesMoney || =================================================== || Enter command: || [Command entered: add Valid Name p/12345 e/valid@email.butNoAddressPrefix valid, address] -|| Invalid command format! +|| Invalid command format! || add: Adds a person to the address book. Contact details can be marked private by prepending 'p' to the prefix. || Parameters: NAME [p]p/PHONE [p]e/EMAIL [p]a/ADDRESS [t/TAG]... || Example: add John Doe p/98765432 e/johnd@gmail.com a/311, Clementi Ave 2, #02-25 t/friends t/owesMoney @@ -86,66 +86,66 @@ || Tags names should be alphanumeric || =================================================== || Enter command: || [Command entered: add Adam Brown p/111111 e/adam@gmail.com a/111, alpha street] -|| New person added: Adam Brown Phone: 111111 Email: adam@gmail.com Address: 111, alpha street Tags: +|| New person added: Adam Brown Phone: 111111 Email: adam@gmail.com Address: 111, alpha street Tags: [NONE] || =================================================== || Enter command: || [Command entered: list] -|| 1. Adam Brown Phone: 111111 Email: adam@gmail.com Address: 111, alpha street Tags: -|| +|| 1. Adam Brown Phone: 111111 Email: adam@gmail.com Address: 111, alpha street Tags: [NONE] +|| || 1 persons listed! || =================================================== || Enter command: || [Command entered: add Betsy Choo pp/222222 pe/benchoo@nus.edu.sg pa/222, beta street t/secretive] || New person added: Betsy Choo Phone: (private) 222222 Email: (private) benchoo@nus.edu.sg Address: (private) 222, beta street Tags: [secretive] || =================================================== || Enter command: || [Command entered: list] -|| 1. Adam Brown Phone: 111111 Email: adam@gmail.com Address: 111, alpha street Tags: -|| 2. Betsy Choo Tags: [secretive] -|| +|| 1. Adam Brown Phone: 111111 Email: adam@gmail.com Address: 111, alpha street Tags: [NONE] +|| 2. Betsy Choo Tags: [secretive] +|| || 2 persons listed! || =================================================== || Enter command: || [Command entered: add Charlie Dickson pp/333333 e/charlie.d@nus.edu.sg a/333, gamma street t/friends t/school] || New person added: Charlie Dickson Phone: (private) 333333 Email: charlie.d@nus.edu.sg Address: 333, gamma street Tags: [school][friends] || =================================================== || Enter command: || [Command entered: list] -|| 1. Adam Brown Phone: 111111 Email: adam@gmail.com Address: 111, alpha street Tags: -|| 2. Betsy Choo Tags: [secretive] -|| 3. Charlie Dickson Email: charlie.d@nus.edu.sg Address: 333, gamma street Tags: [school][friends] -|| +|| 1. Adam Brown Phone: 111111 Email: adam@gmail.com Address: 111, alpha street Tags: [NONE] +|| 2. Betsy Choo Tags: [secretive] +|| 3. Charlie Dickson Email: charlie.d@nus.edu.sg Address: 333, gamma street Tags: [school][friends] +|| || 3 persons listed! || =================================================== || Enter command: || [Command entered: add Dickson Ee p/444444 pe/dickson@nus.edu.sg a/444, delta street t/friends] || New person added: Dickson Ee Phone: 444444 Email: (private) dickson@nus.edu.sg Address: 444, delta street Tags: [friends] || =================================================== || Enter command: || [Command entered: list] -|| 1. Adam Brown Phone: 111111 Email: adam@gmail.com Address: 111, alpha street Tags: -|| 2. Betsy Choo Tags: [secretive] -|| 3. Charlie Dickson Email: charlie.d@nus.edu.sg Address: 333, gamma street Tags: [school][friends] -|| 4. Dickson Ee Phone: 444444 Address: 444, delta street Tags: [friends] -|| +|| 1. Adam Brown Phone: 111111 Email: adam@gmail.com Address: 111, alpha street Tags: [NONE] +|| 2. Betsy Choo Tags: [secretive] +|| 3. Charlie Dickson Email: charlie.d@nus.edu.sg Address: 333, gamma street Tags: [school][friends] +|| 4. Dickson Ee Phone: 444444 Address: 444, delta street Tags: [friends] +|| || 4 persons listed! || =================================================== || Enter command: || [Command entered: add Esther Potato p/555555 e/esther@not.a.real.potato pa/555, epsilon street t/tubers t/starchy] || New person added: Esther Potato Phone: 555555 Email: esther@not.a.real.potato Address: (private) 555, epsilon street Tags: [tubers][starchy] || =================================================== || Enter command: || [Command entered: list] -|| 1. Adam Brown Phone: 111111 Email: adam@gmail.com Address: 111, alpha street Tags: -|| 2. Betsy Choo Tags: [secretive] -|| 3. Charlie Dickson Email: charlie.d@nus.edu.sg Address: 333, gamma street Tags: [school][friends] -|| 4. Dickson Ee Phone: 444444 Address: 444, delta street Tags: [friends] -|| 5. Esther Potato Phone: 555555 Email: esther@not.a.real.potato Tags: [tubers][starchy] -|| +|| 1. Adam Brown Phone: 111111 Email: adam@gmail.com Address: 111, alpha street Tags: [NONE] +|| 2. Betsy Choo Tags: [secretive] +|| 3. Charlie Dickson Email: charlie.d@nus.edu.sg Address: 333, gamma street Tags: [school][friends] +|| 4. Dickson Ee Phone: 444444 Address: 444, delta street Tags: [friends] +|| 5. Esther Potato Phone: 555555 Email: esther@not.a.real.potato Tags: [tubers][starchy] +|| || 5 persons listed! || =================================================== || Enter command: || [Command entered: add Esther Potato p/555555 e/esther@not.a.real.potato pa/555, epsilon street t/tubers t/starchy] || This person already exists in the address book || =================================================== || Enter command: || [Command entered: view] -|| Invalid command format! +|| Invalid command format! || view: Views the non-private details of the person identified by the index number in the last shown person listing. || Parameters: INDEX || Example: view 1 || =================================================== || Enter command: || [Command entered: viewall] -|| Invalid command format! +|| Invalid command format! || viewall: Views the non-private details of the person identified by the index number in the last shown person listing. || Parameters: INDEX || Example: viewall 1 @@ -175,10 +175,10 @@ || The person index provided is invalid || =================================================== || Enter command: || [Command entered: view 1] -|| Viewing person: Adam Brown Phone: 111111 Email: adam@gmail.com Address: 111, alpha street Tags: +|| Viewing person: Adam Brown Phone: 111111 Email: adam@gmail.com Address: 111, alpha street Tags: [NONE] || =================================================== || Enter command: || [Command entered: viewall 1] -|| Viewing person: Adam Brown Phone: 111111 Email: adam@gmail.com Address: 111, alpha street Tags: +|| Viewing person: Adam Brown Phone: 111111 Email: adam@gmail.com Address: 111, alpha street Tags: [NONE] || =================================================== || Enter command: || [Command entered: view 3] || Viewing person: Charlie Dickson Email: charlie.d@nus.edu.sg Address: 333, gamma street Tags: [school][friends] @@ -199,7 +199,7 @@ || Viewing person: Esther Potato Phone: 555555 Email: esther@not.a.real.potato Address: (private) 555, epsilon street Tags: [tubers][starchy] || =================================================== || Enter command: || [Command entered: find] -|| Invalid command format! +|| Invalid command format! || find: Finds all persons whose names contain any of the specified keywords (case-sensitive) and displays them as a list with index numbers. || Parameters: KEYWORD [MORE_KEYWORDS]... || Example: find alice bob charlie @@ -218,23 +218,23 @@ || =================================================== || Enter command: || [Command entered: find Betsy] || 1. Betsy Choo Tags: [secretive] -|| +|| || 1 persons listed! || =================================================== || Enter command: || [Command entered: find Dickson] || 1. Charlie Dickson Email: charlie.d@nus.edu.sg Address: 333, gamma street Tags: [school][friends] -|| 2. Dickson Ee Phone: 444444 Address: 444, delta street Tags: [friends] -|| +|| 2. Dickson Ee Phone: 444444 Address: 444, delta street Tags: [friends] +|| || 2 persons listed! || =================================================== || Enter command: || [Command entered: find Charlie Betsy] || 1. Betsy Choo Tags: [secretive] -|| 2. Charlie Dickson Email: charlie.d@nus.edu.sg Address: 333, gamma street Tags: [school][friends] -|| +|| 2. Charlie Dickson Email: charlie.d@nus.edu.sg Address: 333, gamma street Tags: [school][friends] +|| || 2 persons listed! || =================================================== || Enter command: || [Command entered: delete] -|| Invalid command format! +|| Invalid command format! || delete: Deletes the person identified by the index number used in the last person listing. || Parameters: INDEX || Example: delete 1 @@ -264,30 +264,30 @@ || Person could not be found in address book || =================================================== || Enter command: || [Command entered: list] -|| 1. Adam Brown Phone: 111111 Email: adam@gmail.com Address: 111, alpha street Tags: -|| 2. Betsy Choo Tags: [secretive] -|| 3. Dickson Ee Phone: 444444 Address: 444, delta street Tags: [friends] -|| 4. Esther Potato Phone: 555555 Email: esther@not.a.real.potato Tags: [tubers][starchy] -|| +|| 1. Adam Brown Phone: 111111 Email: adam@gmail.com Address: 111, alpha street Tags: [NONE] +|| 2. Betsy Choo Tags: [secretive] +|| 3. Dickson Ee Phone: 444444 Address: 444, delta street Tags: [friends] +|| 4. Esther Potato Phone: 555555 Email: esther@not.a.real.potato Tags: [tubers][starchy] +|| || 4 persons listed! || =================================================== || Enter command: || [Command entered: delete 4] || Deleted Person: Esther Potato Phone: 555555 Email: esther@not.a.real.potato Address: (private) 555, epsilon street Tags: [tubers][starchy] || =================================================== || Enter command: || [Command entered: list] -|| 1. Adam Brown Phone: 111111 Email: adam@gmail.com Address: 111, alpha street Tags: -|| 2. Betsy Choo Tags: [secretive] -|| 3. Dickson Ee Phone: 444444 Address: 444, delta street Tags: [friends] -|| +|| 1. Adam Brown Phone: 111111 Email: adam@gmail.com Address: 111, alpha street Tags: [NONE] +|| 2. Betsy Choo Tags: [secretive] +|| 3. Dickson Ee Phone: 444444 Address: 444, delta street Tags: [friends] +|| || 3 persons listed! || =================================================== || Enter command: || [Command entered: delete 1] -|| Deleted Person: Adam Brown Phone: 111111 Email: adam@gmail.com Address: 111, alpha street Tags: +|| Deleted Person: Adam Brown Phone: 111111 Email: adam@gmail.com Address: 111, alpha street Tags: [NONE] || =================================================== || Enter command: || [Command entered: list] || 1. Betsy Choo Tags: [secretive] -|| 2. Dickson Ee Phone: 444444 Address: 444, delta street Tags: [friends] -|| +|| 2. Dickson Ee Phone: 444444 Address: 444, delta street Tags: [friends] +|| || 2 persons listed! || =================================================== || Enter command: || [Command entered: clear]