Java Code Examples for org.apache.commons.collections4.PredicateUtils#equalPredicate()

The following examples show how to use org.apache.commons.collections4.PredicateUtils#equalPredicate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BeanPredicateTest.java    From feilong-core with Apache License 2.0 5 votes vote down vote up
/**
 * Test.
 */
@Test
public void test(){
    User user = new User("feilong");

    Predicate<User> predicate = new BeanPredicate<>("name", PredicateUtils.equalPredicate("feilong"));

    assertTrue(predicate.evaluate(user));
}
 
Example 2
Source File: EnumUtilsTest.java    From WiFiAnalyzer with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testFindUsingPredicate() {
    // 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);
}
 
Example 3
Source File: BeanPredicateUtil.java    From feilong-core with Apache License 2.0 2 votes vote down vote up
/**
 * 用来指定 <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));
}