package seedu.todo.ui;

import seedu.todo.controllers.*;

public class InputHandler {
    
    Controller handlingController = null;
    
    public boolean processInput(String input) {
        if (this.handlingController != null) {
            handlingController.process(input);
        } else {
            Controller[] controllers = instantiateAllControllers();
            
            // Define the controller which returns the maximum confidence.
            Controller maxController = null;
            
            // Get controller which has the maximum confidence.
            float maxConfidence = Integer.MIN_VALUE;
            
            for (int i = 0; i < controllers.length; i++) {
                float confidence = controllers[i].inputConfidence(input);
                
                // Don't consider controllers with non-positive confidence.
                if (confidence <= 0)
                    continue;
                
                if (confidence > maxConfidence) {
                    maxConfidence = confidence;
                    maxController = controllers[i];
                }
            }
            
            // No controller exists with confidence > 0.
            if (maxController == null)
                return false;
            
            // Process using best-matched controller.
            maxController.process(input);
            
        }
        
        return true;
    }
    
    private Controller[] instantiateAllControllers() {
        return new Controller[] { new AddController(),
                                  new ListController(),
                                  new DestroyController(),
                                  new UpdateController() };
    }

}

@@ -79,21 +79,17 @@
 ndler %7B%0A
-    
 %0A
+
     Cont
@@ -122,21 +122,17 @@
 = null;%0A
-    
 %0A
+
     publ
@@ -350,29 +350,17 @@
 lers();%0A
-            
 %0A
+
         
@@ -471,29 +471,17 @@
 = null;%0A
-            
 %0A
+
         
@@ -589,29 +589,17 @@
 _VALUE;%0A
-            
 %0A
+
         
@@ -723,33 +723,17 @@
 input);%0A
-                
 %0A
+
         
@@ -836,16 +836,18 @@
 ce %3C= 0)
+ %7B
 %0A       
@@ -877,32 +877,34 @@
                 
+%7D%0A
 %0A               
@@ -1070,29 +1070,17 @@
       %7D%0A
-            
 %0A
+
         
@@ -1166,16 +1166,18 @@
 == null)
+ %7B
 %0A       
@@ -1203,32 +1203,34 @@
 se;%0A            
+%7D%0A
 %0A            // 
@@ -1314,21 +1314,9 @@
 t);%0A
-            
 %0A
+
     
@@ -1321,24 +1321,16 @@
       %7D%0A
-        
 %0A       

Fix spacing and conditional braces