Skip to content

Commit

Permalink
adasd
Browse files Browse the repository at this point in the history
  • Loading branch information
LinusMelb committed Sep 18, 2017
1 parent 8e969b0 commit 5a6c8a2
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 5 deletions.
13 changes: 11 additions & 2 deletions src/seedu/addressbook/commands/FindCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import seedu.addressbook.data.person.ReadOnlyPerson;

import javax.print.DocFlavor;
import java.util.*;

/**
Expand Down Expand Up @@ -44,9 +45,17 @@ public CommandResult execute() {
*/
private List<ReadOnlyPerson> getPersonsWithNameContainingAnyKeyword(Set<String> keywords) {
final List<ReadOnlyPerson> matchedPersons = new ArrayList<>();

/* Converts all keywords into lowercase and puts them into a new ArrayList */
ArrayList<String> lowercaseKeywords = new ArrayList<String>();
for (String word : keywords ){
lowercaseKeywords.add(word.toLowerCase());
}

for (ReadOnlyPerson person : addressBook.getAllPersons()) {
final Set<String> wordsInName = new HashSet<>(person.getName().getWordsInName());
if (!Collections.disjoint(wordsInName, keywords)) {
final Set<String> wordsInName = new HashSet<>(person.getName().getLowercaseWordsInName());

if (!Collections.disjoint(wordsInName, lowercaseKeywords)) {
matchedPersons.add(person);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/seedu/addressbook/commands/HelpCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class HelpCommand extends Command {
+ "\n" + ClearCommand.MESSAGE_USAGE
+ "\n" + FindCommand.MESSAGE_USAGE
+ "\n" + ListCommand.MESSAGE_USAGE
+ "\n" + SortCommand.MESSAGE_USAGE
+ "\n" + ViewCommand.MESSAGE_USAGE
+ "\n" + ViewAllCommand.MESSAGE_USAGE
+ "\n" + HelpCommand.MESSAGE_USAGE
Expand Down
29 changes: 29 additions & 0 deletions src/seedu/addressbook/commands/SortCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package seedu.addressbook.commands;

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

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

/**
* Sorts all persons in the address book in alphabetic order to the user.
*/
public class SortCommand extends Command {

public static final String COMMAND_WORD = "sort";

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


@Override
public CommandResult execute() {

List<Person> SortAllPersons = addressBook.getAllPersons().SortAllPersons();

return new CommandResult(getMessageForPersonListShownSummary(SortAllPersons), SortAllPersons);

}
}
1 change: 1 addition & 0 deletions src/seedu/addressbook/common/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class Messages {
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!";
public static final String MESSAGE_PERSONS_SORTED_OVERVIEW = "%1$d persons sorted!";
public static final String MESSAGE_PROGRAM_LAUNCH_ARGS_USAGE = "Launch command format: " +
"java seedu.addressbook.Main [STORAGE_FILE_PATH]";
public static final String MESSAGE_WELCOME = "Welcome to your Address Book!";
Expand Down
12 changes: 9 additions & 3 deletions src/seedu/addressbook/data/person/Name.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import seedu.addressbook.data.exception.IllegalValueException;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.List;

Expand Down Expand Up @@ -39,10 +40,15 @@ public static boolean isValidName(String test) {

/**
* Retrieves a listing of every word in the name, in order.
*
*/
public List<String> getWordsInName() {
return Arrays.asList(fullName.split("\\s+"));
}
public List<String> getWordsInName() { return Arrays.asList(fullName.split("\\s+")); }

/**
* Retrieves a listing of every word in the name, in order, in lowercase.
*
*/
public List<String> getLowercaseWordsInName() { return Arrays.asList(fullName.toLowerCase().split("\\s+")); }

@Override
public String toString() {
Expand Down
17 changes: 17 additions & 0 deletions src/seedu/addressbook/data/person/UniquePersonList.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,23 @@ public boolean contains(ReadOnlyPerson toCheck) {
return internalList.contains(toCheck);
}


/**
* Sorts all persons by their name, in alphabetic order a to z.
*/
public List<Person> SortAllPersons() {

List<Person> SortedAllPersons = new ArrayList<>();

for (Person p: internalList){
SortedAllPersons.add(p);
}

SortedAllPersons.sort((person1, person2)->(person1.getName().fullName.compareToIgnoreCase(person2.getName().fullName)));

return SortedAllPersons;
}

/**
* Adds a person to the list.
*
Expand Down
3 changes: 3 additions & 0 deletions src/seedu/addressbook/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ public Command parseCommand(String userInput) {
case FindCommand.COMMAND_WORD:
return prepareFind(arguments);

case SortCommand.COMMAND_WORD:
return new SortCommand();

case ListCommand.COMMAND_WORD:
return new ListCommand();

Expand Down

0 comments on commit 5a6c8a2

Please sign in to comment.