All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.finmath.timeseries.TimeSeriesView Maven / Gradle / Ivy

package net.finmath.timeseries;

import java.util.Iterator;

/**
 * A time series created from a sup-interval of another time series.
 *
 * @author Christian Fries
 * @version 1.0
 */
public class TimeSeriesView implements TimeSeries {

	private final TimeSeries timeSeries;
	private final int indexStart;
	private final int indexEnd;

	public TimeSeriesView(final TimeSeries timeSeries, final int indexStart, final int indexEnd) {
		super();
		this.timeSeries = timeSeries;
		this.indexStart = indexStart;
		this.indexEnd = indexEnd;
	}

	@Override
	public double getTime(final int index) {
		return timeSeries.getTime(indexStart+index);
	}

	@Override
	public double getValue(final int index) {
		return timeSeries.getValue(indexStart+index);
	}

	@Override
	public int getNumberOfTimePoints() {
		return indexEnd-indexStart+1;
	}

	@Override
	public Iterable getValues() {
		return new Iterable() {
			private int index = 0;

			@Override
			public Iterator iterator() {
				return new Iterator() {
					@Override
					public boolean hasNext() {
						return index < TimeSeriesView.this.getNumberOfTimePoints();
					}

					@Override
					public Double next() {
						return TimeSeriesView.this.getValue(index++);
					}
				};
			}

		};
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy