Java Integer Convert To convertIntoRange(Integer inValue, int inSteps, int inMin, int inMax)

Here you can find the source of convertIntoRange(Integer inValue, int inSteps, int inMin, int inMax)

Description

Adds values to the given value until it is a value within the range of min and max by adding/substracting the steps value

License

Open Source License

Parameter

Parameter Description
inValue a parameter
inMin a parameter
inMax a parameter

Declaration

public static Integer convertIntoRange(Integer inValue, int inSteps, int inMin, int inMax) 

Method Source Code

//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;
    }
}

Related

  1. convertInternalClassNameToQualifiedName(String className)
  2. convertInternalFormToQualifiedClassName( final String classInternalName)
  3. convertIntFromBytes(byte[] byteArray)
  4. convertIntfwl(String[] idArray)
  5. convertIntList(Integer[] list)
  6. convertIntToDayOfWeek(int day)
  7. convertIntToDouble(final int[] intValues)
  8. convertIntToDWord(final int value)
  9. convertIntToLong(Integer intId)