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

org.javasimon.testapp.WeightController Maven / Gradle / Ivy

There is a newer version: 3.4.0
Show newest version
package org.javasimon.testapp;

import org.javasimon.testapp.test.Action;
import org.javasimon.testapp.test.Controller;

import java.util.*;

/**
 * Class WeightController.
 *
 * @author Radovan Sninsky
 * @since 2.0
 */
public class WeightController implements Controller {

	private final Random random = new Random();

	private SortedMap actions = new TreeMap();

	public WeightController() {
	}

	public void addAction(Action action, int weight) {
		int last = 0;
		if (actions.size() > 0) {
			for (int x : actions.keySet()) {
				last = x;
			}
		}
		actions.put(last+weight, action);
	}

	public Action next() {
		int x = random.nextInt(100);
		for (int i : actions.keySet()) {
			if (x < i) {
				return actions.get(i);
			}
		}
		return null;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy