RangeUtil { public static int constrain(int value, int min, int max) { return Math.min(max, Math.max(value, min)); }  static int constrain(int value, int min, int max); static float constrain(float value, float min, float max); static double constrain(double value, double min, double max); static int map(float value, float fromLow, float fromHigh, int toLow, int toHigh); static int map(float value, float fromLow, float fromHigh, int toLow, int toHigh, boolean constrain); static float map(float value, float fromLow, float fromHigh, float toLow, float toHigh); static float map(float value, float fromLow, float fromHigh, float toLow, float toHigh, boolean constrain); static double map(double value, double fromLow, double fromHigh, double toLow, double toHigh); static double map(double value, double fromLow, double fromHigh, double toLow, double toHigh, boolean constrain);  }
@Test public void testConstrain() { int min = -90; int max = 90; Assert.assertEquals(min, RangeUtil.constrain(min, min, max)); Assert.assertEquals(min, RangeUtil.constrain(min - 1, min, max)); Assert.assertEquals(max, RangeUtil.constrain(max, min, max)); Assert.assertEquals(max, RangeUtil.constrain(max + 1, min, max)); Assert.assertEquals(max / 2, RangeUtil.constrain(max / 2, min, max)); }