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

Merge #21

Merged
merged 32 commits into from
Mar 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
839fea6
Resolve checkstyle errors
Mar 18, 2019
c705f92
FIx Bug in FindCommand (#97)
marcus-pzj Mar 19, 2019
889a725
Update User Guide documentation (#98)
marcus-pzj Mar 19, 2019
1d82e15
Update User Guide documentation (#99)
dingheng4448 Mar 19, 2019
8d8db06
Update UserGuide.adoc (#100)
seanieyap Mar 19, 2019
acd851f
Merge branch 'master' into master
marcus-pzj Mar 19, 2019
95ce28b
Update User Guide
marcus-pzj Mar 19, 2019
764d315
Update User Guide
marcus-pzj Mar 19, 2019
b515fc3
Update User Guide
marcus-pzj Mar 19, 2019
2310b83
Update User Guide
marcus-pzj Mar 19, 2019
aef56f7
Update User Guide
marcus-pzj Mar 19, 2019
efb9346
Update User Guide
marcus-pzj Mar 19, 2019
4ac6174
Update User Guide
marcus-pzj Mar 19, 2019
df367d7
Update User Guide
marcus-pzj Mar 19, 2019
726c5b3
Update User Guide
marcus-pzj Mar 19, 2019
75b5fe8
Update User Guide (#101)
marcus-pzj Mar 19, 2019
0152330
Add config file for Reposense
marcus-pzj Mar 19, 2019
c1656e6
Merge branch 'master' into docs1.2
marcus-pzj Mar 19, 2019
36ebc76
Add config file for Reposense (#102)
marcus-pzj Mar 19, 2019
cfa7a18
Move config.json to _reposense folder
marcus-pzj Mar 19, 2019
f339b97
Merge branch 'docs1.2' of https://github.com/marcus-pzj/main into doc…
marcus-pzj Mar 19, 2019
f96d6c9
Move config.json to _reposense folder (#103)
marcus-pzj Mar 19, 2019
276b9c0
Edit config file for reposense
marcus-pzj Mar 19, 2019
40e38b9
Merge branch 'master' into docs1.2
marcus-pzj Mar 19, 2019
1fe1033
Merge pull request #104 from marcus-pzj/docs1.2
seanieyap Mar 19, 2019
3bcdddb
Merge branch 'master' into master
macchazuki Mar 19, 2019
0ef8c47
Update User Guide (#105)
macchazuki Mar 19, 2019
de93ef3
Update User Guide (#106)
dingheng4448 Mar 20, 2019
1080827
Update README.adoc and UserGuide.adoc: change table layouts (#110)
seanieyap Mar 21, 2019
5495ead
Update User Guide (#108)
dingheng4448 Mar 21, 2019
1cffbbb
Enhance list and find functionality to include tags
marcus-pzj Mar 22, 2019
998fc56
Merge branch 'master' into lftag
marcus-pzj Mar 22, 2019
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
54 changes: 46 additions & 8 deletions src/planmysem/commands/FindCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;

import javafx.util.Pair;
import planmysem.data.semester.Day;
import planmysem.data.slot.ReadOnlySlot;
import planmysem.data.slot.Slot;
import planmysem.data.tag.Tag;


/**
Expand All @@ -23,15 +25,16 @@ public class FindCommand extends Command {
private static final String MESSAGE_SUCCESS = "%1$s Slots listed.\n%2$s";
private static final String MESSAGE_SUCCESS_NONE = "0 Slots listed.\n";
public static final String MESSAGE_USAGE = COMMAND_WORD + ":\n" + "Finds all slots whose name "

+ "contains the specified keywords (not case-sensitive).\n\t"
+ "contains the specified keywords (case-sensitive).\n\t"
+ "Parameters: KEYWORD [MORE_KEYWORDS]...\n\t"
+ "Example: " + COMMAND_WORD + "n/CS";

private final String keyword;
private final boolean isFindByName;

public FindCommand(String keyword) {
this.keyword = keyword;
public FindCommand(String name, String tag ) {
this.keyword = (name == null) ? tag.trim() : name.trim();
this.isFindByName = (name != null);
}

@Override
Expand All @@ -42,10 +45,21 @@ public CommandResult execute() {

for (Map.Entry<LocalDate, Day> entry : planner.getSemester().getDays().entrySet()) {
for (Slot slots : entry.getValue().getSlots()) {
if (Pattern.matches(".*" + keyword + ".*", slots.getName().value)) {
matchedSlots.add(slots);
date = entry.getKey();
relevantSlots.add(new Pair<>(date, slots));
if (isFindByName) {
if (Pattern.matches(".*" + keyword + ".*", slots.getName().value)) {
matchedSlots.add(slots);
date = entry.getKey();
relevantSlots.add(new Pair<>(date, slots));
}
} else {
Set<Tag> tagSet = slots.getTags();
for (Tag tag : tagSet) {
if (Pattern.matches(".*" + keyword + ".*", tag.value)) {
matchedSlots.add(slots);
date = entry.getKey();
relevantSlots.add(new Pair<>(date, slots));
}
}
}
}
}
Expand All @@ -57,6 +71,27 @@ public CommandResult execute() {

return new CommandResult(String.format(MESSAGE_SUCCESS, matchedSlots.size(),
craftSuccessMessage(relevantSlots)));
// final List<Pair<LocalDate, ? extends ReadOnlySlot>> relevantSlots = new ArrayList<>();
// List<Slot> matchedSlots = new ArrayList<>();
// LocalDate date;
//
// for (Map.Entry<LocalDate, Day> entry : planner.getSemester().getDays().entrySet()) {
// for (Slot slots : entry.getValue().getSlots()) {
// if (Pattern.matches(".*" + keyword + ".*", slots.getName().value)) {
// matchedSlots.add(slots);
// date = entry.getKey();
// relevantSlots.add(new Pair<>(date, slots));
// }
// }
// }
//
// if (matchedSlots.isEmpty()) {
// return new CommandResult(MESSAGE_SUCCESS_NONE);
// }
// setData(this.planner, relevantSlots);
//
// return new CommandResult(String.format(MESSAGE_SiUCCESS, matchedSlots.size(),
// craftSuccessMessage(rele
}

/**
Expand All @@ -77,6 +112,9 @@ private String craftSuccessMessage(List<Pair<LocalDate, ? extends ReadOnlySlot>>
sb.append(",\n\t");
sb.append("Start Time: ");
sb.append(pair.getValue().getStartTime());
sb.append("\n\t");
sb.append("Tags: ");
sb.append(pair.getValue().getTags());
sb.append("\n");
count++;
}
Expand Down
35 changes: 27 additions & 8 deletions src/planmysem/commands/ListCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javafx.util.Pair;
import planmysem.data.semester.Day;
import planmysem.data.slot.ReadOnlySlot;
import planmysem.data.slot.Slot;
import planmysem.data.tag.Tag;

/**
* Displays a list of all slots in the planner whose name matches the argument keyword.
Expand All @@ -22,15 +24,17 @@ public class ListCommand extends Command {
public static final String MESSAGE_SUCCESS_NONE = "0 Slots listed.\n";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Lists all slots whose name "
+ "directly matches the specified keyword (not case-sensitive)."
+ "directly matches the specified keyword (case-sensitive)."
//+ "\n\tOptional Parameters: [past] [next] [all]"
//+ "\n\tDefault: list all"
+ "\n\tExample: " + COMMAND_WORD + " n/CS1010";

private final String name;
private final String keyword;
private final boolean isListByName;

public ListCommand(String name) {
this.name = name;
public ListCommand(String name, String tag) {
this.keyword = (name == null) ? tag.trim() : name.trim();
this.isListByName = (name != null);
}
@Override
public CommandResult execute() {
Expand All @@ -40,10 +44,21 @@ public CommandResult execute() {

for (Map.Entry<LocalDate, Day> entry : planner.getSemester().getDays().entrySet()) {
for (Slot slots : entry.getValue().getSlots()) {
if (slots.getName().value.equalsIgnoreCase(name)) {
matchedSlots.add(slots);
date = entry.getKey();
relevantSlots.add(new Pair<>(date, slots));
if (isListByName) {
if (slots.getName().value.equalsIgnoreCase(keyword)) {
matchedSlots.add(slots);
date = entry.getKey();
relevantSlots.add(new Pair<>(date, slots));
}
} else {
Set<Tag> tagSet = slots.getTags();
for (Tag tag : tagSet) {
if (tag.value.equalsIgnoreCase(keyword)) {
matchedSlots.add(slots);
date = entry.getKey();
relevantSlots.add(new Pair<>(date, slots));
}
}
}
}
}
Expand All @@ -57,6 +72,7 @@ public CommandResult execute() {
craftSuccessMessage(relevantSlots)));
}


/**
* Craft success message.
*/
Expand All @@ -75,6 +91,9 @@ private String craftSuccessMessage(List<Pair<LocalDate, ? extends ReadOnlySlot>>
sb.append(",\n\t");
sb.append("Start Time: ");
sb.append(pair.getValue().getStartTime());
sb.append("\n\t");
sb.append("Tags: ");
sb.append(pair.getValue().getTags());
sb.append("\n");
count++;
}
Expand Down
1 change: 1 addition & 0 deletions src/planmysem/common/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class Messages {
public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format! \n%1$s";
public static final String MESSAGE_INVALID_COMMAND_FORMAT_ADDITIONAL = "Invalid command format! \n%1$s\n\n%2$s";
public static final String MESSAGE_INVALID_PERSON_DISPLAYED_INDEX = "The person index provided is invalid";
public static final String MESSAGE_INVALID_MULTIPLE_PARAMS = "Either search by NAME or by TAG only, not both.";
public static final String MESSAGE_INVALID_SLOT_DISPLAYED_INDEX = "The slot 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_SLOT_NOT_IN_PLANNER = "Slot could not be found in Planner";
Expand Down
16 changes: 12 additions & 4 deletions src/planmysem/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static planmysem.common.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static planmysem.common.Messages.MESSAGE_INVALID_COMMAND_FORMAT_ADDITIONAL;
import static planmysem.common.Messages.MESSAGE_INVALID_DATE;
import static planmysem.common.Messages.MESSAGE_INVALID_MULTIPLE_PARAMS;
import static planmysem.common.Messages.MESSAGE_INVALID_TIME;

import java.time.LocalDate;
Expand Down Expand Up @@ -322,10 +323,14 @@ private Command prepareDelete(String args) {
private Command prepareFind(String args) {
HashMap<String, Set<String>> arguments = getParametersWithArguments(args);
String name = getFirstInSet(arguments.get(PARAMETER_NAME));
if (name == null || name.trim().isEmpty()) {
String tag = getFirstInSet(arguments.get(PARAMETER_TAG));
if (name == null && tag == null) {
return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE));
} else if (name != null && tag != null) {
return new IncorrectCommand(String.format(MESSAGE_INVALID_MULTIPLE_PARAMS, FindCommand.MESSAGE_USAGE));

}
return new FindCommand(name);
return new FindCommand(name, tag);
}

/**
Expand All @@ -337,10 +342,13 @@ private Command prepareFind(String args) {
private Command prepareList(String args) {
HashMap<String, Set<String>> arguments = getParametersWithArguments(args);
String name = getFirstInSet(arguments.get(PARAMETER_NAME));
if (name == null || name.trim().isEmpty()) {
String tag = getFirstInSet(arguments.get(PARAMETER_TAG));
if (name == null && tag == null) {
return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, ListCommand.MESSAGE_USAGE));
} else if (name != null && tag != null) {
return new IncorrectCommand(String.format(MESSAGE_INVALID_MULTIPLE_PARAMS, ListCommand.MESSAGE_USAGE));
}
return new ListCommand(name);
return new ListCommand(name, tag);
}

/**
Expand Down
27 changes: 23 additions & 4 deletions test/java/planmysem/logic/LogicTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@


import static junit.framework.TestCase.assertEquals;
import static planmysem.common.Messages.MESSAGE_INVALID_DATE;
import static planmysem.common.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static planmysem.common.Messages.MESSAGE_INVALID_COMMAND_FORMAT_ADDITIONAL;
import static planmysem.common.Messages.MESSAGE_INVALID_TIME;
import static planmysem.common.Messages.*;

import java.time.LocalDate;
import java.time.LocalTime;
Expand All @@ -27,6 +24,8 @@
import planmysem.commands.ClearCommand;
import planmysem.commands.CommandResult;
import planmysem.commands.DeleteCommand;
import planmysem.commands.FindCommand;
import planmysem.commands.ListCommand;
import planmysem.commands.EditCommand;
import planmysem.commands.ExitCommand;
import planmysem.commands.HelpCommand;
Expand Down Expand Up @@ -206,6 +205,26 @@ public void execute_delete_invalidArgsFormat() throws Exception {
"d wrong", expectedMessage);
}

@Test
public void execute_find_invalidArgsFormat() throws Exception {
String expectedMessageSingle = String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE);
String expectedMessageMultipleParams = String.format(MESSAGE_INVALID_MULTIPLE_PARAMS, FindCommand.MESSAGE_USAGE);
assertCommandBehavior(
"find wrong args wrong args", expectedMessageSingle);
assertCommandBehavior(
"find n/CS2113T t/Tutorial", expectedMessageMultipleParams);
}

@Test
public void execute_list_invalidArgsFormat() throws Exception {
String expectedMessageSingle = String.format(MESSAGE_INVALID_COMMAND_FORMAT, ListCommand.MESSAGE_USAGE);
String expectedMessageMultipleParams = String.format(MESSAGE_INVALID_MULTIPLE_PARAMS, ListCommand.MESSAGE_USAGE);
assertCommandBehavior(
"list wrong args wrong args", expectedMessageSingle);
assertCommandBehavior(
"list n/CS2113T t/Tutorial", expectedMessageMultipleParams);
}

/**
* Executes the command and confirms that the result message is correct.
* Both the 'planner' and the 'last shown list' are expected to be empty.
Expand Down