From 4c7d96e36207a833a99e4269b9e3aef972a2bcb6 Mon Sep 17 00:00:00 2001 From: feilong Date: Sun, 25 Aug 2019 21:48:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20ContainsStringPredicate=20?= =?UTF-8?q?fix=20#791?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- pom.xml | 2 +- .../predicate/ContainsStringPredicate.java | 83 +++++++++++++++++++ ...tainsStringPredicateParameterizedTest.java | 53 ++++++++++++ .../FeiLongBeanPredicateUtilSuiteTests.java | 2 + 5 files changed, 140 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/feilong/core/util/predicate/ContainsStringPredicate.java create mode 100644 src/test/java/com/feilong/core/util/predicate/ContainsStringPredicateParameterizedTest.java diff --git a/README.md b/README.md index 997358f2..45aee390 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ feilong core 让Java开发更简便的工具包 ![JDK 1.7](https://img.shields.io/badge/JDK-1.7-green.svg "JDK 1.7") [![jar size 110K](https://img.shields.io/badge/size-110K-green.svg "size 110K")](https://github.com/venusdrogon/feilong-platform/tree/repository/com/feilong/platform/feilong-core/1.14.0) [![javadoc 83%](http://progressed.io/bar/83?title=javadoc "javadoc 83%")](http://venusdrogon.github.io/feilong-platform/javadocs/feilong-core/) -[![tests 2160](https://img.shields.io/badge/tests-2160%20%2F%202160-green.svg "tests 2160")](https://github.com/venusdrogon/feilong-core/tree/master/src/test/java/com/feilong/core) +[![tests 2164](https://img.shields.io/badge/tests-2164%20%2F%202164-green.svg "tests 2164")](https://github.com/venusdrogon/feilong-core/tree/master/src/test/java/com/feilong/core) ![Coverage 91%](http://progressed.io/bar/91?title=Coverage "Coverage 91%") ![sonar](http://venusdrogon.github.io/feilong-platform/mysource/sonar/feilong-core-summary2.jpg) diff --git a/pom.xml b/pom.xml index 9d326466..9f0051e5 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.feilong.platform parent - 1.14.2 + 1.14.3 feilong-core diff --git a/src/main/java/com/feilong/core/util/predicate/ContainsStringPredicate.java b/src/main/java/com/feilong/core/util/predicate/ContainsStringPredicate.java new file mode 100644 index 00000000..3ec66371 --- /dev/null +++ b/src/main/java/com/feilong/core/util/predicate/ContainsStringPredicate.java @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2008 feilong + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.feilong.core.util.predicate; + +import org.apache.commons.lang3.StringUtils; + +/** + * 判断字符串是否包含指定的 searchCharSequence. + * + * @author feilong + * @since 1.14.3 + */ +public class ContainsStringPredicate implements StringPredicate{ + + /** The search char sequence. */ + private CharSequence searchCharSequence; + + //--------------------------------------------------------------- + + /** + * Instantiates a new contains string predicate. + */ + public ContainsStringPredicate(){ + super(); + } + + /** + * Instantiates a new contains string predicate. + * + * @param searchCharSequence + * the search char sequence + */ + public ContainsStringPredicate(CharSequence searchCharSequence){ + super(); + this.searchCharSequence = searchCharSequence; + } + + //--------------------------------------------------------------- + + /* + * (non-Javadoc) + * + * @see org.apache.commons.collections4.Predicate#evaluate(java.lang.Object) + */ + @Override + public boolean evaluate(String value){ + return StringUtils.contains(value, searchCharSequence); + } + + //--------------------------------------------------------------- + /** + * Gets the search char sequence. + * + * @return the searchCharSequence + */ + public CharSequence getSearchCharSequence(){ + return searchCharSequence; + } + + /** + * Sets the search char sequence. + * + * @param searchCharSequence + * the searchCharSequence to set + */ + public void setSearchCharSequence(CharSequence searchCharSequence){ + this.searchCharSequence = searchCharSequence; + } + +} diff --git a/src/test/java/com/feilong/core/util/predicate/ContainsStringPredicateParameterizedTest.java b/src/test/java/com/feilong/core/util/predicate/ContainsStringPredicateParameterizedTest.java new file mode 100644 index 00000000..b000a211 --- /dev/null +++ b/src/test/java/com/feilong/core/util/predicate/ContainsStringPredicateParameterizedTest.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2008 feilong + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.feilong.core.util.predicate; + +import static com.feilong.core.bean.ConvertUtil.toList; +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.junit.runners.Parameterized.Parameters; + +import com.feilong.test.AbstractTwoParamsAndOneResultParameterizedTest; + +/** + * + * @author feilong + * @since 1.14.3 + */ +public class ContainsStringPredicateParameterizedTest extends AbstractTwoParamsAndOneResultParameterizedTest{ + + @Parameters(name = "index:{index}: new ContainsStringPredicate({1}).evaluate({0})={2}") + public static Iterable data(){ + Object[][] objects = new Object[][] { // + { + "FTRADE_NOT_EXIST", + "TRADE_NOT_EXIST", + true }, + { "F", "TRADE_NOT_EXIST", false }, + { "", "TRADE_NOT_EXIST", false }, + { null, "TRADE_NOT_EXIST", false }, + // + }; + return toList(objects); + } + + @Test + public void test(){ + assertEquals(expectedValue, new ContainsStringPredicate(input2).evaluate(input1)); + } + +} diff --git a/src/test/java/com/feilong/core/util/predicate/FeiLongBeanPredicateUtilSuiteTests.java b/src/test/java/com/feilong/core/util/predicate/FeiLongBeanPredicateUtilSuiteTests.java index 1c8324c2..9a098d1c 100644 --- a/src/test/java/com/feilong/core/util/predicate/FeiLongBeanPredicateUtilSuiteTests.java +++ b/src/test/java/com/feilong/core/util/predicate/FeiLongBeanPredicateUtilSuiteTests.java @@ -42,6 +42,8 @@ EqualMapPredicateTest.class, EqualBeanPredicateTest.class, + ContainsStringPredicateParameterizedTest.class, + ComparatorPredicateComparatorTest.class, ComparatorPredicateTest.class, ContainsPredicateListTest.class,