forked from se-edu/addressbook-level2
-
Notifications
You must be signed in to change notification settings - Fork 104
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
PhiLong-Ho
wants to merge
23
commits into
nusCS2113-AY1819S1:master
Choose a base branch
from
CS2113-AY1819S1-T12-1:SortFeature
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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 1eac027
Pull request to my own branch
Geraldcdx d125c1f
Added a new class. LimitListCommand
Geraldcdx d25de8f
[James] Added commands/EditCommand class & edit Parrser.java
jamesyaputra 5e47974
[James] Made edit command behave like add command temporarily
jamesyaputra 94de6f1
[James] Made edit command behave like delete and add commands
jamesyaputra 11fd100
[James] Edited gitignore and edit command bug fix
jamesyaputra 14c64d3
[James] Added edit command in help
jamesyaputra d1002cb
[James] Bug fix edit command (added n/ prefix for name edits)
jamesyaputra 2eb17c5
[James] Added edit command test cases
jamesyaputra cf9be62
[James] Update User Guide
jamesyaputra 17fb890
Added a login feauture and removed LimitListCommand class
Geraldcdx aebf545
Testing with the .batfile
Geraldcdx 6a2c3ed
Merge pull request #2 from CS2113-AY1819S1-T12-1/add-edit-command
PhiLong-Ho 9661f6e
Added a log in function
Geraldcdx 2ee5f5c
Resolving Conflict
Geraldcdx e92be2e
Added information to the user guide
Geraldcdx c9844a0
Added OOP
Geraldcdx ad6f293
Resolved oonflict
Geraldcdx 88964c9
Merge pull request #1 from Geraldcdx/Gerald'sBranch
cqinkai dcd3036
Create SortCommand and Comparator Class for current and future use
PhiLong-Ho 9483d00
Fix small error
PhiLong-Ho 78c42f5
Sort by name
PhiLong-Ho File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,3 +27,6 @@ test/localrun.bat | |
# Gradle build files | ||
.gradle/ | ||
build/ | ||
|
||
# out folder | ||
.out/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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` | ||
|
@@ -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. + | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.