List of usage examples for org.apache.commons.collections4 PredicateUtils notPredicate
public static <T> Predicate<T> notPredicate(final Predicate<? super T> predicate)
From source file:com.feilong.core.util.AggregateUtilTest.java
/** * Test sum3.// ww w . j a v a 2s.c o m */ @Test public void testSum3() { User liubei = new User(10L); liubei.setName(""); liubei.setAge(50); User guanyu = new User(20L); liubei.setName(""); guanyu.setAge(50); User zhangfei = new User(100L); zhangfei.setName(""); zhangfei.setAge(null); User zhaoyun = new User((Long) null); zhaoyun.setName(""); zhaoyun.setAge(100); List<User> list = toList(liubei, guanyu, zhangfei, zhaoyun); Predicate<User> notPredicate = PredicateUtils .notPredicate(BeanPredicateUtil.equalPredicate("name", "")); Map<String, BigDecimal> map = AggregateUtil.sum(list, toArray("id", "age"), notPredicate); assertThat(map, allOf(hasEntry("id", toBigDecimal(30)), hasEntry("age", toBigDecimal(200)))); }
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//from ww w.j a v a 2s .c o m .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); }