|
GettingStarted
A Quick Guide on how to use hamcrest-collections
Download ItGrab the zip, unzip it and add the Jar to your classpath. Runtime DependenciesHamcrest-collections relies on Hamcrest 1.1 or later. Use ItSelect & Rejectselect and reject allow you to filter lists based on any Hamcrest Matcher. Hamcrest comes with useful Matchers like greatherThan, equalTo etc., but you are free to create your own. select returns a collection of items that match the matcher, reject returns a list of items that don't match the matcher. For example: import static org.hamcrest.Matchers greaterThan; import static org.hamcrestcollections.SelectMatcher select; import static org.hamcrestcollections.RejectMatcher reject; ... List<Integer> myInts = new ArrayList<Integer>(); myInts.add(1); myInts.add(2); myInts.add(3); myInts.add(4); Iterable<Integer> oneAndTwo = reject(myInts, greaterThan(2)); Iterable<Integer> threeAndFour = select(myInts, greaterThan(2)); |
Sign in to add a comment
