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

org.jamesii.ml3.observation.TimePointListObserver Maven / Gradle / Ivy

Go to download

The Modeling Language for Linked Lives, a domain specific modeling language for agent-based computational demography.

There is a newer version: 0.2.8
Show newest version
/*
 * Copyright 2017 University of Rostock
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jamesii.ml3.observation;

import java.util.ArrayList;
import java.util.List;

/**
 * Observer that is triggered at a list of time points. The observer will
 * definitely notify it's listeners once for every time in it's list, even when
 * the simulation finishes early.
 * 
 * @author Oliver Reinhardt
 *
 */
public class TimePointListObserver extends TimeTriggeredObserver {
	private List observationPoints;
	private int index;

	/**
	 * @param observationPoints
	 *            - the times of observation
	 */
	public TimePointListObserver(List observationPoints) {
		this.observationPoints = observationPoints;
	}

	/**
	 * @param observationPoints
	 *            - the times of observation
	 */
	public TimePointListObserver(double... observationPoints) {
		this.observationPoints = new ArrayList<>(observationPoints.length);
		for (double observationPoint : observationPoints) {
			this.observationPoints.add(observationPoint);
		}
	}

	@Override
	protected double getNextObservationPoint() {
		if (index < observationPoints.size())
			return observationPoints.get(index);
		else
			return Double.POSITIVE_INFINITY;
	}

	@Override
	protected void advanceObservationPoint() {
		index++;
	}

	@Override
	protected boolean hasMandatoryNextObservationPoint() {
		return index < observationPoints.size();
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy