package seedu.todo.controllers;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;

import edu.emory.mathcs.backport.java.util.Arrays;
import seedu.todo.commons.exceptions.ParseException;
import seedu.todo.commons.util.StringUtil;
import seedu.todo.controllers.concerns.Renderer;
import seedu.todo.models.Event;
import seedu.todo.models.Task;
import seedu.todo.models.TodoListDB;

/**
 * Controller to find task/event by keyword
 * 
 * @@author A0093907W
 *
 */
public class FindController extends Controller {
    
    private static final String NAME = "Find";
    private static final String DESCRIPTION = "Find tasks and events based on the provided keyword.";
    private static final String COMMAND_SYNTAX = "find [name]";
    private static final String COMMAND_KEYWORD = "find";
    
    public static final String MESSAGE_LISTING_SUCCESS = "A total of %s %s and %s %s found!";
    public static final String MESSAGE_LISTING_FAILURE = "No tasks or events found!";
    public static final String STRING_SPACE = " ";
    
    private static CommandDefinition commandDefinition =
            new CommandDefinition(NAME, DESCRIPTION, COMMAND_SYNTAX, COMMAND_KEYWORD); 

    @Override
    public CommandDefinition getCommandDefinition() {
        return commandDefinition;
    }

    @Override
    public void process(String input) throws ParseException {
        input = input.replaceFirst(COMMAND_KEYWORD, "").trim();
        List<String> namesToFind = Arrays.asList(input.split(STRING_SPACE));
        
        List<Predicate<Task>> taskPredicates = new ArrayList<Predicate<Task>>();
        taskPredicates.add(Task.predByNameAny(namesToFind));
        List<Task> tasks = Task.where(taskPredicates);
        
        List<Predicate<Event>> eventPredicates = new ArrayList<Predicate<Event>>();
        eventPredicates.add(Event.predByNameAny(namesToFind));
        List<Event> events = Event.where(eventPredicates);
        
        if (tasks.size() == 0 && events.size() == 0) {
            Renderer.renderIndex(TodoListDB.getInstance(), MESSAGE_LISTING_FAILURE);
        } else {
            String consoleMessage = String.format(MESSAGE_LISTING_SUCCESS,
                    tasks.size(), StringUtil.pluralizer(tasks.size(), "task", "tasks"),
                    events.size(), StringUtil.pluralizer(events.size(), "event", "events"));
            Renderer.renderSelected(TodoListDB.getInstance(), consoleMessage, tasks, events);
        }
    }
}

@@ -50,24 +50,49 @@
 .ArrayList;%0A
+import java.util.Arrays;%0A
 import java.
@@ -98,24 +98,24 @@
 .util.List;%0A
-
 import java.
@@ -144,59 +144,8 @@
 e;%0A%0A
-import edu.emory.mathcs.backport.java.util.Arrays;%0A
 impo
@@ -516,21 +516,17 @@
 oller %7B%0A
-    
 %0A
+
     priv
@@ -788,21 +788,17 @@
 %22find%22;%0A
-    
 %0A
+
     publ
@@ -1020,20 +1020,16 @@
  = %22 %22;%0A
-    
 %0A    pri
@@ -1077,28 +1077,16 @@
 nition =
-%0A           
  new Com
@@ -1134,16 +1134,28 @@
 _SYNTAX,
+%0A           
  COMMAND
@@ -1164,17 +1164,16 @@
 EYWORD);
- 
 %0A%0A    @O
@@ -1492,25 +1492,17 @@
 PACE));%0A
-        
 %0A
+
         
@@ -1686,33 +1686,25 @@
 redicates);%0A
-        
 %0A
+
         List
@@ -1901,17 +1901,9 @@
 s);%0A
-        
 %0A
+
     
@@ -2129,16 +2129,30 @@
 SUCCESS,
+ tasks.size(),
 %0A       
@@ -2163,30 +2163,16 @@
         
- tasks.size(),
  StringU
@@ -2217,18 +2217,32 @@
 tasks%22),
-%0A
  
+events.size(),%0A
         
@@ -2252,30 +2252,16 @@
         
-events.size(),
  StringU

Fix warning