|
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
Hey Sam! Congrats for your project. Am already using it in production code. Just created a post on hamcrest-collection, if you find it useful to add it as a resource, feel free!
http://blog.m.artins.net/hamcrest-out-of-test-code/
Congrats!
This project made me see how usefull Hamcrest is, and how much Java needs better ways of expressing intetion. This was such an influence, that I felt compelled to make a similar project, called Fluent Java, taking enumerations to Smalltalk's (ok more like Ruby's) level.
Good work!