package seedu.tasklist.model;

import com.google.common.eventbus.Subscribe;

import seedu.tasklist.commons.core.EventsCenter;
import seedu.tasklist.commons.events.model.TaskCountersChangedEvent;
import seedu.tasklist.commons.events.model.TaskListChangedEvent;
import seedu.tasklist.model.task.ReadOnlyTask;
//@@author A0146107M
public class TaskCounter {

	private int total;
	private int floating;
	private int overdue;
	private int tomorrow;
	private int today;
	private int other;
	private int upcoming;
	
	public TaskCounter(ReadOnlyTaskList src){
		reinitializeValues();
		for(ReadOnlyTask task: src.getTaskList()){
    		incrementCounters(task);
    	}
		EventsCenter.getInstance().registerHandler(this);
		EventsCenter.getInstance().post(new TaskCountersChangedEvent(this));
	}
	
    @Subscribe
    private void modelChangedEvent(TaskListChangedEvent abce) {
    	reinitializeValues();
    	for(ReadOnlyTask task: abce.data.getTaskList()){
    		incrementCounters(task);
    	}
    	EventsCenter.getInstance().post(new TaskCountersChangedEvent(this));
    }
    
    private void incrementCounters(ReadOnlyTask task){
    	total++;
    	if(task.isFloating()){
    		floating++;
    	}
    	else if(task.isEvent() && !task.isOverDue()){
    		upcoming++;
    	}
    	else {
    		other++;
    	}
    	
    	if(task.isOverDue()){
    		overdue++;
    	}
    	else if(task.isTomorrow()){
    		tomorrow++;
    	}
    	else if(task.isToday()){
    		today++;
    	}
    }
    
    private void reinitializeValues(){
    	 this.total = 0;
    	 this.floating = 0;
    	 this.overdue = 0;
    	 this.tomorrow = 0;
    	 this.today = 0;
    	 this.other = 0;
    	 this.upcoming = 0;
    }
    
	public int getTotal() {
		return total;
	}

	public int getFloating() {
		return floating;
	}

	public int getOverdue() {
		return overdue;
	}

	public int getTomorrow() {
		return tomorrow;
	}

	public int getToday() {
		return today;
	}

	public int getOther() {
		return other;
	}

	public int getUpcoming() {
		return upcoming;
	}	
}

@@ -321,16 +321,70 @@
 146107M%0A
+/**%0A * Counts the numbers of each type of task%0A *%0A */%0A
 public c
@@ -556,16 +556,127 @@
 ming;%0A%09%0A
+%09%0A%09/**%0A%09 * Constructor with ReadOnlyTaskList%0A%09 * %0A%09 * @param src ReadOnlyTaskList containing initial data%0A%09 */%0A
 %09public 
@@ -945,16 +945,125 @@
 );%0A%09%7D%0A%09%0A
+%09/**%0A%09 * Handler for TaskListChangedEvent%0A%09 * %0A%09 * @param tlce TaskListChangedEvent containing new list%0A%09 */%0A
     @Sub
@@ -1125,18 +1125,18 @@
 edEvent 
-ab
+tl
 ce) %7B%0A  
@@ -1192,10 +1192,10 @@
 sk: 
-ab
+tl
 ce.d
@@ -1329,32 +1329,131 @@
 s));%0A    %7D%0A    %0A
+    %0A%09/**%0A%09 * Increments counters based on given task%0A%09 * %0A%09 * @param task Task to be counted%0A%09 */%0A
     private void
@@ -1842,24 +1842,63 @@
 %0A    %7D%0A    %0A
+%09/**%0A%09 * Resets all counters%0A%09 * %0A%09 */%0A
     private 
@@ -2100,16 +2100,21 @@
  %7D%0A    %0A
+    %0A
 %09public 

Refactor TaskCounter