Java tutorial
//package com.java2s; public class Main { public static final int bringToBounds(final int pMinValue, final int pMaxValue, final int pValue) { return Math.max(pMinValue, Math.min(pMaxValue, pValue)); } public static final float bringToBounds(final float pMinValue, final float pMaxValue, final float pValue) { return Math.max(pMinValue, Math.min(pMaxValue, pValue)); } }