List of usage examples for org.apache.commons.collections4 Predicate Predicate
Predicate
From source file:com.wiiyaya.provider.main.service.impl.ResourceServiceImpl.java
@Override @Transactional(rollbackFor = BusinessException.class) public void updateResourceContent(ResourceDto resourceDto) throws BusinessException { Resource resourceDb = resourceDao.findOne(resourceDto.getId()); if (resourceDb == null) { throw new BusinessException(MainConstant.ERROR_RESOURCE_NOT_FOUND); }/*from w ww .j av a 2s . co m*/ resourceDb.setVersion(resourceDto.getVersion()); if (CollectionUtils.isNotEmpty(resourceDto.getContentIds())) { for (Iterator<Resource> itDb = resourceDb.getContents().iterator(); itDb.hasNext();) { final Resource contentDb = itDb.next(); boolean existInPage = IterableUtils.matchesAny(resourceDto.getContentIds(), new Predicate<Long>() { @Override public boolean evaluate(Long object) { return contentDb.getId().equals(object); } }); if (!existInPage) { itDb.remove(); } } resourceDb.getContents().addAll(resourceDao.findAll(resourceDto.getContentIds())); } else { resourceDb.getContents().clear(); } resourceDao.save(resourceDb); }
From source file:it.infn.ct.futuregateway.apiserver.resources.Task.java
/** * Retrieves the associated infrastructure Id. * This is the infrastructure selected to execute the task among * the many the application can run on./*from w ww. ja v a 2 s . c om*/ * * @return The infrastructure */ @Transient public Infrastructure getAssociatedInfrastructure() { if (applicationDetail == null) { return null; } return IterableUtils.find(applicationDetail.getInfrastructures(), new Predicate<Infrastructure>() { @Override public boolean evaluate(final Infrastructure t) { return t.getId().equals(getAssociatedInfrastructureId()); } }); }
From source file:it.infn.ct.futuregateway.apiserver.resources.Task.java
/** * Retrieves the associated infrastructure Id. * This is the Id of the infrastructure selected to execute the task among * the many the application can run on.//from w w w. j av a2 s . com * * @return The infrastructure Id */ public String getAssociatedInfrastructureId() { if ((associatedInfrastructureId == null || associatedInfrastructureId.isEmpty()) && applicationDetail != null) { List<Infrastructure> infras = ListUtils.select(applicationDetail.getInfrastructures(), new Predicate<Infrastructure>() { @Override public boolean evaluate(final Infrastructure t) { return t.isEnabled(); } }); Random rand = new Random((new Date()).getTime()); while (!infras.isEmpty()) { Infrastructure i = infras.remove(rand.nextInt(infras.size())); if (i.isEnabled()) { setAssociatedInfrastructureId(i.getId()); return associatedInfrastructureId; } } } return associatedInfrastructureId; }
From source file:it.infn.ct.futuregateway.apiserver.resources.Task.java
/** * Update the status of input files.//from w ww. j a v a 2 s. co m * Change the status value for the input file specified. If the name is not * associated with any input file nothing happen. * <p> * There is not check on the file existence and real status which * is delegated to the caller object. * * @param name File name * @param aStatus New status */ public final void updateInputFileStatus(final String name, final TaskFile.FILESTATUS aStatus) { TaskFileInput tfi = IterableUtils.find(inputFiles, new Predicate<TaskFileInput>() { @Override public boolean evaluate(final TaskFileInput t) { return t.getName().equals(name); } }); if (tfi != null) { tfi.setStatus(aStatus); lastChange = new Date(); setChanged(); notifyObservers(); } }
From source file:com.smartmarmot.dbforbix.config.Config.java
/** * @return a list of all VALID zabbix server configurations *///from w w w . j ava2s .c o m public Collection<ZabbixServer> getZabbixServers() { Collection<ZabbixServer> validServers = _zabbixServers; CollectionUtils.filter(validServers, new Predicate<ZabbixServer>() { @Override public boolean evaluate(ZabbixServer object) { return ((ZabbixServer) object).isValid(); } }); return validServers; }
From source file:com.smartmarmot.dbforbix.config.Config.java
/** * @return a list of all VALID database configurations *///w w w .ja va 2 s.com public Collection<Database> getDatabases() { Collection<Database> validDatabases = databases; CollectionUtils.filter(validDatabases, new Predicate<Database>() { @Override public boolean evaluate(Database object) { return ((Database) object).isValid(); } }); return validDatabases; }
From source file:net.tirasa.blog.ilgrosso.syncopecustompolicyrules.sample.App.java
public static void main(final String[] args) { // 1. configure the custom account rule and create an account policy using it CustomAccountRuleConf customAccountRuleConf = new CustomAccountRuleConf(); customAccountRuleConf.setRequiredSubString(ACCOUNT_REQUIRED_SUBSTRING); AccountPolicyTO accountPolicy = new AccountPolicyTO(); accountPolicy.setDescription("Account Policy with custom rules"); accountPolicy.getRuleConfs().add(customAccountRuleConf); accountPolicy = createPolicy(accountPolicy); // 2. create a password policy using a custom password rule with no configuration options PasswordPolicyTO passwordPolicy = new PasswordPolicyTO(); passwordPolicy.setDescription("Password Policy with custom rules"); passwordPolicy.getRuleConfs().add(new CustomPasswordRuleConf()); passwordPolicy = createPolicy(passwordPolicy); // 3. set the account and password policies above for root realm List<RealmTO> realms = client.getService(RealmService.class).list(); RealmTO rootRealm = CollectionUtils.find(realms, new Predicate<RealmTO>() { @Override/*from www. ja va 2 s . c om*/ public boolean evaluate(final RealmTO realm) { return SyncopeConstants.ROOT_REALM.equals(realm.getFullPath()); } }); rootRealm.setAccountPolicy(accountPolicy.getKey()); rootRealm.setPasswordPolicy(passwordPolicy.getKey()); client.getService(RealmService.class).update(rootRealm); // 4. obtain sample user: should fail both account and password policy verification UserTO userTO = getSampleTO("sample@tirasa.net"); // 5. attempt to create user -> password policy fails because it has the same value as security answer try { client.getService(UserService.class).create(userTO); fail(); } catch (SyncopeClientException e) { assertEquals(ClientExceptionType.InvalidUser, e.getType()); assertTrue(e.getElements().iterator().next().startsWith("InvalidPassword")); } // 6. change security answer to comply with password policy userTO.setSecurityAnswer("another value"); // 7. attempt to create user -> account policy fails because username doesn't contain ACCOUNT_REQUIRED_SUBSTRING try { client.getService(UserService.class).create(userTO); fail(); } catch (SyncopeClientException e) { assertEquals(ClientExceptionType.InvalidUser, e.getType()); assertTrue(e.getElements().iterator().next().startsWith("InvalidUsername")); } // 8. change username to comply with account policy userTO.setUsername("pre" + ACCOUNT_REQUIRED_SUBSTRING + "post"); // 9. finally succeed :-) client.getService(UserService.class).create(userTO); }
From source file:org.apache.bcel.BCELBenchmark.java
private Iterable<JarEntry> getClasses(JarFile jar) { return new IteratorIterable<>( new FilterIterator<>(new EnumerationIterator<>(jar.entries()), new Predicate<JarEntry>() { @Override//from w w w.j av a 2 s . c om public boolean evaluate(JarEntry entry) { return entry.getName().endsWith(".class"); } })); }
From source file:org.apache.openmeetings.db.dao.label.LabelDao.java
private static List<StringLabel> getLabels(Locale l, final String search) { if (!labelCache.containsKey(l)) { List<StringLabel> ll = getLabels(l); if (ll != null) { labelCache.putIfAbsent(l, ll); }/*w w w .ja v a 2s . c om*/ } List<StringLabel> result = new ArrayList<>( labelCache.containsKey(l) ? labelCache.get(l) : new ArrayList<StringLabel>()); if (!Strings.isEmpty(search)) { CollectionUtils.filter(result, new Predicate<StringLabel>() { @Override public boolean evaluate(StringLabel o) { return o != null && (o.getKey().contains(search) || o.getValue().contains(search)); } }); } return result; }
From source file:org.apache.syncope.client.console.panels.ConnectorDetailsPanel.java
private List<String> getVersions(final ConnInstanceTO connInstanceTO, final List<ConnBundleTO> bundles) { return new ArrayList<>( CollectionUtils.collect(CollectionUtils.select(bundles, new Predicate<ConnBundleTO>() { @Override/*from w w w. j a v a 2s. c o m*/ public boolean evaluate(final ConnBundleTO object) { return object.getLocation().equals(connInstanceTO.getLocation()) && object.getBundleName().equals(connInstanceTO.getBundleName()); } }), new Transformer<ConnBundleTO, String>() { @Override public String transform(final ConnBundleTO input) { return input.getVersion(); } }, new HashSet<String>())); }