X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.history%2Fsrc%2Forg%2Fsimantics%2Fhistory%2Futil%2FStreamIterator.java;h=e548f9bf805efd0ff3a3edce39fb20ef73325a1e;hb=refs%2Fchanges%2F38%2F238%2F2;hp=c30862af53c185dc2a1cbb52150f0b9e5704fcb4;hpb=24e2b34260f219f0d1644ca7a138894980e25b14;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.history/src/org/simantics/history/util/StreamIterator.java b/bundles/org.simantics.history/src/org/simantics/history/util/StreamIterator.java index c30862af5..e548f9bf8 100644 --- a/bundles/org.simantics.history/src/org/simantics/history/util/StreamIterator.java +++ b/bundles/org.simantics.history/src/org/simantics/history/util/StreamIterator.java @@ -1,291 +1,291 @@ -/******************************************************************************* - * Copyright (c) 2007, 2012 Association for Decentralized Information Management in - * Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.history.util; - -import org.simantics.databoard.Bindings; -import org.simantics.databoard.accessor.ArrayAccessor; -import org.simantics.databoard.accessor.error.AccessorException; -import org.simantics.databoard.binding.Binding; -import org.simantics.databoard.binding.RecordBinding; -import org.simantics.databoard.binding.error.BindingException; -import org.simantics.history.HistoryException; - -/** - * Stream iterator iterates sample entries in an array. - * - * Is scans the next sample and knows its time stamp. - * - * @author toni.kalajainen - */ -public class StreamIterator { - - // Sample binding - RecordBinding sampleBinding; - - // Array accessor - ArrayAccessor aa; - // Array stream - Stream stream; - // From and end times of the whole stream - double from, end; - - // Current and next sample - Object current, next; - - // Utility for reading sample - ValueBand valueBand, nextValueBand; - // Start and end time of current sample - double startTime, endTime; - - int index = -1; - int size; - - public StreamIterator(ArrayAccessor aa) throws HistoryException { - try { - this.aa = aa; - sampleBinding = (RecordBinding) Bindings.getBeanBinding( aa.type().componentType ); - current = sampleBinding.createDefault(); - next = sampleBinding.createDefault(); - valueBand = new ValueBand(sampleBinding, current); - nextValueBand = new ValueBand(sampleBinding, next); - stream = new Stream( aa, sampleBinding ); - size = aa.size(); - if ( size>0 ) { - aa.get(0, sampleBinding, current); - from = valueBand.getTimeDouble(); - aa.get(size-1, sampleBinding, current); - end = valueBand.hasEndTime() ? valueBand.getEndTimeDouble() : valueBand.getTimeDouble(); - } - } catch (BindingException e) { - throw new HistoryException( e ); - } catch (AccessorException e) { - throw new HistoryException( e ); - } - } - - /** - * Go to time using random access - * @param time - * @return true if sample was found - * @throws HistoryException - */ - public boolean gotoTime(double time) throws HistoryException { - // Outside range - if ( timeend ) { - index = -1; - return false; - } - - // Already at cursor - if ( time>=startTime && time=0) { - gotoIndex( i ); - } else { - int insertPos = -i-2; - if ( insertPos<0 || insertPos>=size ) { - index = -1; - } else { - gotoIndex( insertPos ); - if ( endTime