package udo.storage;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.GregorianCalendar;
import java.util.Iterator;
import java.util.PriorityQueue;
import java.util.Timer;
import java.util.TimerTask;

import udo.storage.Task.TaskType;

public class Reminder extends TimerTask {
	public static final String EOL = System.getProperty("line.separator");
	//private static File storageFile;
	private static PriorityQueue<Task> taskQueue;

	public static void main(String[] args) throws IOException{

		PriorityQueue<Task> pq = PQ();
		System.out.println("taskQueue "+pq);
		remind();
		System.out.println("HERE "+remindList);
	}

	//read from json file
	static String lastPath;
	public static PriorityQueue<Task> PQ(){
		taskQueue = new PriorityQueue<Task>(10, new ReminderComparator());
		ArrayList<Task> taskList = new ArrayList<Task>();
		try {
			System.out.println("Reading JSON file from setting");
			FileReader fr = new FileReader("setting.txt");
			BufferedReader br = new BufferedReader(fr);
			lastPath = br.readLine();
			br.close();
			taskList = JsonProcessor.readJson(lastPath);
			taskList.add(new Task(TaskType.DEADLINE, "fighting", new GregorianCalendar(2010,01,03), 
					new GregorianCalendar(2011,01,02),new GregorianCalendar(2010,01,03), 5,new GregorianCalendar(2010,01,03),
					"personal", false, false));
			taskList.add(new Task(TaskType.DEADLINE, "jogging", new GregorianCalendar(2010,01,03), 
					new GregorianCalendar(2011,01,02),new GregorianCalendar(2010,01,03), 10,new GregorianCalendar(2010,01,02),
					"personal", false, false));
			taskList.add(new Task(TaskType.DEADLINE, "sleeping", new GregorianCalendar(2010,01,03), 
					new GregorianCalendar(2011,01,02),new GregorianCalendar(2010,01,03), 15,new GregorianCalendar(2010,01,05),
					"personal", false, false));
			taskList.add(new Task(TaskType.DEADLINE, "crying", new GregorianCalendar(2010,01,03), 
					new GregorianCalendar(2011,01,02),new GregorianCalendar(2010,01,03), 15,new GregorianCalendar(2010,01,05),
					"personal", false, true));

			for (int i =0; i<taskList.size(); i++) {
				if (!taskList.get(i).isDone())
					taskQueue.add(taskList.get(i));
			}
		} catch (Exception ex) {
			PQ();
		}
		return taskQueue;
	}
	public static ArrayList<Task> remind() {
		Timer timer = new Timer();
		if (!taskQueue.isEmpty()) {
		timer.schedule(new Reminder(), taskQueue.peek().getReminder().getTime());
		}
		return remindList;
	}
	static ArrayList<Task> remindList = new ArrayList<Task>();
	public Reminder() {
	}
	@Override
	public void run() {
		remindList.add(taskQueue.poll());
	}
}

@@ -2499,16 +2499,23 @@
 st;%0A%09%7D%0A%09
+public 
 static A
@@ -2586,16 +2586,25 @@
 der() %7B%0A
+%09%09run();%0A
 %09%7D%0A%09@Ove

Add run() into reminder()