Details

    • Type: CSR
    • Status: Closed
    • Priority: P3
    • Resolution: Approved
    • Fix Version/s: 11
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Compatibility Risk:
      minimal
    • Interface Kind:
      Java API
    • Scope:
      SE

      Description

      Summary

      Introduce a new static method Predicate::not which will allow developers to negate predicate lambdas trivially.

      Problem

      The requirement for predicate negation occurs frequently since predicates are defined antipodal to a positive selection; isNull, isEmpty, isBlank.

      Presently there is no easy way to negate a predicate lambda without first wrapping in a Predicate Object.

      Ex.
      
          List<String> list = bufferedReader
            .lines()
            .filter(((Predicate<String>)String::isEmpty).negate())
            .collect(toList()); 

      Solution

      Introduce a method that accepts an unwrapped lambda and returns the negated form.

      Ex.
      
      import static java.util.function.Predicate.not;
      ...
      
          List<String> list = bufferedReader
            .lines()
            .filter(not(String::isEmpty))
            .collect(toList()); 

      Specification

          /**
           * Returns a predicate that is the negation of the
           * supplied predicate.
           * @param <T>     the type of arguments to the
           *                specified predicate
           * @param target  predicate to negate
           *
           * @return a predicate that negates the results
           *         of the supplied predicate
           *
           * @since 11
           */
          static <T> Predicate<T> not(Predicate<? super T> target) {
              return (Predicate<T>)target.negate();
          }

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                jlaskey Jim Laskey
                Reporter:
                webbuggrp Webbug Group
                Reviewed By:
                Chris Hegarty, Doug Lea, Paul Sandoz, RĂ©mi Forax, Stuart Marks
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: