Example usage for org.apache.commons.collections CollectionUtils collect

List of usage examples for org.apache.commons.collections CollectionUtils collect

Introduction

In this page you can find the example usage for org.apache.commons.collections CollectionUtils collect.

Prototype

public static Collection collect(Iterator inputIterator, Transformer transformer) 

Source Link

Document

Transforms all elements from the inputIterator with the given transformer and adds them to the outputCollection.

Usage

From source file:com.texeltek.accumulocloudbaseshim.ByteSequenceShim.java

@SuppressWarnings("unchecked")
public static Collection<cloudbase.core.data.ByteSequence> cloudbaseCollection(
        Collection<ByteSequence> byteSequenceCollection) {
    return CollectionUtils.collect(byteSequenceCollection, new Transformer() {
        @Override//from  w  ww . ja  va2 s  .c  o m
        public Object transform(Object o) {
            return ((ByteSequence) o).impl;
        }
    });
}

From source file:net.sourceforge.fenixedu.applicationTier.Servico.degree.execution.ReadExecutionCoursesByExecutionDegreeService.java

@Atomic
public static List run(String executionDegreeId, String executionPeriodId) throws FenixServiceException {

    final ExecutionSemester executionSemester;
    if (StringUtils.isEmpty(executionPeriodId)) {
        executionSemester = ExecutionSemester.readActualExecutionSemester();
    } else {//from w  w  w .j  a  va 2 s . c om
        executionSemester = FenixFramework.getDomainObject(executionPeriodId);
    }

    final ExecutionDegree executionDegree = FenixFramework.getDomainObject(executionDegreeId);
    if (executionDegree == null) {
        throw new NonExistingExecutionDegree();
    }

    Set<ExecutionCourse> executionCourseList = executionDegree.getDegreeCurricularPlan()
            .getExecutionCoursesByExecutionPeriod(executionSemester);

    List infoExecutionCourseList = (List) CollectionUtils.collect(executionCourseList, new Transformer() {

        @Override
        public Object transform(Object input) {
            ExecutionCourse executionCourse = (ExecutionCourse) input;
            InfoExecutionCourse infoExecutionCourse = InfoExecutionCourse.newInfoFromDomain(executionCourse);
            return infoExecutionCourse;
        }
    });

    return infoExecutionCourseList;

}

From source file:net.sf.wickedshell.action.batch.SelectBatchFileAction.java

/**
 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
 *//* w ww. j  a v a2 s.  c om*/
@SuppressWarnings("unchecked")
public void run(IAction action) {
    FileDialog fileDialog = new FileDialog(view.getSite().getShell(), SWT.OPEN);
    fileDialog.setText("Select existing Batch File for Batch View");

    List executableFiles = ShellViewUtil.getTargetableExecutableFiles();
    String[] batchFileExtensions = (String[]) CollectionUtils.collect(executableFiles, new Transformer() {
        /**
         * @see org.apache.commons.collections.Transformer#transform(java.lang.Object)
         */
        public Object transform(Object object) {
            IExecutableFile executableFile = (IExecutableFile) object;
            StringBuffer buffer = new StringBuffer();
            buffer.append("*");
            buffer.append(executableFile.getExtension());
            return buffer.toString();
        }
    }).toArray(new String[0]);

    String[] batchFileDescriptions = (String[]) CollectionUtils.collect(executableFiles, new Transformer() {
        public Object transform(Object object) {
            IExecutableFile executableFile = (IExecutableFile) object;
            StringBuffer buffer = new StringBuffer();
            buffer.append(executableFile.getDescription());
            buffer.append(" (*");
            buffer.append(executableFile.getExtension());
            buffer.append(")");
            return buffer.toString();
        }
    }).toArray(new String[0]);

    fileDialog.setFilterExtensions(batchFileExtensions);
    fileDialog.setFilterNames(batchFileDescriptions);

    String selectedBatch = fileDialog.open();
    if (selectedBatch != null) {
        BatchView batchView = (BatchView) view;
        batchView.getBatchManager()
                .addBatchFileDescriptor(IBatchFileDescriptor.Factory.newInstance(selectedBatch));
    }
}

From source file:net.sourceforge.fenixedu.applicationTier.Servico.commons.ReadActiveDegreeCurricularPlansByDegreeType.java

private static Collection<InfoDegreeCurricularPlan> getActiveDegreeCurricularPlansByDegreeType(
        final DegreeType degreeType, AccessControlPredicate<Object> permission) {
    List<DegreeCurricularPlan> degreeCurricularPlans = new ArrayList<DegreeCurricularPlan>();
    for (DegreeCurricularPlan dcp : DegreeCurricularPlan.readByDegreeTypeAndState(degreeType,
            DegreeCurricularPlanState.ACTIVE)) {
        if (permission != null) {
            if (!permission.evaluate(dcp.getDegree())) {
                continue;
            }//from  w  w w.ja  v  a  2  s  .c  o m
        }
        degreeCurricularPlans.add(dcp);
    }

    return CollectionUtils.collect(degreeCurricularPlans, new Transformer() {

        @Override
        public Object transform(Object arg0) {
            DegreeCurricularPlan degreeCurricularPlan = (DegreeCurricularPlan) arg0;
            return InfoDegreeCurricularPlan.newInfoFromDomain(degreeCurricularPlan);
        }

    });
}

From source file:net.sourceforge.fenixedu.dataTransferObject.InfoExamWithRoomOccupationsAndScopesWithCurricularCoursesWithDegreeAndSemesterAndYear.java

private List copyICurricularCourseScope2InfoCurricularCourseScope(Collection associatedCurricularCourseScopes) {
    List associatedInfoCCScopes = (List) CollectionUtils.collect(associatedCurricularCourseScopes,
            new Transformer() {

                @Override/*  ww w  .j  av  a 2  s. co  m*/
                public Object transform(Object arg0) {
                    return InfoCurricularCourseScope.newInfoFromDomain((CurricularCourseScope) arg0);
                }
            });

    return associatedInfoCCScopes;
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.utils.RequestUtils.java

public static Collection buildExecutionDegreeLabelValueBean(Collection executionDegrees) {
    final Map duplicateDegreesMap = new HashMap();
    for (Iterator iterator = executionDegrees.iterator(); iterator.hasNext();) {
        InfoExecutionDegree infoExecutionDegree = (InfoExecutionDegree) iterator.next();
        InfoDegree infoDegree = infoExecutionDegree.getInfoDegreeCurricularPlan().getInfoDegree();
        String degreeName = infoDegree.getNome();

        if (duplicateDegreesMap.get(degreeName) == null) {
            duplicateDegreesMap.put(degreeName, new Boolean(false));
        } else {//from w w  w . ja  v a2s . co m
            duplicateDegreesMap.put(degreeName, new Boolean(true));
        }
    }

    Collection lableValueList = CollectionUtils.collect(executionDegrees, new Transformer() {

        @Override
        public Object transform(Object arg0) {
            InfoExecutionDegree infoExecutionDegree = (InfoExecutionDegree) arg0;

            String label = infoExecutionDegree.getInfoDegreeCurricularPlan().getDegreeCurricularPlan()
                    .getPresentationName(infoExecutionDegree.getInfoExecutionYear().getExecutionYear());

            String value = infoExecutionDegree.getExternalId().toString();

            return new LabelValueBean(label, value);
        }

    });

    Comparator comparator = new BeanComparator("label", Collator.getInstance());
    Collections.sort((List) lableValueList, comparator);

    return lableValueList;
}

From source file:net.sourceforge.fenixedu.dataTransferObject.InfoGuideWithPersonAndExecutionDegreeAndContributor.java

@Override
public void copyFromDomain(Guide guide) {
    super.copyFromDomain(guide);
    if (guide != null) {
        setInfoPerson(InfoPerson.newInfoFromDomain(guide.getPerson()));
        setInfoExecutionDegree(InfoExecutionDegree.newInfoFromDomain(guide.getExecutionDegree()));
        setInfoContributor(InfoContributor.newInfoFromDomain(guide.getContributorParty()));
        setInfoGuideSituation(InfoGuideSituation.newInfoFromDomain(guide.getActiveSituation()));

        if (guide.getGuideEntriesSet() != null) {
            List infoGuideEntryList = (List) CollectionUtils.collect(guide.getGuideEntriesSet(),
                    new Transformer() {

                        @Override
                        public Object transform(Object arg0) {
                            GuideEntry guideEntry = (GuideEntry) arg0;
                            return InfoGuideEntry.newInfoFromDomain(guideEntry);
                        }/* ww  w . j  a v  a2 s  . c o  m*/
                    });
            setInfoGuideEntries(infoGuideEntryList);
        }

        if (guide.getGuideSituationsSet() != null) {
            List infoGuideSituationList = (List) CollectionUtils.collect(guide.getGuideSituationsSet(),
                    new Transformer() {

                        @Override
                        public Object transform(Object arg0) {
                            GuideSituation guideSituation = (GuideSituation) arg0;
                            return InfoGuideSituation.newInfoFromDomain(guideSituation);
                        }
                    });
            setInfoGuideSituations(infoGuideSituationList);
        }
    }
}

From source file:com.base2.kagura.core.report.parameterTypes.datasources.SQL.java

/**
 * Executes the report, selecting the first column OR the column designated to make up the parameters values.
 * {@inheritDoc}// w  w w . jav  a 2  s.  c o  m
 */
@JsonIgnore
@Override
public Collection<Object> getValues() {
    ReportConnector reportConnector = report.getReportConnector();
    reportConnector.run(extra);
    if (reportConnector.getRows() == null)
        return new ArrayList<Object>();
    return CollectionUtils.collect(reportConnector.getRows(), new Transformer() {
        @Override
        public Object transform(Object input) {
            Map<String, Object> map = (Map<String, Object>) input;
            if (map.size() == 1)
                return map.values().iterator().next();
            else
                return map.get(selectedColumn);
        }
    });
}

From source file:com.abiquo.server.core.cloud.VirtualDatacenterDAO.java

private static Criterion availableToUser(final User user) {
    Collection<String> idsStrings = Arrays.asList(user.getAvailableVirtualDatacenters().split(","));

    Collection<Integer> ids = CollectionUtils.collect(idsStrings, new Transformer() {
        @Override//from   w  w  w  . ja v  a 2  s.co m
        public Object transform(final Object input) {
            return Integer.valueOf(input.toString());
        }
    });

    return Restrictions.in(PersistentEntity.ID_PROPERTY, ids);
}

From source file:com.acc.storefront.controllers.cms.CartSuggestionComponentController.java

@Override
protected void fillModel(final HttpServletRequest request, final Model model,
        final CartSuggestionComponentModel component) {
    if (cartFacade.hasSessionCart()) {
        final Set<String> products = new HashSet<String>(
                CollectionUtils.collect(cartFacade.getSessionCart().getEntries(), new Transformer() {
                    @Override/*from w w w  .jav a  2s .c o m*/
                    public Object transform(final Object object) {
                        final OrderEntryData orderEntry = (OrderEntryData) object;
                        return orderEntry.getProduct().getCode();
                    }
                }));

        if (!Collections.isEmpty(products)) {
            final List<ProductData> productSuggestions = simpleSuggestionFacade.getReferencesForProducts(
                    products, component.getProductReferenceTypes(), component.isFilterPurchased(),
                    component.getMaximumNumberProducts());

            model.addAttribute("title", component.getTitle());
            model.addAttribute("suggestions", productSuggestions);
        }
    }
}