Skip to content

Commit

Permalink
Check for tag when getting item handles
Browse files Browse the repository at this point in the history
  • Loading branch information
irvinlim committed Nov 6, 2016
1 parent 6105ae3 commit 2ea8d06
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 2 deletions.
20 changes: 20 additions & 0 deletions src/main/java/seedu/todo/commons/util/ListUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package seedu.todo.commons.util;

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

// @@author A0139812A
public class ListUtil {

/**
* Checks if two lists are equal, without regard for order.
*/
public static <T> boolean unorderedListEquals(List<T> list1, List<T> list2) {
final Set<T> set1 = new HashSet<>(list1);
final Set<T> set2 = new HashSet<>(list2);

return set1.equals(set2);
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package seedu.todo.guitests.guihandles;

import java.util.Arrays;
import java.util.List;

import javafx.scene.Node;
import javafx.stage.Stage;
import seedu.todo.commons.util.ListUtil;
import seedu.todo.guitests.GuiRobot;
import seedu.todo.models.Event;

Expand All @@ -11,6 +15,7 @@
public class TaskListEventItemHandle extends GuiHandle {

private static final String TASKLISTEVENTITEM_NAME_ID = "#eventText";
private static final String TASKLISTEVENTITEM_TAGS_ID = "#eventTagListText";
private Node node;

public TaskListEventItemHandle(GuiRobot guiRobot, Stage primaryStage, Node node){
Expand All @@ -25,6 +30,24 @@ public String getName() {
return getStringFromText(TASKLISTEVENTITEM_NAME_ID, node);
}

/**
* Gets the list of tags for this task item.
*/
public List<String> getTags() {
String tagsText = getStringFromText(TASKLISTEVENTITEM_TAGS_ID, node);

// Strip square brackets off
tagsText = tagsText.replaceAll("\\[|\\]", "");

// Check for empty string... because Java returns an array of size 1
// when you split an empty string.
if (tagsText.length() <= 0) {
return Arrays.asList(new String[] {});
}

return Arrays.asList(tagsText.split(", "));
}

/**
* Checks if this handle is referring to an event of the same data.
*
Expand All @@ -36,7 +59,7 @@ public boolean isEqualsToEvent(Event eventToCompare) {
return false;
}

return getName().equals(eventToCompare.getName());
return getName().equals(eventToCompare.getName()) && ListUtil.unorderedListEquals(getTags(), eventToCompare.getTagList());
}

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package seedu.todo.guitests.guihandles;

import java.time.LocalTime;
import java.util.List;

import java.util.Arrays;
import javafx.scene.Node;
import javafx.stage.Stage;
import seedu.todo.commons.util.DateUtil;
import seedu.todo.commons.util.ListUtil;
import seedu.todo.guitests.GuiRobot;
import seedu.todo.models.Task;

Expand All @@ -15,6 +18,7 @@ public class TaskListTaskItemHandle extends GuiHandle {

private static final String TASKLISTTASKITEM_NAME_ID = "#taskText";
private static final String TASKLISTTASKITEM_TIME_ID = "#taskTime";
private static final String TASKLISTTASKITEM_TAGS_ID = "#taskTagListText";
private Node node;

public TaskListTaskItemHandle(GuiRobot guiRobot, Stage primaryStage, Node node){
Expand Down Expand Up @@ -42,6 +46,24 @@ public LocalTime getTime() {
return DateUtil.parseTime(timeText);
}

/**
* Gets the list of tags for this task item.
*/
public List<String> getTags() {
String tagsText = getStringFromText(TASKLISTTASKITEM_TAGS_ID, node);

// Strip square brackets off
tagsText = tagsText.replaceAll("\\[|\\]", "");

// Check for empty string... because Java returns an array of size 1
// when you split an empty string.
if (tagsText.length() <= 0) {
return Arrays.asList(new String[] {});
}

return Arrays.asList(tagsText.split(", "));
}

/**
* Checks if this handle task time is equal to that of a task provided.
*
Expand Down Expand Up @@ -69,7 +91,8 @@ public boolean isEqualsToTask(Task taskToCompare) {
return false;
}

return getName().equals(taskToCompare.getName()) && isTimeEqual(taskToCompare);
return getName().equals(taskToCompare.getName()) && isTimeEqual(taskToCompare)
&& ListUtil.unorderedListEquals(taskToCompare.getTagList(), getTags());
}

}

0 comments on commit 2ea8d06

Please sign in to comment.