package org.openntf.conference.graph.examples;

import java.text.SimpleDateFormat;
import java.util.List;

import org.openntf.conference.graph.ConferenceGraph;
import org.openntf.conference.graph.Event;
import org.openntf.conference.graph.Presentation;
import org.openntf.conference.graph.TimeSlot;
import org.openntf.domino.junit.TestRunnerUtil;

import com.google.common.collect.Ordering;

public class SessionsByTimeslot implements Runnable {
	private long marktime;
	private SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd/MM HH:mm");

	public SessionsByTimeslot() {

	}

	@Override
	public void run() {
		long testStartTime = System.nanoTime();
		marktime = System.nanoTime();
		try {
			timelog("Beginning Sessions By TimeSlot...");
			ConferenceGraph graph = new ConferenceGraph();

			Ordering<TimeSlot> byStart = new Ordering<TimeSlot>() {

				@Override
				public int compare(final TimeSlot t1, final TimeSlot t2) {
					return t1.getStartTime().compareTo(t2.getStartTime());
				}
			};

			Iterable<TimeSlot> times = graph.getTimeSlots();
			List<TimeSlot> timesSorted = byStart.sortedCopy(times);
			for (TimeSlot ts : timesSorted) {
				System.out.println("Sessions running from " + DATE_FORMAT.format(ts.getStartTime().getTime()) + " to "
						+ DATE_FORMAT.format(ts.getEndTime().getTime()));
				Iterable<Event> presentations = ts.getEvents();
				for (Event evt : presentations) {
					if (evt instanceof Presentation) {
						Presentation pres = (Presentation) evt;
						System.out.println(pres.getSessionId() + ": " + pres.getTitle());
					}

				}

			}
		} catch (Throwable t) {
			t.printStackTrace();
		}
		long testEndTime = System.nanoTime();
		System.out.println("Completed " + getClass().getSimpleName() + " run in " + ((testEndTime - testStartTime) / 1000000) + " ms");
	}

	public void timelog(final String message) {
		long curtime = System.nanoTime();
		long elapsed = curtime - marktime;
		marktime = curtime;
		System.out.println(elapsed / 1000000 + " ms: " + message);
	}

	public static void main(final String[] args) {
		TestRunnerUtil.runAsDominoThread(new SessionsByTimeslot(), TestRunnerUtil.NATIVE_SESSION);
	}
}

@@ -101,24 +101,71 @@
 il.List;%0D%0A%0D%0A
+import org.openntf.conference.graph.Attendee;%0D%0A
 import org.o
@@ -206,16 +206,16 @@
 Graph;%0D%0A
-
 import o
@@ -344,24 +344,60 @@
 .TimeSlot;%0D%0A
+import org.openntf.domino.Session;%0D%0A
 import org.o
@@ -432,16 +432,112 @@
 erUtil;%0D
+%0Aimport org.openntf.domino.utils.Factory;%0D%0Aimport org.openntf.domino.utils.Factory.SessionType;%0D
 %0A%0D%0Aimpor
@@ -946,16 +946,16 @@
 ...%22);%0D%0A
-
 %09%09%09Confe
@@ -999,16 +999,186 @@
 h();%0D%0A%0D%0A
+%09%09%09Session session = Factory.getSession(SessionType.CURRENT);%0D%0A%09%09%09String myName = session.getEffectiveUserName();%0D%0A%09%09%09Attendee att = graph.getAttendee(myName, false);%0D%0A%0D%0A
 %09%09%09Order

Test on getting me