MathExt { public static double between(double value, double min, double max) { Preconditions.checkArgument(min <= max, "min must be less than or equal to max"); return Math.max(Math.min(value, max), min); }  static double scale(double value, double min, double max); static double scale(double value, double min, double max, double minRangeValue, double maxRangeValue); static double between(double value, double min, double max); static long between(long value, long min, long max);  }
@Test public void testBetween0And1() { Assertions.assertThat(MathExt.between(1.1, 0.0, 1.0)).isEqualTo(1.0); Assertions.assertThat(MathExt.between(1.0, 2.0, 10.0)).isEqualTo(2.0); Assertions.assertThat(MathExt.between(0.5, 0.0, 1.0)).isEqualTo(0.5); }
@Test public void testBetween0And1Long() { Assertions.assertThat(MathExt.between(0, 5, 10)).isEqualTo(5); Assertions.assertThat(MathExt.between(1, 2, 10)).isEqualTo(2); Assertions.assertThat(MathExt.between(5, 0, 10)).isEqualTo(5); }