ifeilong / feilong-core

:gem: Reduce development, Release ideas
Apache License 2.0
529 stars 155 forks source link

新建 RegexStringPredicate #775

Closed venusdrogon closed 5 years ago

venusdrogon commented 5 years ago

适用于在 字符串 list 中查找 特定格式的字符串

新建 RegexStringPredicate

venusdrogon commented 5 years ago

 @Test
    public void testSelectPredicateTest(){
        String string = "15002841618";
        String regexPattern = "^1[3456789]\\d{9}$";

        //---------------------------------------------------------------
        List<String> list = toList(//
                        null,
                        string,
                        string,
                        string,
                        null,
                        string,
                        "飞龙",
                        "",
                        "jinxin",
                        string,
                        string);

        List<String> select = select(list, new RegexStringPredicate(regexPattern));

        assertThat(
                        select,
                        allOf(//
                                        hasItem(string),

                                        not(hasItem("飞龙")),
                                        not(hasItem("")),
                                        not(hasItem((String) null)),
                                        not(hasItem("jinxin"))
                        //
                        ));
    }