Here you can find the source of convertIntoRange(Integer inValue, int inSteps, int inMin, int inMax)
Parameter | Description |
---|---|
inValue | a parameter |
inMin | a parameter |
inMax | a parameter |
public static Integer convertIntoRange(Integer inValue, int inSteps, int inMin, int inMax)
//package com.java2s; //License from project: Open Source License public class Main { /**//from w w w.j a va 2 s. co m * Adds values to the given value until it is a value within the range of * min and max by adding/substracting the steps value * * @param inValue * @param inMin * @param inMax * @return */ public static Integer convertIntoRange(Integer inValue, int inSteps, int inMin, int inMax) { if (inValue == null) { return null; } if (inMin > inMax) { final int t = inMax; inMax = inMin; inMin = t; } if (inValue >= inMin && inValue <= inMax) { return inValue; } while (inValue < inMin) { inValue += inSteps; } while (inValue > inMax) { inValue -= inSteps; } return inValue < inMin || inValue > inMax ? null : inValue; } }