Example usage for org.apache.commons.collections4 PredicateUtils equalPredicate

List of usage examples for org.apache.commons.collections4 PredicateUtils equalPredicate

Introduction

In this page you can find the example usage for org.apache.commons.collections4 PredicateUtils equalPredicate.

Prototype

public static <T> Predicate<T> equalPredicate(final T value) 

Source Link

Document

Creates a Predicate that checks if the input object is equal to the specified object using equals().

Usage

From source file:com.feilong.core.util.predicate.BeanPredicateUtil.java

/**
 * Equal predicate.//w  w w . ja va2  s  . c om
 * 
 * <p>
 * ? <code>T</code>   <code>propertyName</code> equals  propertyValue
 * </p>
 * 
 * @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) {
    return new BeanPredicate<T>(propertyName, PredicateUtils.equalPredicate(propertyValue));
}

From source file:com.vrem.util.EnumUtilsTest.java

@Test
public void testFindUsingPredicate() throws Exception {
    // setup//w  ww.  j av  a  2 s . com
    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);
}

From source file:org.apache.syncope.core.misc.security.SyncopeUserDetailsService.java

@Override
public UserDetails loadUserByUsername(final String username) {
    final Set<SyncopeGrantedAuthority> authorities = new HashSet<>();
    if (anonymousUser.equals(username)) {
        authorities.add(new SyncopeGrantedAuthority(Entitlement.ANONYMOUS));
    } else if (adminUser.equals(username)) {
        CollectionUtils/*w w w  .  ja  va  2  s. c  om*/
                .collect(
                        IteratorUtils.filteredIterator(Entitlement.values().iterator(),
                                PredicateUtils
                                        .notPredicate(PredicateUtils.equalPredicate(Entitlement.ANONYMOUS))),
                        new Transformer<String, SyncopeGrantedAuthority>() {

                            @Override
                            public SyncopeGrantedAuthority transform(final String entitlement) {
                                return new SyncopeGrantedAuthority(entitlement, SyncopeConstants.ROOT_REALM);
                            }
                        }, authorities);
    } else {
        org.apache.syncope.core.persistence.api.entity.user.User user = userDAO.find(username);
        if (user == null) {
            throw new UsernameNotFoundException("Could not find any user with id " + username);
        }

        // Give entitlements as assigned by roles (with realms, where applicable) - assigned either
        // statically and dynamically
        for (final Role role : userDAO.findAllRoles(user)) {
            CollectionUtils.forAllDo(role.getEntitlements(), new Closure<String>() {

                @Override
                public void execute(final String entitlement) {
                    SyncopeGrantedAuthority authority = new SyncopeGrantedAuthority(entitlement);
                    authorities.add(authority);

                    List<String> realmFullPahs = new ArrayList<>();
                    CollectionUtils.collect(role.getRealms(), new Transformer<Realm, String>() {

                        @Override
                        public String transform(final Realm realm) {
                            return realm.getFullPath();
                        }
                    }, realmFullPahs);
                    authority.addRealms(realmFullPahs);
                }
            });
        }

        // Give group entitlements for owned groups
        for (Group group : groupDAO.findOwnedByUser(user.getKey())) {
            for (String entitlement : Arrays.asList(Entitlement.GROUP_READ, Entitlement.GROUP_UPDATE,
                    Entitlement.GROUP_DELETE)) {

                SyncopeGrantedAuthority authority = new SyncopeGrantedAuthority(entitlement);
                authority.addRealm(
                        RealmUtils.getGroupOwnerRealm(group.getRealm().getFullPath(), group.getKey()));
                authorities.add(authority);
            }
        }
    }

    return new User(username, "<PASSWORD_PLACEHOLDER>", authorities);
}

From source file:org.apache.syncope.core.persistence.api.dao.AllowedSchemas.java

public boolean forMembershipsContains(final Group group, final S schema) {
    return IterableUtils.matchesAny(forMemberships.get(group), PredicateUtils.equalPredicate(schema));
}