List of usage examples for org.apache.commons.collections Transformer Transformer
Transformer
From source file:de.tudarmstadt.lt.lm.mapbased.CountingLM.java
@Override public Iterator<List<W>> getNgramIterator() { @SuppressWarnings("unchecked") Iterator<List<W>> iter = IteratorUtils.transformedIterator(getNgramIdIterator(), new Transformer() { @Override//from w w w . j a va2 s.c om public Object transform(final Object o) { List<Integer> ngram = (List<Integer>) o; return toWordList(ngram); } }); return iter; }
From source file:fr.itldev.koya.alfservice.DossierService.java
/** * * @param parent//w w w . ja va2 s.com * @return * @throws KoyaServiceException */ public List<Dossier> list(NodeRef parent) throws KoyaServiceException { if (!nodeService.getType(parent).equals(KoyaModel.TYPE_SPACE)) { throw new KoyaServiceException(KoyaErrorCodes.DOSSIER_INVALID_PARENT_NODE); } List nodes = nodeService.getChildAssocs(parent, new HashSet<QName>() { { add(KoyaModel.TYPE_DOSSIER); } }); /** * transform List<ChildAssociationRef> to List<Dossier> */ CollectionUtils.transform(nodes, new Transformer() { @Override public Object transform(Object input) { try { return koyaNodeService.getSecuredItem(((ChildAssociationRef) input).getChildRef(), Dossier.class); } catch (KoyaServiceException ex) { return null; } } }); return nodes; }
From source file:com.alkacon.opencms.survey.CmsFormReportingBean.java
/** * Returns a lazy initialized map that provides the label and database label for each value used as a key in the Map.<p> * /*from ww w. ja v a 2s. co m*/ * @return a lazy initialized map */ public Map getLabeling() { if (m_label == null) { m_label = LazyMap.decorate(new HashMap(), new Transformer() { /** * @see org.apache.commons.collections.Transformer#transform(java.lang.Object) */ public Object transform(Object input) { String value = String.valueOf(input); String[] result = new String[] { value, value }; if (!CmsStringUtil.isEmpty(value)) { String[] array = CmsStringUtil.splitAsArray(value, '|'); if (array.length > 1) { result = array; } } return result; } }); } return m_label; }
From source file:net.sourceforge.fenixedu.presentationTier.Action.academicAdministration.executionCourseManagement.InsertExecutionCourseDispatchAction.java
@EntryPoint public ActionForward prepareInsertExecutionCourse(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { List infoExecutionPeriods = null; infoExecutionPeriods = ReadExecutionPeriods.run(); if (infoExecutionPeriods != null && !infoExecutionPeriods.isEmpty()) { // exclude closed execution periods infoExecutionPeriods = (List) CollectionUtils.select(infoExecutionPeriods, new Predicate() { @Override/* w w w . j a v a 2 s.c om*/ public boolean evaluate(Object input) { InfoExecutionPeriod infoExecutionPeriod = (InfoExecutionPeriod) input; if (!infoExecutionPeriod.getState().equals(PeriodState.CLOSED)) { return true; } return false; } }); ComparatorChain comparator = new ComparatorChain(); comparator.addComparator(new BeanComparator("infoExecutionYear.year"), true); comparator.addComparator(new BeanComparator("name"), true); Collections.sort(infoExecutionPeriods, comparator); List<LabelValueBean> executionPeriodLabels = new ArrayList<LabelValueBean>(); CollectionUtils.collect(infoExecutionPeriods, new Transformer() { @Override public Object transform(Object arg0) { InfoExecutionPeriod infoExecutionPeriod = (InfoExecutionPeriod) arg0; LabelValueBean executionPeriod = new LabelValueBean( infoExecutionPeriod.getName() + " - " + infoExecutionPeriod.getInfoExecutionYear().getYear(), infoExecutionPeriod.getExternalId().toString()); return executionPeriod; } }, executionPeriodLabels); request.setAttribute(PresentationConstants.LIST_EXECUTION_PERIODS, executionPeriodLabels); List<LabelValueBean> entryPhases = new ArrayList<LabelValueBean>(); for (EntryPhase entryPhase : EntryPhase.values()) { LabelValueBean labelValueBean = new LabelValueBean(entryPhase.getLocalizedName(), entryPhase.getName()); entryPhases.add(labelValueBean); } request.setAttribute("entryPhases", entryPhases); } return mapping.findForward("insertExecutionCourse"); }
From source file:com.projity.util.DataUtils.java
public static String stringListWithMaxAndMessage(Collection collection, int maxInList, String message) { return StringList.listWithMaxAndMessage(collection, maxInList, message, new Transformer() { public Object transform(Object arg0) { return "" + ((HasKey) arg0).getId(); }/*from ww w.jav a2s .c o m*/ }); }
From source file:com.abiquo.server.core.cloud.VirtualApplianceDAO.java
@SuppressWarnings("unchecked") private static Collection<Integer> availableVdsToUser(final User user) { Collection<String> idsStrings = Arrays.asList(user.getAvailableVirtualDatacenters().split(",")); return CollectionUtils.collect(idsStrings, new Transformer() { @Override//from w w w.j a v a 2 s. c o m public Object transform(final Object input) { return Integer.valueOf(input.toString()); } }); }
From source file:com.epam.cme.core.services.impl.DefaultCompatibilityServiceIntegrationTest.java
protected void assertCompatibileListIsCorrect(final List<? extends ProductModel> returnedProducts, final Set<String> expectedCodes) { Assert.assertEquals(expectedCodes.size(), returnedProducts.size()); final List<String> returnedCodes = (List<String>) CollectionUtils.collect(returnedProducts, new Transformer() { @Override// w w w . j av a2 s . c o m public Object transform(final Object product) { final String productCode = ((ProductModel) product).getCode(); return productCode; } }); Assert.assertTrue(CollectionUtils.isEqualCollection(expectedCodes, returnedCodes)); }
From source file:com.amalto.core.storage.StagingStorage.java
@Override public void update(Iterable<DataRecord> records) { final TransformIterator iterator = new TransformIterator(records.iterator(), new Transformer() { @Override/*from ww w . j av a2s . c o m*/ public Object transform(Object input) { DataRecord dataRecord = (DataRecord) input; DataRecordMetadata metadata = dataRecord.getRecordMetadata(); Map<String, String> recordProperties = metadata.getRecordProperties(); // Update on a record in staging reset all its match&merge information. String status = recordProperties.get(METADATA_STAGING_STATUS); StagingUpdateAction updateAction = updateActions.get(status); if (updateAction == null) { // Try to re-read status from database if (status == null) { UserQueryBuilder readStatus = from(dataRecord.getType()); for (FieldMetadata keyField : dataRecord.getType().getKeyFields()) { readStatus.where(eq(keyField, StorageMetadataUtils.toString(dataRecord.get(keyField), keyField))); } StorageResults refreshedRecord = delegate.fetch(readStatus.getSelect()); for (DataRecord record : refreshedRecord) { Map<String, String> refreshedProperties = record.getRecordMetadata() .getRecordProperties(); updateAction = updateActions.get(refreshedProperties.get(METADATA_STAGING_STATUS)); } } // Database doesn't have any satisfying update action if (updateAction == null) { updateAction = defaultUpdateAction; // Covers cases where update action isn't specified. } } recordProperties.put(Storage.METADATA_STAGING_STATUS, updateAction.value()); recordProperties.put(Storage.METADATA_STAGING_ERROR, StringUtils.EMPTY); if (updateAction.resetTaskId()) { metadata.setTaskId(null); } return dataRecord; } }); Iterable<DataRecord> transformedRecords = new Iterable<DataRecord>() { @Override public Iterator<DataRecord> iterator() { return iterator; } }; delegate.update(transformedRecords); }
From source file:net.sourceforge.fenixedu.applicationTier.Servico.teacher.onlineTests.ReadDistributedTestMarksToString.java
protected String run(String executionCourseId, String[] distributedTestCodes) throws FenixServiceException { StringBuilder result = new StringBuilder(); result.append(BundleUtil.getString(Bundle.APPLICATION, "label.username")).append("\t"); result.append(BundleUtil.getString(Bundle.APPLICATION, "label.number")).append("\t"); result.append(BundleUtil.getString(Bundle.APPLICATION, "label.name")).append("\t"); ExecutionCourse executionCourse = FenixFramework.getDomainObject(executionCourseId); List<Registration> studentsFromAttendsList = (List) CollectionUtils.collect(executionCourse.getAttendsSet(), new Transformer() { @Override//from www . j a va2 s . c om public Object transform(Object input) { return ((Attends) input).getRegistration(); } }); final Set<Registration> students = new HashSet<Registration>(); for (final String distributedTestCode : distributedTestCodes) { final DistributedTest distributedTest = FenixFramework.getDomainObject(distributedTestCode); students.addAll(distributedTest.findStudents()); } List<Registration> studentList = concatStudentsLists(studentsFromAttendsList, students); Double[] maxValues = new Double[distributedTestCodes.length]; for (int i = 0; i < distributedTestCodes.length; i++) { DistributedTest distributedTest = FenixFramework.getDomainObject(distributedTestCodes[i]); if (distributedTest == null) { throw new InvalidArgumentsServiceException(); } maxValues[i] = distributedTest.calculateMaximumDistributedTestMark(); result.append(distributedTest.getTitle()); result.append("\t"); if (maxValues[i].doubleValue() > 0) { result.append("%\t"); } } for (Registration registration : studentList) { result.append("\n"); result.append(registration.getPerson().getUsername()); result.append("\t"); result.append(registration.getNumber()); result.append("\t"); result.append(registration.getPerson().getName()); result.append("\t"); for (int i = 0; i < distributedTestCodes.length; i++) { Double finalMark = new Double(0); DecimalFormat df = new DecimalFormat("#0.##"); DecimalFormat percentageFormat = new DecimalFormat("#%"); final DistributedTest distributedTest = FenixFramework.getDomainObject(distributedTestCodes[i]); finalMark = distributedTest.calculateTestFinalMarkForStudent(registration); if (finalMark == null) { result.append("NA\t"); if (maxValues[i].doubleValue() > 0) { result.append("NA\t"); } } else { if (finalMark.doubleValue() < 0) { result.append("0\t"); } else { result.append(df.format(finalMark.doubleValue())); result.append("\t"); } if (maxValues[i].doubleValue() > 0) { double finalMarkPercentage = finalMark.doubleValue() * java.lang.Math.pow(maxValues[i].doubleValue(), -1); if (finalMarkPercentage < 0) { result.append("0%\t"); } else { result.append(percentageFormat.format(finalMarkPercentage)); result.append("\t"); } } } } } return result.toString(); }
From source file:de.tudarmstadt.lt.lm.mapbased.CountingLM.java
@Override public Iterator<List<Integer>> getNgramIdIterator() { @SuppressWarnings("unchecked") Iterator<List<Integer>> iter = IteratorUtils.transformedIterator(_ngrams_of_order.entrySet().iterator(), new Transformer() { @Override//from w w w . ja va 2s . c o m public Object transform(final Object o) { Entry<List<Integer>, Integer> ngram_counts = (Entry<List<Integer>, Integer>) o; return ngram_counts.getKey(); } }); return iter; }