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][T12-1] Ho Phi Long #167

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
fc926ad
Testing branching on GitKraken
Geraldcdx Sep 8, 2018
1eac027
Pull request to my own branch
Geraldcdx Sep 8, 2018
d125c1f
Added a new class. LimitListCommand
Geraldcdx Sep 8, 2018
d25de8f
[James] Added commands/EditCommand class & edit Parrser.java
jamesyaputra Sep 8, 2018
5e47974
[James] Made edit command behave like add command temporarily
jamesyaputra Sep 8, 2018
94de6f1
[James] Made edit command behave like delete and add commands
jamesyaputra Sep 8, 2018
11fd100
[James] Edited gitignore and edit command bug fix
jamesyaputra Sep 8, 2018
14c64d3
[James] Added edit command in help
jamesyaputra Sep 8, 2018
d1002cb
[James] Bug fix edit command (added n/ prefix for name edits)
jamesyaputra Sep 8, 2018
2eb17c5
[James] Added edit command test cases
jamesyaputra Sep 8, 2018
cf9be62
[James] Update User Guide
jamesyaputra Sep 8, 2018
17fb890
Added a login feauture and removed LimitListCommand class
Geraldcdx Sep 8, 2018
aebf545
Testing with the .batfile
Geraldcdx Sep 8, 2018
6a2c3ed
Merge pull request #2 from CS2113-AY1819S1-T12-1/add-edit-command
PhiLong-Ho Sep 9, 2018
9661f6e
Added a log in function
Geraldcdx Sep 10, 2018
2ee5f5c
Resolving Conflict
Geraldcdx Sep 10, 2018
e92be2e
Added information to the user guide
Geraldcdx Sep 10, 2018
c9844a0
Added OOP
Geraldcdx Sep 10, 2018
ad6f293
Resolved oonflict
Geraldcdx Sep 10, 2018
88964c9
Merge pull request #1 from Geraldcdx/Gerald'sBranch
cqinkai Sep 10, 2018
dcd3036
Create SortCommand and Comparator Class for current and future use
PhiLong-Ho Sep 11, 2018
9483d00
Fix small error
PhiLong-Ho Sep 11, 2018
78c42f5
Sort by name
PhiLong-Ho Sep 12, 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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ test/localrun.bat
# Gradle build files
.gradle/
build/

# out folder
.out/
29 changes: 29 additions & 0 deletions docs/UserGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ What's different from AddressBook-Level1:
* Support for marking a contact detail as 'private' (`pa/`) (`pe/`) (`pp/`)
* View details of a person (`view` : shows non-private details), (`viewall` : shows all details)

== Password to login
Tentaively, I(Gerald) have commented out the login because the .bat file doesn't seem to work with the password but everything is fine when compile.
Examples:

* `What's the password?` will show up
* You have to key in `password` to allow access to the `Commands:` part of the code
* If you typed the wrong password, `Wrong Password, try again` will show up and you are prompted to type in the password again

== Viewing help : `help`

Format: `help`
Expand Down Expand Up @@ -91,6 +99,27 @@ Returns `John Doe` but not `john`.
* `find Betsy Tim John` +
Returns Any person having names `Betsy`, `Tim`, or `John`.

== Editing a person : `edit`

Edits the specified person from the address book. Irreversible. +
Format: `edit INDEX n/NAME [p]p/PHONE_NUMBER [p]e/EMAIL [p]a/ADDRESS [t/TAG]...`

****
Words in `UPPER_CASE` are the parameters, items in `SQUARE_BRACKETS` are optional,
items with `...` after them can have multiple instances. Order of parameters are fixed.

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 can have any number of tags (including 0).
****

Examples:

* `list` +
`edit 2 n/Dickson p/123456 e/[email protected] a/Address, Singapore t/wow` +
Edits the 2nd person in the address book with the arguments given

== Deleting a person : `delete`

Deletes the specified person from the address book. Irreversible. +
Expand Down
23 changes: 23 additions & 0 deletions src/seedu/addressbook/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.Scanner;

import seedu.addressbook.commands.Command;
import seedu.addressbook.commands.CommandResult;
Expand Down Expand Up @@ -40,10 +41,32 @@ public static void main(String... launchArgs) {
/** Runs the program until termination. */
public void run(String[] launchArgs) {
start(launchArgs);
//login(); //commented out first
runCommandLoopUntilExitCommand();
exit();
}

/*
Password feature to allow users to log in
*/
public void login() {
while(true){
System.out.println("|| What is the Password?");
if(checkPassword()){
System.out.println("|| Password is correct, you have gained access to the addressbook");
break;
}
else{
System.out.println("|| Password is incorrect try again!");
}
}
}
public boolean checkPassword(){
Scanner SCANNER= new Scanner(System.in);
if(SCANNER.nextLine().equals("password")) return true;
else return false;
}

/**
* Sets up the required objects, loads up the data from the storage file, and prints the welcome message.
*
Expand Down
1 change: 0 additions & 1 deletion src/seedu/addressbook/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public DeleteCommand(int targetVisibleIndex) {
super(targetVisibleIndex);
}


@Override
public CommandResult execute() {
try {
Expand Down
75 changes: 75 additions & 0 deletions src/seedu/addressbook/commands/EditCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package seedu.addressbook.commands;

import seedu.addressbook.common.Messages;
import seedu.addressbook.data.exception.IllegalValueException;
import seedu.addressbook.data.person.UniquePersonList.PersonNotFoundException;
import seedu.addressbook.data.person.*;
import seedu.addressbook.data.tag.Tag;

import java.util.HashSet;
import java.util.Set;

/**
* Edits a person identified using it's last displayed index from the address book.
*/
public class EditCommand extends Command {

public static final String COMMAND_WORD = "edit";

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Edits the person identified by the index number used in the last person listing.\n"
+ "Parameters: INDEX NAME [p]p/PHONE [p]e/EMAIL [p]a/ADDRESS [t/TAG]...\n"
+ "Example: " + COMMAND_WORD + " 1 n/Kristo p/1231818 e/[email protected] a/Singapore t/friends";

private static final String MESSAGE_EDIT_PERSON_SUCCESS = "Edited Person: %1$s";
private static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book";

private final Person toEdit;

/**
* Convenience constructor using raw values.
*
* @throws IllegalValueException if any of the raw values are invalid
*/
public EditCommand(String targetVisibleIndex,
String name,
String phone, boolean isPhonePrivate,
String email, boolean isEmailPrivate,
String address, boolean isAddressPrivate,
Set<String> tags) throws IllegalValueException {
super(Integer.parseInt(targetVisibleIndex));

final Set<Tag> tagSet = new HashSet<>();
for (String tagName : tags) {
tagSet.add(new Tag(tagName));
}

this.toEdit = new Person(
new Name(name),
new Phone(phone, isPhonePrivate),
new Email(email, isEmailPrivate),
new Address(address, isAddressPrivate),
tagSet
);
}

public ReadOnlyPerson getPerson() {
return toEdit;
}

@Override
public CommandResult execute() {
try {
final ReadOnlyPerson target = getTargetPerson();
addressBook.removePerson(target);
addressBook.addPerson(toEdit);
return new CommandResult(String.format(MESSAGE_EDIT_PERSON_SUCCESS, toEdit));
} catch (UniquePersonList.DuplicatePersonException dpe) {
return new CommandResult(MESSAGE_DUPLICATE_PERSON);
} catch (IndexOutOfBoundsException ie) {
return new CommandResult(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
} catch (PersonNotFoundException pnfe) {
return new CommandResult(Messages.MESSAGE_PERSON_NOT_IN_ADDRESSBOOK);
}
}
}
1 change: 1 addition & 0 deletions src/seedu/addressbook/commands/HelpCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public HelpCommand() {}
public CommandResult execute() {
return new CommandResult(
AddCommand.MESSAGE_USAGE
+ "\n" + EditCommand.MESSAGE_USAGE
+ "\n" + DeleteCommand.MESSAGE_USAGE
+ "\n" + ClearCommand.MESSAGE_USAGE
+ "\n" + FindCommand.MESSAGE_USAGE
Expand Down
2 changes: 1 addition & 1 deletion src/seedu/addressbook/commands/ListCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
public class ListCommand extends Command {

public static final String COMMAND_WORD = "list";
public static final String COMMAND_WORD = "list" ;

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Displays all persons in the address book as a list with index numbers.\n"
Expand Down
32 changes: 32 additions & 0 deletions src/seedu/addressbook/commands/SortCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package seedu.addressbook.commands;

import seedu.addressbook.common.NameComparator;
import seedu.addressbook.data.person.Person;
import seedu.addressbook.data.person.ReadOnlyPerson;

import seedu.addressbook.data.person.UniquePersonList;

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

Choose a reason for hiding this comment

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

Consider adding comments for this class, clarifying what kind of "sorting" this class is supposed to do.

public class SortCommand extends Command {
public static final String COMMAND_WORD = "sort";

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Sort base on name in alphabetical order.\n"
+ "Example: Sort";

public SortCommand() {}
public List<ReadOnlyPerson> SortList() {
//Copy the unmodifiable array to a list
List<ReadOnlyPerson> SortedList = new ArrayList<ReadOnlyPerson>(addressBook.getAllPersons().immutableListView());
SortedList.sort(new NameComparator());
return SortedList;
}
@Override
public CommandResult execute () {
List<ReadOnlyPerson> SortedList = SortList();
return new CommandResult(getMessageForPersonListShownSummary(SortedList), SortedList);
}
}
8 changes: 8 additions & 0 deletions src/seedu/addressbook/common/Comparators.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package seedu.addressbook.common;

import seedu.addressbook.data.person.ReadOnlyPerson;

//Collection of comparator for different filter/sort used in the project
public class Comparators {

}
13 changes: 13 additions & 0 deletions src/seedu/addressbook/common/DateComparator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package seedu.addressbook.common;

public class DateComparator {
//Later will be change will Date class in the project
public int compare(int date1, int date2) {
if(date1 < date2)
return -1;
else if (date1 == date2)
return 0;
else
return 1;
}
}
13 changes: 13 additions & 0 deletions src/seedu/addressbook/common/NameComparator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package seedu.addressbook.common;

import seedu.addressbook.data.person.ReadOnlyPerson;

import java.util.Comparator;

public class NameComparator implements Comparator<ReadOnlyPerson> {
public int compare(ReadOnlyPerson p1, ReadOnlyPerson p2) {
String p1Name = p1.getName().fullName;
String p2Name = p2.getName().fullName;
return p1Name.compareTo(p2Name);
}
}
48 changes: 48 additions & 0 deletions src/seedu/addressbook/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import seedu.addressbook.commands.*;
import seedu.addressbook.commands.AddCommand;
import seedu.addressbook.commands.EditCommand;
import seedu.addressbook.commands.ClearCommand;
import seedu.addressbook.commands.Command;
import seedu.addressbook.commands.DeleteCommand;
Expand Down Expand Up @@ -41,6 +43,14 @@ public class Parser {
+ " (?<isAddressPrivate>p?)a/(?<address>[^/]+)"
+ "(?<tagArguments>(?: t/[^/]+)*)"); // variable number of tags

public static final Pattern PERSON_DATA_EDIT_ARGS_FORMAT =
Pattern.compile("(?<targetVisibleIndex>[^/]+)"
+ " n/(?<name>[^/]+)"
+ " (?<isPhonePrivate>p?)p/(?<phone>[^/]+)"
+ " (?<isEmailPrivate>p?)e/(?<email>[^/]+)"
+ " (?<isAddressPrivate>p?)a/(?<address>[^/]+)"
+ "(?<tagArguments>(?: t/[^/]+)*)"); // variable number of tags


/**
* Signals that the user input could not be parsed.
Expand Down Expand Up @@ -78,6 +88,9 @@ public Command parseCommand(String userInput) {
case AddCommand.COMMAND_WORD:
return prepareAdd(arguments);

case EditCommand.COMMAND_WORD:
return prepareEdit(arguments);

case DeleteCommand.COMMAND_WORD:
return prepareDelete(arguments);

Expand All @@ -99,6 +112,7 @@ public Command parseCommand(String userInput) {
case ExitCommand.COMMAND_WORD:
return new ExitCommand();


case HelpCommand.COMMAND_WORD: // Fallthrough
default:
return new HelpCommand();
Expand Down Expand Up @@ -158,6 +172,40 @@ private static Set<String> getTagsFromArgs(String tagArguments) throws IllegalVa
return new HashSet<>(tagStrings);
}

/**
* Parses arguments in the context of the edit person command.
*
* @param args full command args string
* @return the prepared command
*/
private Command prepareEdit(String args) {

final Matcher matcher = PERSON_DATA_EDIT_ARGS_FORMAT.matcher(args.trim());
// Validate arg string format
if (!matcher.matches()) {
return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE));
}
try {
return new EditCommand(
matcher.group("targetVisibleIndex"),

matcher.group("name"),

matcher.group("phone"),
isPrivatePrefixPresent(matcher.group("isPhonePrivate")),

matcher.group("email"),
isPrivatePrefixPresent(matcher.group("isEmailPrivate")),

matcher.group("address"),
isPrivatePrefixPresent(matcher.group("isAddressPrivate")),

getTagsFromArgs(matcher.group("tagArguments"))
);
} catch (IllegalValueException ive) {
return new IncorrectCommand(ive.getMessage());
}
}

/**
* Parses arguments in the context of the delete person command.
Expand Down
Loading