package net.sf.jranges.range;

import java.util.Collection;

import net.sf.jranges.range.doublerange.DoubleRange;
import net.sf.jranges.range.integer.IntegerRange;
import net.sf.kerner.utils.math.MathUtils;

public class RangeUtils {
	
	public interface IntegerRangeTask {
		void call(int i);
	}
	
	public interface DoubleRangeTask {
		void call(double d);
	}
	
	private RangeUtils(){}
	
	public static boolean includesAll(IntegerRange range, Collection<? extends Integer> positions){
		for(int i : positions){
			if(range.includes(i)){
				// ok
			} else {
				return false;
			}
		}
		return true;
	}
	
	public static void doForAllInRange(IntegerRange range, IntegerRangeTask task){
		for(int i = range.getStart(); i <= range.getStop(); i+= range.getInterval()){
			task.call(i);
		}
	}
	
	public static void doForAllInRange(DoubleRange range, DoubleRangeTask task){
		for(double i = range.getStart(); MathUtils.round(i, 6) <= range.getStop(); i+= range.getInterval()){
			task.call(i);
		}
	}

}

@@ -990,11 +990,251 @@
 %0A%09%09%7D%0A%09%7D%0A
+%09%0A%09public static int startStayWithinLimit(int value, int limit)%7B%0A%09%09if(value %3C limit)%0A%09%09%09return limit;%0A%09%09return value;%0A%09%7D%0A%09%0A%09public static int stopStayWithinLimit(int value, int limit)%7B%0A%09%09if(value %3E limit)%0A%09%09%09return limit;%0A%09%09return value;%0A%09%7D
 %0A%7D%0A

Introduce RangeUtils#*stayWithinRange().