本文整理汇总了Java中org.apache.commons.collections4.PredicateUtils.equalPredicate方法的典型用法代码示例。如果您正苦于以下问题:Java PredicateUtils.equalPredicate方法的具体用法?Java PredicateUtils.equalPredicate怎么用?Java PredicateUtils.equalPredicate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.collections4.PredicateUtils
的用法示例。
在下文中一共展示了PredicateUtils.equalPredicate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test
import org.apache.commons.collections4.PredicateUtils; //导入方法依赖的package包/类
@Test
public void test(){
User user = new User("feilong");
Predicate<User> predicate = new BeanPredicate<>("name", PredicateUtils.equalPredicate("feilong"));
assertTrue(predicate.evaluate(user));
}
示例2: testFindUsingPredicate
import org.apache.commons.collections4.PredicateUtils; //导入方法依赖的package包/类
@Test
public void testFindUsingPredicate() throws Exception {
// setup
final TestObject expected = TestObject.VALUE3;
Predicate<TestObject> predicate = PredicateUtils.equalPredicate(expected);
// execute
TestObject actual = EnumUtils.find(TestObject.class, predicate, TestObject.VALUE2);
// validate
assertEquals(expected, actual);
}
示例3: equalPredicate
import org.apache.commons.collections4.PredicateUtils; //导入方法依赖的package包/类
/**
* 用来指定 <code>T</code> 对象的特定属性 <code>propertyName</code> equals 指定的 <code>propertyValue</code>.
*
* <h3>说明:</h3>
* <blockquote>
* <ol>
* <li>
* 常用于解析集合,如 {@link CollectionsUtil#select(Iterable, Predicate) select},{@link CollectionsUtil#find(Iterable, Predicate) find},
* {@link CollectionsUtil#selectRejected(Iterable, Predicate) selectRejected},
* {@link CollectionsUtil#group(Iterable, String, Predicate) group},
* {@link AggregateUtil#groupCount(Iterable, String, Predicate) groupCount},
* {@link AggregateUtil#sum(Iterable, String, Predicate) sum} 等方法.
* </li>
* </ol>
* </blockquote>
*
* <h3>示例:</h3>
*
* <blockquote>
*
* <p>
* <b>场景:</b> 在list中查找 名字是 关羽,并且 年龄是30 的user
* </p>
*
* <pre class="code">
*
* User guanyu30 = new User("关羽", 30);
* List{@code <User>} list = toList(//
* new User("张飞", 23),
* new User("关羽", 24),
* new User("刘备", 25),
* guanyu30);
*
* Predicate{@code <User>} predicate = PredicateUtils
* .andPredicate(BeanPredicateUtil.equalPredicate("name", "关羽"), BeanPredicateUtil.equalPredicate("age", 30));
*
* assertEquals(guanyu30, CollectionsUtil.find(list, predicate));
*
* </pre>
*
* </blockquote>
*
* @param <T>
* the generic type
* @param <V>
* the value type
* @param propertyName
* 泛型T对象指定的属性名称,Possibly indexed and/or nested name of the property to be modified,参见
* <a href="../../bean/BeanUtil.html#propertyName">propertyName</a>
* @param propertyValue
* the property value
* @return 如果 <code>propertyName</code> 是null,抛出 {@link NullPointerException}<br>
* 如果 <code>propertyName</code> 是blank,抛出 {@link IllegalArgumentException}<br>
* @see org.apache.commons.collections4.PredicateUtils#equalPredicate(Object)
*/
public static <T, V> Predicate<T> equalPredicate(String propertyName,V propertyValue){
Validate.notBlank(propertyName, "propertyName can't be blank!");
return new BeanPredicate<>(propertyName, PredicateUtils.equalPredicate(propertyValue));
}