简体   繁体   English

将 Guava 谓词转换为 Java 8 谓词

[英]Convert Guava predicate to Java 8 predicate

I am trying to convert the below code to java predicate from Gauva predicate but don't know how to apply or,and not function of java predicate to the below method我正在尝试将以下代码从 Gauva 谓词转换为 java 谓词,但不知道如何应用或,而不是 java 谓词的 function 到以下方法

import java.util.function.Predicate;
class Test {

private Predicate<String> getPath() {
      
        return or(

               
                PathSelectors.ant("/v1/*/s1/**"),
                PathSelectors.ant("/v1/*/s2/**"),
                and(PathSelectors.ant("/v/*/test/*/s3/*")),
                not(PathSelectors.ant("/v1/*/test/*/s4/*"))),
                PathSelectors.ant("/v1/*/test/*/s5/*/*"),
                PathSelectors.ant("/v1/*/test/*/s5/*/*"),
               
        );
    }
    
    }

Predicate has and , or and a negate method, but and and or only accept a single other predicate. Predicateand , or and 一个negate方法,但是 and 和 or 只接受一个单独的其他谓词。 Still you can use these methods like this:您仍然可以像这样使用这些方法:

PathSelectors.ant("/v1/*/s1/**")
     .or(PathSelectors.ant("/v1/*/s2/**")
    .or(PathSelectors.ant("/v/*/test/*/s3/*").and(PathSelectors.ant("/v1/*/test/*/s4/*").negate()))
    .or(PathSelectors.ant("/v1/*/test/*/s5/*/*")
    .or(PathSelectors.ant("/v1/*/test/*/s5/*/*");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM