/**Code copied and re-adapted  from  
 * http://www.ibm.com/developerworks/java/library/j-jtp11137.html and 
 * http://www.ibm.com/developerworks/java/library/j-jtp03048.html 
 */

package maxInParallel;

public class SelectMaxProblem {

	private final int[] numbers;
	private final int start;
	private final int end;
	
	/** Constructor for parallel execution. 
	 * 
	 * @param numbers
	 * @param start
	 * @param end
	 */
	public SelectMaxProblem(int[] numbers, int start, int end) {
		this.numbers = numbers;
		this.start = start;
		this.end = end;
	}
	
	/** Constructor for sequential execution.
	 * 
	 * @param numbers
	 */
	public SelectMaxProblem(int[] numbers) {
		this.numbers = numbers;
		this.start = 0;
		this.end = numbers.length-1;
	}

	public int solveSequentially(){
		int max = Integer.MIN_VALUE;
		for (int i = start; i<end; i++){
			int n = numbers[i];
			if(n > max)
				max = n;
		}
		return max;
	}
	
	public SelectMaxProblem subproblem(int subStart, int subEnd){
		return new SelectMaxProblem(numbers, start+subStart, start+subEnd);
	}
	
	public int getSize() {
		return end-start;
	}
}