I would suggest adding an exists() method to the main class, with the following
simple implementation:
public static boolean exists(Matcher<?> matcher, Object iterable) {
return selectFirst(iterable, matcher) != null;
}
Here are some tests
assertTrue("Anything", exists(anything(), Collections.singleton("foo")));
assertFalse("Nothing", exists(not(anything()), Collections.singleton("foo")));
assertFalse("Empty", exists(anything(), Collections.emptySet()));
assertTrue("Has match", exists(equalTo("foo"), Collections.singleton("foo")));
assertFalse("Has no match", exists(equalTo("foo"), Collections.singleton("bar")));
assertTrue("One of many", exists(equalTo("foo"), Arrays.asList("bar", "foo")));
Original issue reported on code.google.com by mattias....@gmail.com on 15 Apr 2011 at 12:07
Original issue reported on code.google.com by
mattias....@gmail.com
on 15 Apr 2011 at 12:07