
import traildb.*;

import java.io.FileNotFoundException;

class Parallel implements Runnable {
	TrailDB tdb;
	int sessionLimit;
	Parallel(TrailDB tdb, int sessionLimit) {
		this.tdb = tdb;
		this.sessionLimit = sessionLimit;
	}
	public void run() {
		System.out.println("Session Limit: " + sessionLimit);
		TrailDBCursor cursor = new TrailDBCursor(tdb);
		long n = tdb.numTrails();
		long totalSessions = 0;
		long totalEvents = 0;

		for (long i = 0; i < n; i++) {
			TrailDBEvent event;
			cursor.getTrail(i);
			event = cursor.next();
			long prevTime = event.timestamp;
			long numSessions = 1;
			long numEvents = 1;
			while ((event = cursor.next()) != null) {
				if (event.timestamp - prevTime > sessionLimit)
					numSessions++;
				prevTime = event.timestamp;
				numEvents++;
			}
			totalSessions += numSessions;
			totalEvents += numEvents;
		}
		cursor.free();

		System.out.println("Session Limit: " + sessionLimit + " Trails: " + n + " Sessions: " + totalSessions + " Events: " + totalEvents);
	}
}

class ThreadedExample {

	public static void main(String[] args) throws FileNotFoundException, InterruptedException {
		TrailDB tdb = new TrailDB("wikipedia-history-small.tdb");
		int n = 8;
		Thread[] threads = new Thread[n];

		for (int i = 0; i < n; i++) {
			Thread thread = new Thread(new Parallel(tdb, 60 * (i + 1)), "" + i);
			threads[i] = thread;
			thread.start();
		}
		for (int i = 0; i < n; i++) {
			threads[i].join();
		}

		System.out.println("Closing tdb");
		tdb.close();
	}
}

@@ -312,21 +312,19 @@
 ilDB
-Cursor cursor
+Trail trail
  = n
@@ -337,18 +337,20 @@
 ilDB
-Cursor
+Trail
 (tdb
+, 0
 );%0A%09
@@ -356,16 +356,24 @@
 %09%09long n
+umTrails
  = tdb.n
@@ -451,32 +451,40 @@
 ong i = 0; i %3C n
+umTrails
 ; i++) %7B%0A%09%09%09Trai
@@ -483,73 +483,40 @@
 %0A%09%09%09
-T
+t
 rail
-DBEvent event;%0A%09%09%09cursor.getTrail(i);%0A%09%09%09event = cursor.next
+.getTrail(i);%0A%09%09%09trail.peek
 ();%0A
@@ -530,39 +530,42 @@
  prevTime = 
-event.t
+trail.getT
 imestamp
 ;%0A%09%09%09long nu
@@ -548,24 +548,26 @@
 getTimestamp
+()
 ;%0A%09%09%09long nu
@@ -618,31 +618,20 @@
 le (
-(event = cursor
+trail
 .next()
-)
  != 
@@ -646,31 +646,34 @@
 %09%09%09%09if (
-event.t
+trail.getT
 imestamp
  - prevT
@@ -664,16 +664,18 @@
 imestamp
+()
  - prevT
@@ -733,23 +733,26 @@
 e = 
-event.t
+trail.getT
 imestamp
 ;%0A%09%09
@@ -747,16 +747,18 @@
 imestamp
+()
 ;%0A%09%09%09%09nu
@@ -842,25 +842,8 @@
 %0A%09%09%7D
-%0A%09%09cursor.free();
 %0A%0A%09%09
@@ -911,16 +911,24 @@
 s: %22 + n
+umTrails
  + %22 Ses

Update ThreadedExample to use new API