Skip to content
This repository has been archived by the owner on Aug 20, 2021. It is now read-only.

Commit

Permalink
新建 ContainsStringPredicate fix #791
Browse files Browse the repository at this point in the history
  • Loading branch information
venusdrogon committed Aug 25, 2019
1 parent 8d0f96e commit 4c7d96e
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.feilong.platform</groupId>
<artifactId>parent</artifactId>
<version>1.14.2</version>
<version>1.14.3</version>
</parent>

<artifactId>feilong-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <a href="http://feitianbenyue.iteye.com/">feilong</a>
* @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;
}

}
Original file line number Diff line number Diff line change
@@ -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 <a href="http://feitianbenyue.iteye.com/">feilong</a>
* @since 1.14.3
*/
public class ContainsStringPredicateParameterizedTest extends AbstractTwoParamsAndOneResultParameterizedTest<String, String, Boolean>{

@Parameters(name = "index:{index}: new ContainsStringPredicate({1}).evaluate({0})={2}")
public static Iterable<Object[]> data(){
Object[][] objects = new Object[][] { //
{
"<alipay><is_success>F</is_success><error>TRADE_NOT_EXIST</error></alipay>",
"TRADE_NOT_EXIST",
true },
{ "<alipay><is_success>F</is_success><error></error></alipay>", "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));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
EqualMapPredicateTest.class,
EqualBeanPredicateTest.class,

ContainsStringPredicateParameterizedTest.class,

ComparatorPredicateComparatorTest.class,
ComparatorPredicateTest.class,
ContainsPredicateListTest.class,
Expand Down

0 comments on commit 4c7d96e

Please sign in to comment.