10

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?

well actually
  • 11,810
  • 19
  • 52
  • 70

2 Answers2

7

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

Hugh
  • 8,872
  • 2
  • 37
  • 42
2

If you are using the Google Guava library, this is merely Predicates.and(preds).

Al.G.
  • 4,327
  • 6
  • 31
  • 56
Michael Deardeuff
  • 10,386
  • 5
  • 51
  • 74