package com.tempoiq;

import java.util.Iterator;

public class DataPointCursor implements Cursor<DataPoint> {
  private class DataPointIterator implements Iterator<DataPoint> {
    private final Iterator<Row> rowIterator;
    private final String deviceKey;
    private final String sensorKey;
    private Row nextRow;
    
    public DataPointIterator(DataPointRowCursor rowCursor, String deviceKey, String sensorKey) {
      this.rowIterator = rowCursor.iterator();
      System.out.println("ROW ITERATOR: ");
      for(Row r : rowCursor) {
        System.out.println(r.toString());
      }
      this.deviceKey = deviceKey;
      this.sensorKey = sensorKey;
    }

    @Override
    public boolean hasNext() {
      while (rowIterator.hasNext()) {
	nextRow = rowIterator.next();
	if (nextRow.hasSensor(deviceKey, sensorKey)) {
	  return true;
	}
      }

      return false;
    }

    @Override
    public DataPoint next() {
      return new DataPoint(nextRow.getTimestamp(), nextRow.getValue(deviceKey, sensorKey));
    }

    @Override
    public void remove() {
      throw new UnsupportedOperationException();
    }
  }

  private final String deviceKey;
  private final String sensorKey;
  private final DataPointRowCursor rowCursor;

  public DataPointCursor(DataPointRowCursor rowCursor, String deviceKey, String sensorKey) {
    this.rowCursor = rowCursor;
    this.deviceKey = deviceKey;
    this.sensorKey = sensorKey;
  }

  public Iterator<DataPoint> iterator() {
    return new DataPointIterator(rowCursor, deviceKey, sensorKey);
  }
}

@@ -316,13 +316,9 @@
 ow;%0A
-    
 %0A
+
     
@@ -461,133 +461,8 @@
 ();%0A
-      System.out.println(%22ROW ITERATOR: %22);%0A      for(Row r : rowCursor) %7B%0A        System.out.println(r.toString());%0A      %7D%0A
     
@@ -615,17 +615,24 @@
 xt()) %7B%0A
-%09
+        
 nextRow 
@@ -653,17 +653,24 @@
 next();%0A
-%09
+        
 if (next
@@ -708,17 +708,24 @@
 Key)) %7B%0A
-%09
+        
   return
@@ -735,9 +735,16 @@
 ue;%0A
-%09
+        
 %7D%0A  

Remove old print statements