title: Java 8 Stream filter with comparator
body: <p>I want to filter list of <code>MyObject</code> based on <code>values</code> field. In this case: if any value on <code>MyObject::getValues</code> is less than given <code>value</code>, than the predicate is false. I haven't found the way to do it with Stream API, so I tried <code>ComparatorPredicate</code> by <code>Apache</code>. Here is my try:</p>
  
  <pre><code>private Predicate&lt;MyObject&gt; valueGreaterThanOrEqualTo(ValueObject value){
      return myObject -&gt; myObject.getValues().stream()
              .noneMatch(v -&gt; ComparatorPredicate.comparatorPredicate(value, new ValueComparator(), ComparatorPredicate.Criterion.LESS)
                      .evaluate(v));
  }
  </code></pre>
  
  <p>This, however, results in:</p>
  
  <pre><code>Caused by: java.lang.ClassCastException: Cannot cast java.lang.Boolean to com.ValueObject
      at java.lang.Class.cast(Class.java:3369)
      at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
      at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
      at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
      at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
      at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
      at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
      at java.util.ArrayList$ArrayListSpliterator.tryAdvance(ArrayList.java:1351)
      at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126)
      at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:498)
      at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485)
      at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
      at java.util.stream.MatchOps$MatchOp.evaluateSequential(MatchOps.java:230)
      at java.util.stream.MatchOps$MatchOp.evaluateSequential(MatchOps.java:196)
      at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
      at java.util.stream.ReferencePipeline.noneMatch(ReferencePipeline.java:459)
  </code></pre>
  
  <p>So my question is why does the ClassCastException occur and how to resolve it AND/OR how to resolve my problem with some other (better?) solution?</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>A little update on the issue. The first problem (<code>ClassCastException</code>) was caused by the code I didn't include in my example. After solving it <code>ComparatorPredicate</code> works fine, so if you like it: go for it. I, however will go with the suggestion from accepted answer which is simpler and doesn't involve using external libs. Especially since <code>ComparatorPredicate</code> doesn't extend <code>java.util.function.Predicate</code> but <code>org.apache.commons.collections4.Predicate</code> instead.</p>