Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[W5.11][F10-3]Shreyas Kuthanoor Prakash #181

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
fe9fe0f
Added confirm/cancel clear option to after clear command
iamputradanish Sep 6, 2018
66db9a8
Merge pull request #1 from CS2113-AY1819S1-F10-3/confirm_cancel_clear…
iamputradanish Sep 6, 2018
f22df67
Update UserGuide
iamputradanish Sep 6, 2018
ff12999
Merge pull request #2 from CS2113-AY1819S1-F10-3/iamputradanish-patch-1
iamputradanish Sep 6, 2018
ffa8b03
Delete by name command
andyrobert3 Sep 6, 2018
d3d0e55
Added user guide for new delete_name command
andyrobert3 Sep 6, 2018
0bdbacb
Merge branch 'master' into feature/delete_name
andyrobert3 Sep 6, 2018
51c1830
Merge pull request #3 from CS2113-AY1819S1-F10-3/feature/delete_name
ShreyasKp Sep 7, 2018
07b409a
added nonsense
ongweekeong Sep 7, 2018
4971881
Merge commit '51c183064febaed0dea56ca2e129f40484781a94' into tutorial-4
ongweekeong Sep 7, 2018
b7c6185
Merge branch 'master' into feature/delete_name
andyrobert3 Sep 6, 2018
94bece0
Merge remote-tracking branch 'origin/feature/delete_name' into W5.11
andyrobert3 Sep 7, 2018
ba96540
deleted nonsense
ongweekeong Sep 7, 2018
51af3c6
Merge remote-tracking branch 'origin/feature/delete_name' into W5.11
andyrobert3 Sep 7, 2018
2a5b474
added total command and edited user guide
muhdharun Sep 7, 2018
a47f7a8
Merge branch 'master' into w5.11
muhdharun Sep 8, 2018
03bf4b6
Merge pull request #4 from muhdharun/w5.11
ongweekeong Sep 13, 2018
871908b
Added further constraints to 'add' feature
ongweekeong Sep 13, 2018
9eddf0d
Edited user guide
ongweekeong Sep 13, 2018
eec6c50
Merge branch 'W5.11' of https://github.com/CS2113-AY1819S1-F10-3/addr…
ongweekeong Sep 13, 2018
99cf098
Merge pull request #5 from CS2113-AY1819S1-F10-3/W5.11
andyrobert3 Sep 13, 2018
7e71dca
Revert "[W5.11][CS2113-AY1819S1-F10-3]Ong Wee Keong"
andyrobert3 Sep 13, 2018
db25458
Merge pull request #6 from CS2113-AY1819S1-F10-3/revert-5-W5.11
andyrobert3 Sep 13, 2018
4ebc7f0
Added restrictions to 'add' command & removed duplicate labels
ongweekeong Sep 13, 2018
9594a6f
Merge pull request #7 from CS2113-AY1819S1-F10-3/W_5.11
muhdharun Sep 13, 2018
f705fc0
add functionality to list top five persons
ShreyasKp Sep 13, 2018
a8529c5
update user guide and parser files
ShreyasKp Sep 13, 2018
8fc7316
Merge branch 'master' of https://github.com/CS2113-AY1819S1-F10-3/add…
ShreyasKp Sep 13, 2018
1ee73fa
update ParserTest
ShreyasKp Sep 13, 2018
9951c42
remove ParserTest edit
ShreyasKp Sep 13, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ The full list of contributors for se-edu can be found https://se-edu.github.io/T
* *Bug reports, Suggestions* : Post in our https://github.com/se-edu/addressbook-level2/issues[issue tracker]
if you noticed bugs or have suggestions on how to improve.
* *Contributing* : We welcome pull requests. Follow the process described https://github.com/oss-generic/process[here]

48 changes: 46 additions & 2 deletions docs/UserGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ items with `...` after them can have multiple instances. Order of parameters are
Put a `p` before the phone / email / address prefixes to mark it as `private`. `private` details can only
be seen using the `viewall` command.

Persons with duplicate primary key identity fields (Same name AND same phone number/email, or even different
name with same phone number AND email) will not be allowed.

Persons can have any number of tags (including 0).
****

Expand All @@ -67,11 +70,21 @@ Examples:
* `add John Doe p/98765432 e/[email protected] a/John street, block 123, #01-01`
* `add Betsy Crowe pp/1234567 e/[email protected] pa/Newgate Prison t/criminal t/friend`

== Showing current number of contacts : `total`

Shows the current total number of contacts in the address book, without showing the names. +
Format: `total`

== Listing all persons : `list`

Shows a list of all persons, along with their non-private details, in the address book. +
Format: `list`

== Listing first five persons : `topFive`

Shows a list of the first five persons, along with their non-private details, in the address book. +
Format: `topFive`

== Finding all persons containing any keyword in their name: `find`

Finds persons whose names contain any of the given keywords. +
Expand All @@ -91,7 +104,7 @@ Returns `John Doe` but not `john`.
* `find Betsy Tim John` +
Returns Any person having names `Betsy`, `Tim`, or `John`.

== Deleting a person : `delete`
== Deleting a person by index: `delete`

Deletes the specified person from the address book. Irreversible. +
Format: `delete INDEX`
Expand All @@ -111,6 +124,27 @@ Deletes the 2nd person in the address book.
`delete 1` +
Deletes the 1st person in the results of the `find` command.

== Deleting a person by name: `delete_name`

Deletes the specified person from the address book after indexing other commands. Irreversible. +
Format: `delete NAME`

****
Deletes the person by `NAME` not case sensitive.
`NAME` refers to the full name of the person.
****

Examples:

* `list` +
`delete_name Matthew Alexander` +
Deletes the Matthew Alexander in the address book.

* `find Betsy` +
`delete_name Betsy` +
Deletes the 1st person in the results of the `find` command.


== View non-private details of a person : `view`

Displays the non-private details of the specified person. +
Expand Down Expand Up @@ -153,9 +187,19 @@ Views all details of the 1st person in the results of the `find` command.

== Clearing all entries : `clear`

Clears all entries from the address book. +
Gives user a warning prompt to confirm or cancel deletion of address book.+
Format: `clear`

== Confirm Clear all entries : `yes`

Clears all entries from the address book. +
Format: `yes`

== Cancel the clearing of all entries : `no`

Informs user that the address book has not been cleared. +
Format: `no`

== Exiting the program : `exit`

Exits the program. +
Expand Down
14 changes: 14 additions & 0 deletions src/seedu/addressbook/commands/CancelClearCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package seedu.addressbook.commands;

public class CancelClearCommand extends Command {

public static final String COMMAND_WORD = "no";
public static final String MESSAGE_CANCEL = "Address book has not been cleared.";

public CancelClearCommand() {}

@Override
public CommandResult execute() {
return new CommandResult(MESSAGE_CANCEL);
}
}
6 changes: 2 additions & 4 deletions src/seedu/addressbook/commands/ClearCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@ public class ClearCommand extends Command {
public static final String MESSAGE_USAGE = "Clears address book permanently.\n"
+ "Example: " + COMMAND_WORD;

public static final String MESSAGE_SUCCESS = "Address book has been cleared!";
public static final String MESSAGE_CONFIRM = "Are you sure you want to clear the Address book? Enter yes or no.";

public ClearCommand() {}


@Override
public CommandResult execute() {
addressBook.clear();
return new CommandResult(MESSAGE_SUCCESS);
return new CommandResult(MESSAGE_CONFIRM);
}
}
17 changes: 17 additions & 0 deletions src/seedu/addressbook/commands/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class Command {
protected AddressBook addressBook;
protected List<? extends ReadOnlyPerson> relevantPersons;
private int targetIndex = -1;
private String name = "";

/**
* @param targetIndex last visible listing index of the target person
Expand All @@ -23,6 +24,8 @@ public Command(int targetIndex) {
this.setTargetIndex(targetIndex);
}

public Command(String name) { this.name = name; }

protected Command() {
}

Expand Down Expand Up @@ -57,6 +60,7 @@ public void setData(AddressBook addressBook, List<? extends ReadOnlyPerson> rele
* @throws IndexOutOfBoundsException if the target index is out of bounds of the last viewed listing
*/
protected ReadOnlyPerson getTargetPerson() throws IndexOutOfBoundsException {
if (getTargetIndex() == -1) { setTargetIndex(getTargetIndexByName(this.name)); } // getTargetIndex == -1, DeleteCommand(name)
return relevantPersons.get(getTargetIndex() - DISPLAYED_INDEX_OFFSET);
}

Expand All @@ -67,4 +71,17 @@ public int getTargetIndex() {
public void setTargetIndex(int targetIndex) {
this.targetIndex = targetIndex;
}

public int getTargetIndexByName(String name) {
int targetIndex = DISPLAYED_INDEX_OFFSET;

for (ReadOnlyPerson person : relevantPersons) {
if (person.getName().toString().equalsIgnoreCase(name)) {
return targetIndex;
}
targetIndex++;
}

return targetIndex;
}
}
15 changes: 15 additions & 0 deletions src/seedu/addressbook/commands/ConfirmClearCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package seedu.addressbook.commands;

public class ConfirmClearCommand extends Command {

public static final String COMMAND_WORD = "yes";
public static final String MESSAGE_SUCCESS = "Address book has been cleared!";

public ConfirmClearCommand() {}

@Override
public CommandResult execute() {
addressBook.clear();
return new CommandResult(MESSAGE_SUCCESS);
}
}
10 changes: 5 additions & 5 deletions src/seedu/addressbook/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@
public class DeleteCommand extends Command {

public static final String COMMAND_WORD = "delete";
public static final String COMMAND_WORD_STRING = "delete_name";

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Deletes the person identified by the index number used in the last person listing.\n"
+ "Parameters: INDEX\n"
+ "Parameters: INDEX/NAME\n"
+ "Example: " + COMMAND_WORD + " 1";

public static final String MESSAGE_DELETE_PERSON_SUCCESS = "Deleted Person: %1$s";


public DeleteCommand(int targetVisibleIndex) {
super(targetVisibleIndex);
}
public DeleteCommand(int targetVisibleIndex) { super(targetVisibleIndex); }

public DeleteCommand(String name) { super(name); }


@Override
Expand All @@ -31,7 +32,6 @@ public CommandResult execute() {
final ReadOnlyPerson target = getTargetPerson();
addressBook.removePerson(target);
return new CommandResult(String.format(MESSAGE_DELETE_PERSON_SUCCESS, target));

} catch (IndexOutOfBoundsException ie) {
return new CommandResult(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
} catch (PersonNotFoundException pnfe) {
Expand Down
34 changes: 34 additions & 0 deletions src/seedu/addressbook/commands/TopFiveCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package seedu.addressbook.commands;

import seedu.addressbook.data.person.ReadOnlyPerson;

import java.util.ArrayList;
import java.util.List;

/**
* Lists the first five persons in the address book to the user.
*/

public class TopFiveCommand extends Command{
public static final String COMMAND_WORD = "topFive";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe to keep the command word format consistent, you can use top_five instead of camelCase, or simply top might be more intuitive and user-friendly

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alternatively, you might want to allow the user to specify how many persons to list, so command like 'top 5'


public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Displays first five persons in the address book as a list with index numbers.\n"
+ "Example: " + COMMAND_WORD;

@Override
public CommandResult execute() {
List<ReadOnlyPerson> allPersons = addressBook.getAllPersons().immutableListView();
int size = allPersons.size();
if(size < 5) {
return new CommandResult(getMessageForPersonListShownSummary(allPersons), allPersons);
}
else {
List<ReadOnlyPerson> toBeDisplayed = new ArrayList<>();
for(int i = 0; i < 5; i++) {
toBeDisplayed.add(i, allPersons.get(i));
}
return new CommandResult(getMessageForPersonListShownSummary(toBeDisplayed), toBeDisplayed);
}
}
}
27 changes: 27 additions & 0 deletions src/seedu/addressbook/commands/TotalCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package seedu.addressbook.commands;

import seedu.addressbook.data.person.ReadOnlyPerson;

import java.util.List;


/**
* Shows current total number of contacts in book.
*/
public class TotalCommand extends Command {

public static final String COMMAND_WORD = "total";

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Displays the current number of contacts in the AB.\n"
+ "Example: " + COMMAND_WORD;

public static final String MESSAGE_SUCCESS = " Contact(s) found";


@Override
public CommandResult execute() {
int TotalContacts = addressBook.total();
return new CommandResult(TotalContacts + "" + MESSAGE_SUCCESS);
}
}
6 changes: 6 additions & 0 deletions src/seedu/addressbook/data/AddressBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ public void clear() {
allPersons.clear();
}

/**
* Returns total number of contacts
*/

public int total() {return allPersons.total();}

/**
* Returns a new UniquePersonList of all persons in the address book at the time of the call.
*/
Expand Down
10 changes: 7 additions & 3 deletions src/seedu/addressbook/data/person/ReadOnlyPerson.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@ public interface ReadOnlyPerson {
Set<Tag> getTags();

/**
* Returns true if both persons have the same identity fields (name and telephone).
* Returns true if both persons have the same identity fields (name and telephone and/or email).
* Will also return true if a different person has the same telephone and email.
*/
default boolean isSamePerson(ReadOnlyPerson other) {
return (other == this)
|| (other != null
&& other.getName().equals(this.getName())
&& other.getPhone().equals(this.getPhone()));
&& other.getPhone().equals(this.getPhone())
&& other.getEmail().equals(this.getEmail())
|| (other.getName().equals(this.getName())
&& (other.getPhone().equals(this.getPhone())
|| other.getEmail().equals(this.getEmail()))));
}

/**
Expand Down
8 changes: 8 additions & 0 deletions src/seedu/addressbook/data/person/UniquePersonList.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ public void add(Person toAdd) throws DuplicatePersonException {
internalList.add(toAdd);
}

/**
* Gets total contacts
*/

public int total(){
return internalList.size();
}

/**
* Removes the equivalent person from the list.
*
Expand Down
Loading