
import traildb.TrailDB;
import traildb.TrailDBConstructor;
import traildb.TrailDBCursor;
import traildb.TrailDBEvent;
import traildb.TrailDBMultiCursor;
import traildb.TrailDBMultiEvent;

import java.util.UUID;
import java.io.FileNotFoundException;


class Event {
	UUID cookie;
	int timestamp;
	String[] values;
	Event(UUID cookie, int timestamp, String[] values) {
		this.cookie = cookie;
		this.timestamp = timestamp;
		this.values = values;
	}
}

public class MultiCursors {

	public static void read() throws FileNotFoundException {
		System.out.println("Reading");
		TrailDB tdb1 = new TrailDB("tiny1.tdb");
		TrailDB tdb2 = new TrailDB("tiny2.tdb");
		TrailDBCursor c1 = new TrailDBCursor(tdb1);
		TrailDBCursor c2 = new TrailDBCursor(tdb2);
		c1.getTrail(0);
		c2.getTrail(1);

		TrailDBCursor[] cursors = new TrailDBCursor[] {c1, c2};

		TrailDBMultiCursor multi = new TrailDBMultiCursor(cursors);
		TrailDBMultiEvent mevent;

		while ((mevent = multi.next()) != null) {
			System.out.println(mevent.event.timestamp);
		}
	}

	public static void write(String name, String[] fields, Event[] events) throws FileNotFoundException {
		TrailDBConstructor cons = new TrailDBConstructor(name, fields);
		for (int i = 0; i < events.length; i++) {
			cons.add(events[i].cookie, events[i].timestamp, events[i].values);
		}
		cons.finalize();
		cons.close();
		System.out.println("Wrote: " + name);
	}

	public static void main(String[] args) throws FileNotFoundException {
		UUID cookie1 = UUID.randomUUID();
		UUID cookie2 = UUID.randomUUID();

		write("tiny1", new String[] {"user", "action"}, new Event[] {
				new Event(cookie1, 2, new String[] {"bob", "run"}),
				new Event(cookie2, 4, new String[] {"fred", "walk"}),
				new Event(cookie1, 8, new String[] {"jerry", "speak"}),
				new Event(cookie2, 10, new String[] {"ted", "fly"}),
				new Event(cookie2, 12, new String[] {"doug", "dab"}),
		});

		write("tiny2", new String[] {"user", "action"}, new Event[] {
				new Event(cookie2, 1, new String[] {"cindy", "run"}),
				new Event(cookie2, 3, new String[] {"lucy", "walk"}),
				new Event(cookie1, 5, new String[] {"mary", "speak"}),
				new Event(cookie1, 6, new String[] {"sue", "fly"}),
				new Event(cookie2, 7, new String[] {"gunhilda of denmark", "dab"}),
		});

		System.out.println("Finished writing");
		read();
	}
}
@@ -79,112 +79,47 @@
 ilDB
-Cursor;%0Aimport traildb.TrailDBEvent;%0Aimport traildb.TrailDBMultiCursor;%0Aimport traildb.TrailDBMultiEvent
+Trail;%0Aimport traildb.TrailDBMultiTrail
 ;%0A%0Ai
@@ -434,16 +434,30 @@
 id read(
+UUID%5B%5D cookies
 ) throws
@@ -609,24 +609,27 @@
 %09TrailDB
-Cursor c
+Trail trail
 1 = new 
@@ -639,19 +639,21 @@
 ilDB
-Cursor
+Trail
 (tdb1
+, 0
 );%0A%09
@@ -664,16 +664,19 @@
 ilDB
-Cursor c
+Trail trail
 2 = 
@@ -690,113 +690,84 @@
 ilDB
-Cursor(tdb2);%0A%09%09c1.getTrail(0);%0A%09%09c2.getTrail(1);%0A%0A%09%09TrailDBCursor%5B%5D cursors = new TrailDBCursor%5B%5D %7Bc1, c
+Trail(tdb2, 1);%0A%0A%09%09TrailDBTrail%5B%5D trails = new TrailDBTrail%5B%5D %7Btrail1, trail
 2%7D;%0A
@@ -781,22 +781,21 @@
 lDBMulti
-Cursor
+Trail
  multi =
@@ -815,51 +815,21 @@
 ulti
-Cursor(cursors);%0A%09%09TrailDBMultiEvent mevent
+Trail(trails)
 ;%0A%0A%09
@@ -840,18 +840,8 @@
 le (
-(mevent = 
 mult
@@ -848,17 +848,16 @@
 i.next()
-)
  != null
@@ -887,29 +887,70 @@
 ln(m
-event.event.timestamp
+ulti.getTimestamp());%0A//%09%09%09System.out.println(multi.getItem(0)
 );%0A%09
@@ -2249,15 +2249,44 @@
 %0A%09%09read(
+new UUID%5B%5D %7Bcookie1, cookie2%7D
 );%0A%09%7D%0A%7D

Update MultiCursors example to use new API