@Test(expected = IllegalArgumentException.class) public void shouldFailIfValueIsOutsideTheUpperBound() { Validate.checkRange(21, 10, 20); }
public static <T extends Comparable<T>> T checkRange(T value, T begin, T end) { if (value.compareTo(begin) >= 0 && value.compareTo(end) <= 0) { return value; } throw new IllegalArgumentException("Value [" + value + "] out of range: [" + begin + ".." + end + "]"); }
Validate { public static <T extends Comparable<T>> T checkRange(T value, T begin, T end) { if (value.compareTo(begin) >= 0 && value.compareTo(end) <= 0) { return value; } throw new IllegalArgumentException("Value [" + value + "] out of range: [" + begin + ".." + end + "]"); } }
Validate { public static <T extends Comparable<T>> T checkRange(T value, T begin, T end) { if (value.compareTo(begin) >= 0 && value.compareTo(end) <= 0) { return value; } throw new IllegalArgumentException("Value [" + value + "] out of range: [" + begin + ".." + end + "]"); } private  Validate(); }
Validate { public static <T extends Comparable<T>> T checkRange(T value, T begin, T end) { if (value.compareTo(begin) >= 0 && value.compareTo(end) <= 0) { return value; } throw new IllegalArgumentException("Value [" + value + "] out of range: [" + begin + ".." + end + "]"); } private  Validate(); static void isTrue(boolean expression); static void isTrue(boolean expression, String message); static T notNull(T object); static T notNull(T object, String message); static T checkRange(T value, T begin, T end); }
Validate { public static <T extends Comparable<T>> T checkRange(T value, T begin, T end) { if (value.compareTo(begin) >= 0 && value.compareTo(end) <= 0) { return value; } throw new IllegalArgumentException("Value [" + value + "] out of range: [" + begin + ".." + end + "]"); } private  Validate(); static void isTrue(boolean expression); static void isTrue(boolean expression, String message); static T notNull(T object); static T notNull(T object, String message); static T checkRange(T value, T begin, T end);  }