1 package org.hamcrest.number; 2 3 import org.hamcrest.Matcher; 4 import org.hamcrest.comparator.ComparatorMatcherBuilder; 5 6 public class OrderingComparison { 7 OrderingComparison()8 private OrderingComparison() { 9 } 10 11 /** 12 * Creates a matcher of {@link Comparable} object that matches when the examined object is 13 * equal to the specified value, as reported by the <code>compareTo</code> method of the 14 * <b>examined</b> object. 15 * For example: 16 * <pre>assertThat(1, comparesEqualTo(1))</pre> 17 * 18 * @param value the value which, when passed to the compareTo method of the examined object, should return zero 19 */ comparesEqualTo(T value)20 public static <T extends Comparable<T>> Matcher<T> comparesEqualTo(T value) { 21 return ComparatorMatcherBuilder.<T>usingNaturalOrdering().comparesEqualTo(value); 22 } 23 24 /** 25 * Creates a matcher of {@link Comparable} object that matches when the examined object is 26 * greater than the specified value, as reported by the <code>compareTo</code> method of the 27 * <b>examined</b> object. 28 * For example: 29 * <pre>assertThat(2, greaterThan(1))</pre> 30 * 31 * @param value the value which, when passed to the compareTo method of the examined object, should return greater 32 * than zero 33 */ greaterThan(T value)34 public static <T extends Comparable<T>> Matcher<T> greaterThan(T value) { 35 return ComparatorMatcherBuilder.<T>usingNaturalOrdering().greaterThan(value); 36 } 37 38 /** 39 * Creates a matcher of {@link Comparable} object that matches when the examined object is 40 * greater than or equal to the specified value, as reported by the <code>compareTo</code> method 41 * of the <b>examined</b> object. 42 * For example: 43 * <pre>assertThat(1, greaterThanOrEqualTo(1))</pre> 44 * 45 * @param value the value which, when passed to the compareTo method of the examined object, should return greater 46 * than or equal to zero 47 */ greaterThanOrEqualTo(T value)48 public static <T extends Comparable<T>> Matcher<T> greaterThanOrEqualTo(T value) { 49 return ComparatorMatcherBuilder.<T>usingNaturalOrdering().greaterThanOrEqualTo(value); 50 } 51 52 /** 53 * Creates a matcher of {@link Comparable} object that matches when the examined object is 54 * less than the specified value, as reported by the <code>compareTo</code> method of the 55 * <b>examined</b> object. 56 * For example: 57 * <pre>assertThat(1, lessThan(2))</pre> 58 * 59 * @param value the value which, when passed to the compareTo method of the examined object, should return less 60 * than zero 61 */ lessThan(T value)62 public static <T extends Comparable<T>> Matcher<T> lessThan(T value) { 63 return ComparatorMatcherBuilder.<T>usingNaturalOrdering().lessThan(value); 64 } 65 66 /** 67 * Creates a matcher of {@link Comparable} object that matches when the examined object is 68 * less than or equal to the specified value, as reported by the <code>compareTo</code> method 69 * of the <b>examined</b> object. 70 * For example: 71 * <pre>assertThat(1, lessThanOrEqualTo(1))</pre> 72 * 73 * @param value the value which, when passed to the compareTo method of the examined object, should return less 74 * than or equal to zero 75 */ lessThanOrEqualTo(T value)76 public static <T extends Comparable<T>> Matcher<T> lessThanOrEqualTo(T value) { 77 return ComparatorMatcherBuilder.<T>usingNaturalOrdering().lessThanOrEqualTo(value); 78 } 79 } 80