2014-02-12 49 views
0

我正在迭代使用隊列上的迭代器,並測試項目(如果..)我得到: sensorEventp1(當前元素) 無論如何也得到以前的元素?Android java隊列+迭代器 - 無論如何獲得前一個項目?

我試圖用一個計數器(我),但隊列sensorQueue不接受GET(INT)... 感謝意見...

public Vector3 interpolate(Queue<CapturedSensorEvent> sensorQueue, Long interpolationTime, Integer points) { 
    Iterator<CapturedSensorEvent> sensorEventsIterator = sensorQueue.iterator(); 
    Integer i = -1; 
    sensorEventsLoop: 
    while (sensorEventsIterator.hasNext()) { 
     i++; 
     CapturedSensorEvent sensorEventp1 = sensorEventsIterator.next(); 
     if (sensorEventp1.timestamp > interpolationTime) { 
      if (points == 2) { 
       CapturedSensorEvent sensorEventm1 = sensorQueue.get(i-1); 
      } 
      break sensorEventsLoop; 
     } 
    } 
    return Vector3.Zero(); // test only 
} 

回答

1
CapturedSensorEvent previous = null; 
while (sensorEventsIterator.hasNext()) { 
    i++; 
    CapturedSensorEvent sensorEventp1 = sensorEventsIterator.next(); 
    if (sensorEventp1.timestamp > interpolationTime) { 
     if (points == 2) { 
      CapturedSensorEvent sensorEventm1 = previous; 
     } 
     break sensorEventsLoop; 
    } 
    previous = sensorEventp1; 
} 
return Vector3.Zero(); 
+0

的感謝!我現在可以去睡覺了....享受你的一天! – erwin

相關問題