Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java: Combining multiple predicates

In Java, is there a short elegant way to combine multiple predicates (Guava Predicate) into one?

Currently, I have some list of predicates:

Collection<Predicate<TypeA>> preds = ...;

And I have some code that loops through the predicates and returns false if any one of them are false. Is there a one-liner that accomplishes the same thing?

like image 621
well actually Avatar asked Nov 08 '11 01:11

well actually


1 Answers

If you're using Guava, it looks like Predicates#and will do what you want.

like image 118
Hugh Avatar answered Sep 21 '22 15:09

Hugh