List of usage examples for org.apache.commons.collections CollectionUtils collect
public static Collection collect(Iterator inputIterator, Transformer transformer)
From source file:gov.nih.nci.caintegrator.studyQueryService.germline.ObjectQueryHandler.java
public Collection<Integer> getAgeUpperLimitValues(StudyCriteria studyCrit) { if (studyCrit == null || studyCrit.getId() == null) return new ArrayList<Integer>(); Long studyId = studyCrit.getId(); ageUpperLimits = new HashSet<Integer>(); Session session = getSessionFactory().getCurrentSession(); HashMap params = new HashMap(); String sql = " SELECT AGE_AT_ENROLL_MAX FROM ENROLL_AGE_LU WHERE STUDY_ID = :studyId "; params.put("studyId", studyId); SQLQuery q = session.createSQLQuery(sql); q.addScalar("AGE_AT_ENROLL_MAX", Hibernate.INTEGER); HQLHelper.setParamsOnQuery(params, q); Collection<BigDecimal> minValues = q.list(); Collection<Integer> intValues = CollectionUtils.collect(minValues, new IntegerTransformer()); ageUpperLimits.addAll(intValues);/*from w w w . j a va2 s . com*/ return ageUpperLimits; }
From source file:common.utils.ReflectionAssert.java
/** * Asserts that a property of all objects in the collection are equal to the given values. * <p/>//from w ww . ja va 2 s.com * Example: assertPropertyEquals("id", myIdCollection, myObjectCollection) checks whether all values of the * id field of the myObjectCollection elements matches the values in the myIdCollection * <p/> * Bean notation can be used to specify inner properties. Eg myArray[2].innerValue. * assertReflectionEquals is used to check whether both values are equal. * <p/> * The comparator modes determine how strict to compare the values. * * @param message a message for when the assertion fails * @param propertyName the property, not null * @param expectedPropertyValues the expected values, not null * @param actualObjects the objects that contain the property * @param modes the comparator modes * @throws AssertionFailedError when both objects are not equals */ public static void assertPropertyReflectionEquals(String message, String propertyName, Collection<?> expectedPropertyValues, Collection<?> actualObjects, ReflectionComparatorMode... modes) throws AssertionFailedError { assertNotNull("Actual object list is null.", actualObjects); Collection<?> actualPropertyValues = CollectionUtils.collect(actualObjects, new OgnlTransformer(propertyName)); assertReflectionEquals(message, expectedPropertyValues, actualPropertyValues, modes); }
From source file:mondrian.olap.IdBatchResolverTest.java
private Set<String> getResolvedNames(Map<QueryPart, QueryPart> resolvedIdents) { return new HashSet(CollectionUtils.collect(resolvedIdents.keySet(), new Transformer() { public Object transform(Object o) { return o.toString(); }//from w ww .j a v a 2s . c o m })); }
From source file:ar.com.zauber.commons.repository.query.visitor.CriteriaFilterVisitor.java
/** @see FilterVisitor#visitInPropertyFilter(InPropertyFilter) */ public final void visitInPropertyFilter(final InPropertyFilter inPropertyFilter) { String fieldName = getFieldName(inPropertyFilter.getProperty()); criterion = Restrictions.in(fieldName, CollectionUtils .collect(inPropertyFilter.getValues(), new BeanToPropertyValueTransformer("value")).toArray()); negateIfNeeded(inPropertyFilter);/* w w w . j a v a 2s . c om*/ }
From source file:com.square.core.dao.implementations.RessourceDaoImplementation.java
@SuppressWarnings("unchecked") @Override//from w w w .j a v a2s. co m public List<Long> rechercherFullTextIdsRessources(RessourceCriteresRechercheDto criteres) throws ParseException { // Si des critres ont t fournis on traite ces critres final BooleanQuery bq = new BooleanQuery(); if (criteres.getNom() != null && !("".equals(criteres.getNom()))) { final AnalysingCustomQueryParser parser = new AnalysingCustomQueryParser(getMatchingVersion(), FIELD_NOM, getAnalyser(Ressource.class)); parser.setAllowLeadingWildcard(true); final String nom = criteres.getNom().replaceAll(POURCENT, ETOILE); final org.apache.lucene.search.Query requeteLucene = parser .parse(nom.lastIndexOf(ETOILE) == nom.length() - 1 ? nom : nom + ETOILE); bq.add(requeteLucene, BooleanClause.Occur.MUST); } if (criteres.getPrenom() != null && !("".equals(criteres.getPrenom()))) { final AnalysingCustomQueryParser parser = new AnalysingCustomQueryParser(getMatchingVersion(), "prenom", getAnalyser(Ressource.class)); parser.setAllowLeadingWildcard(true); final String prenom = criteres.getPrenom().replaceAll(POURCENT, ETOILE); final org.apache.lucene.search.Query requeteLucene = parser .parse(prenom.lastIndexOf(ETOILE) == prenom.length() - 1 ? prenom : prenom + ETOILE); bq.add(requeteLucene, BooleanClause.Occur.MUST); } // Critre sur la liste des services if (criteres.getIdServices() != null && !criteres.getIdServices().isEmpty()) { final List<String> listeValeurs = (List<String>) CollectionUtils.collect(criteres.getIdServices(), StringValueTransformer.getInstance()); bq.add((Query) getInQuery("service.id", listeValeurs), BooleanClause.Occur.MUST); } // Critre sur la liste des fonctions if (criteres.getIdFonctions() != null && !criteres.getIdFonctions().isEmpty()) { final List<String> listeValeurs = (List<String>) CollectionUtils.collect(criteres.getIdFonctions(), StringValueTransformer.getInstance()); bq.add((Query) getInQuery("fonction.id", listeValeurs), BooleanClause.Occur.MUST); } // Critre sur la liste des etats if (criteres.getIdEtats() != null && !criteres.getIdEtats().isEmpty()) { final List<String> listeValeurs = (List<String>) CollectionUtils.collect(criteres.getIdEtats(), StringValueTransformer.getInstance()); bq.add((Query) getInQuery("etat.id", listeValeurs), BooleanClause.Occur.MUST); } // Critre sur la liste des agences if (criteres.getIdAgences() != null && !criteres.getIdAgences().isEmpty()) { final List<String> listeValeurs = (List<String>) CollectionUtils.collect(criteres.getIdAgences(), StringValueTransformer.getInstance()); bq.add((Query) getInQuery("agence.id", listeValeurs), BooleanClause.Occur.MUST); } // Critre sur la liste des identifiants extrieurs des fonctions if (criteres.getListeIdsExtsFonctions() != null && !criteres.getListeIdsExtsFonctions().isEmpty()) { final List<String> listeValeurs = (List<String>) CollectionUtils .collect(criteres.getListeIdsExtsFonctions(), StringValueTransformer.getInstance()); bq.add((Query) getInQuery("fonction.identifiantExterieur", listeValeurs), BooleanClause.Occur.SHOULD); } // PARAMETRE TOUJOURS VRAI POUR RECHERCHER SANS CRITERE if (criteres.getNom() == null || "".equals(criteres.getNom())) { final QueryParser parser = new QueryParser(getMatchingVersion(), FIELD_NOM, getAnalyser(PersonnePhysique.class)); parser.setAllowLeadingWildcard(true); final org.apache.lucene.search.Query requeteLucene = parser.parse("*"); bq.add(requeteLucene, BooleanClause.Occur.MUST); } // CONSTRUCTION DE LA REQUETE final FullTextQuery fullTextQuery = createFullTextQuery(bq, Ressource.class); fullTextQuery.setProjection("id"); final List<Object[]> listeResultats = (List<Object[]>) fullTextQuery.list(); // Mapping des rsultats final List<Long> resultats = new ArrayList<Long>(); for (Object[] resultat : listeResultats) { resultats.add((Long) resultat[0]); } return resultats; }
From source file:com.mulesoft.mule.cassandradb.CassandraDBUtils.java
/** * Utility method to convert a List of IndexExpression of type String to List of IndexExpression of type ByteBuffer. * * @param list List of IndexExpression./* www.ja v a 2 s . co m*/ * @return ByteBuffer type of IndexExpression List. */ @SuppressWarnings("unchecked") public static List<IndexExpression> toIndexExpression(List<IndexExpresion> list) { return (List<IndexExpression>) CollectionUtils.collect((List) list, new Transformer() { @Override public Object transform(Object input) { IndexExpresion sExp = (IndexExpresion) input; IndexExpression exp = new IndexExpression(); exp.setColumn_name(CassandraDBUtils.toByteBuffer(sExp.getColumnName())); exp.setOp(sExp.getOp()); exp.setValue(CassandraDBUtils.toByteBuffer(sExp.getValue())); return exp; } }); }
From source file:com.mulesoft.mule.cassandradb.CassandraDBUtils.java
/** * Utility method to convert a list of String into List of ColumnDefinition. * * @param list A collection of strings to be transformed. * @param keyspace Cassandra keyspace to be set. * @return the result as a list of CfDef. *//* w ww .ja va 2 s . co m*/ @SuppressWarnings("unchecked") public static List<CfDef> toColumnDefinition(List<String> list, final String keyspace) { return (List<CfDef>) CollectionUtils.collect((List) list, new Transformer() { @Override public Object transform(Object input) { String name = (String) input; CfDef cfDef = new CfDef(); cfDef.setKeyspace(keyspace); cfDef.setName(name); return cfDef; } }); }
From source file:net.sourceforge.fenixedu.domain.candidacyProcess.mobility.MobilityApplicationProcess.java
public List<Degree> getDegreesAssociatedToTeacherAsCoordinator(final Teacher teacher) { List<MobilityCoordinator> coordinators = getErasmusCoordinatorForTeacher(teacher); return new ArrayList<Degree>(CollectionUtils.collect(coordinators, new Transformer() { @Override//from w w w . java2 s . co m public Object transform(Object arg0) { return ((MobilityCoordinator) arg0).getDegree(); } })); }
From source file:com.redhat.rhn.frontend.xmlrpc.chain.ActionChainHandler.java
/** * Deploy configuration./*from ww w. j a va 2s . c om*/ * * @param loggedInUser The current user * @param chainLabel Label of the action chain * @param serverId System ID * @param revisions List of configuration revisions. * @return True in XML-RPC representation * * @xmlrpc.doc Adds an action to deploy a configuration file to an Action Chain. * @xmlrpc.param #param_desc("string", "sessionKey", "Session token, issued at login") * @xmlrpc.param #param_desc("string", "chainLabel", "Label of the chain") * @xmlrpc.param #param_desc("int", "System ID", "System ID") * @xmlrpc.param #array_single("int", "Revision ID") * @xmlrpc.returntype #return_int_success() */ @SuppressWarnings("unchecked") public Integer addConfigurationDeployment(User loggedInUser, String chainLabel, Integer serverId, List<Integer> revisions) { if (revisions.isEmpty()) { throw new InvalidParameterException("At least one revision should be given."); } List<Long> server = new ArrayList<Long>(); server.add(serverId.longValue()); ActionChainManager.createConfigActions(loggedInUser, CollectionUtils.collect(revisions, new ActionChainRPCCommon.IntegerToLongTransformer()), server, ActionFactory.TYPE_CONFIGFILES_DEPLOY, new Date(), this.acUtil.getActionChainByLabel(loggedInUser, chainLabel)); return BaseHandler.VALID; }
From source file:com.jaspersoft.jasperserver.remote.services.impl.BatchRepositoryServicePeganatedSearchTest.java
private void assertResult(final List<ClientResourceLookup> result, final String... resourceLabels) { assertEquals(result.size(), resourceLabels.length); Collection<String> resultColl = CollectionUtils.collect(result, new Transformer() { @Override//from w ww .j a va 2 s . c o m public String transform(Object input) { final ClientResourceLookup entity = (ClientResourceLookup) input; return entity.getLabel(); } }); String[] resultAsArray = Arrays.copyOf(resultColl.toArray(new String[resultColl.size()]), resultColl.size()); assertEquals(resultAsArray, resourceLabels); }