package primegui;

import javafx.concurrent.Task;

/**
 * Version 1: counts the primes below a limit on a background
 * thread. No progress reporting, no cancelling.
 */
public class BasicPrimeCountTask extends Task<Integer> {

	private int limit_;

	/**
	 * @param limit count the primes below this; read from the UI on the FX
	 *          thread
	 */
	public BasicPrimeCountTask ( int limit ) {
		limit_ = limit;
	}

	@Override
	protected Integer call () {
		int count = 0;
		for ( int n = 2 ; n < limit_ ; n++ ) {
			if ( PrimeCounter.isPrime(n) ) {
				count++;
			}
		}
		return count;
	}

}
