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, final Transformer transformer,
        final Collection outputCollection) 

Source Link

Document

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

Usage

From source file:nl.strohalm.cyclos.services.accounts.guarantees.CertificationServiceImpl.java

@Override
@SuppressWarnings("unchecked")
public List<CertificationDTO> searchWithUsedAmount(final CertificationQuery queryParameters) {
    final List<Certification> certifications = certificationDao.seach(queryParameters);

    final Transformer transformer = new Transformer() {
        @Override/*from w ww . j  av a 2s  .  co m*/
        public Object transform(final Object input) {
            final Certification certification = (Certification) input;
            return new CertificationDTO(certification, getUsedAmount(certification, false));
        }
    };

    List<CertificationDTO> result = (List<CertificationDTO>) CollectionUtils.collect(certifications,
            transformer, new ArrayList<CertificationDTO>());
    if (certifications instanceof Page) {
        final Page<Certification> original = (Page<Certification>) certifications;
        final PageParameters pageParameters = new PageParameters(original.getPageSize(),
                original.getCurrentPage());
        result = new PageImpl<CertificationDTO>(pageParameters, original.getTotalCount(), result);
    }

    return result;
}

From source file:org.broadleafcommerce.admin.server.service.handler.SkuCustomPersistenceHandler.java

/**
 * Returns a {@link Property} filled out with a delimited list of the <b>values</b> that are passed in. This should be
 * invoked on a fetch and the returned property should be added to the fetched {@link Entity} dto.
 * /*from   w ww  .j  a v  a  2s.  c o m*/
 * @param values
 * @return
 * @see {@link #createConsolidatedOptionField(Class)};
 */
public Property getConsolidatedOptionProperty(Collection<ProductOptionValue> values) {
    Property optionValueProperty = new Property();
    optionValueProperty.setName(CONSOLIDATED_PRODUCT_OPTIONS_FIELD_NAME);

    //order the values by the display order of their correspond product option
    //        Collections.sort(values, new Comparator<ProductOptionValue>() {
    //
    //            @Override
    //            public int compare(ProductOptionValue value1, ProductOptionValue value2) {
    //                return new CompareToBuilder().append(value1.getProductOption().getDisplayOrder(),
    //                        value2.getProductOption().getDisplayOrder()).toComparison();
    //            }
    //        });

    ArrayList<String> stringValues = new ArrayList<String>();
    CollectionUtils.collect(values, new Transformer() {

        @Override
        public Object transform(Object input) {
            return ((ProductOptionValue) input).getAttributeValue();
        }
    }, stringValues);

    optionValueProperty.setValue(StringUtils.join(stringValues, CONSOLIDATED_PRODUCT_OPTIONS_DELIMETER));
    return optionValueProperty;
}

From source file:org.broadleafcommerce.core.workflow.BaseProcessor.java

/**
 * Called after the properties have been set, Ensures the list of activities
 *  is not empty and each activity is supported by this Workflow Processor
 *
 * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
 */// w  w  w . jav  a 2s.  c  om
@Override
public void afterPropertiesSet() throws Exception {

    if (!(beanFactory instanceof ListableBeanFactory)) {
        throw new BeanInitializationException("The workflow processor [" + beanName + "] "
                + "is not managed by a ListableBeanFactory, please re-deploy using some derivative of ListableBeanFactory such as"
                + "ClassPathXmlApplicationContext ");
    }

    if (CollectionUtils.isEmpty(activities) && !isAllowEmptyActivities()) {
        throw new UnsatisfiedDependencyException(getBeanDesc(), beanName, "activities",
                "No activities were wired for this workflow");
    }

    //sort the activities based on their configured order
    OrderComparator.sort(activities);

    HashSet<String> moduleNames = new HashSet<String>();
    for (Iterator<Activity<ProcessContext<? extends Object>>> iter = activities.iterator(); iter.hasNext();) {
        Activity<? extends ProcessContext<? extends Object>> activity = iter.next();
        if (!supports(activity)) {
            throw new BeanInitializationException("The workflow processor [" + beanName + "] does "
                    + "not support the activity of type" + activity.getClass().getName());
        }

        if (activity instanceof ModuleActivity) {
            moduleActivities.add((ModuleActivity) activity);
            moduleNames.add(((ModuleActivity) activity).getModuleName());
        }
    }

    if (CollectionUtils.isNotEmpty(moduleActivities)) {
        //log the fact that we've got some modifications to the workflow
        StringBuffer message = new StringBuffer();
        message.append("The following modules have made changes to the " + getBeanName() + " workflow: ");
        message.append(Arrays.toString(moduleNames.toArray()));
        message.append("\n");
        message.append("The final ordering of activities for the " + getBeanName() + " workflow is: \n");
        ArrayList<String> activityNames = new ArrayList<String>();
        CollectionUtils.collect(activities, new Transformer() {

            @Override
            public Object transform(Object input) {
                return ((Activity) input).getBeanName();
            }
        }, activityNames);
        message.append(Arrays.toString(activityNames.toArray()));

        supportLogger.lifecycle(LifeCycleEvent.CONFIG, message.toString());
    }

}

From source file:org.kuali.mobility.computerlabs.entity.LabGroupImpl.java

/**
 * @param locations the locations to set
 *//*from w  w  w. ja va2 s.  c om*/
@Override
public void setLocations(List<? extends Location> locations) {
    CollectionUtils.collect(locations, new LocationTransform(), this.locations);
}

From source file:org.kuali.mobility.computerlabs.entity.LocationImpl.java

@Override
public void setLabs(List<? extends Lab> labs) {
    CollectionUtils.collect(labs, LAB_TRANSFORM, this.labs);
}

From source file:org.kuali.mobility.computerlabs.service.ComputerLabsServiceImpl.java

@GET
@Path("/getLabGroups")
@Override/*  www . j ava  2 s. c  o m*/
public List<LabGroupImpl> getLabGroups() {
    List<LabGroupImpl> labGroups = new ArrayList<LabGroupImpl>();
    CollectionUtils.collect(getDao().getLabGroups(), new LabGroupTransform(), labGroups);
    return labGroups;
}

From source file:org.kuali.mobility.computerlabs.service.ComputerLabsServiceImpl.java

@GET
@Path("/getLocations")
@Override// w  ww.  j a  va 2  s  . c o  m
public List<LocationImpl> getLocations(@QueryParam(value = "groupId") final String groupId) {
    List<LocationImpl> locations = new ArrayList<LocationImpl>();
    CollectionUtils.collect(getDao().getLocations(groupId), new LocationTransform(), locations);
    return locations;
}

From source file:org.kuali.mobility.computerlabs.service.ComputerLabsServiceImpl.java

@GET
@Path("/getLabs")
@Override//from   w w  w.  j  ava 2s  .  co  m
public List<LabImpl> getLabs(@QueryParam(value = "locationId") final String locationId,
        @QueryParam(value = "buildingCode") final String buildingCode) {
    List<LabImpl> myLabs = new ArrayList<LabImpl>();
    CollectionUtils.collect(getDao().getLabs(locationId, buildingCode), new LabTransform(), myLabs);
    return myLabs;
}

From source file:org.kuali.mobility.emergencyinfo.service.EmergencyInfoServiceImpl.java

@GET
@Path("information/lookup")
@Transactional/*w  ww  .j  a  v  a 2s.  c o  m*/
@Override
public List<EmergencyInfoImpl> findAllEmergencyInfo() {
    List<EmergencyInfoImpl> contacts = new ArrayList<EmergencyInfoImpl>();
    CollectionUtils.collect(getEmergencyInfoDao().findAllEmergencyInfo(), new EmergencyInfoTransform(),
            contacts);
    return contacts;
}

From source file:org.kuali.mobility.emergencyinfo.service.EmergencyInfoServiceImpl.java

@GET
@Path("information/bycampus/{campus}")
@Transactional/*from  w  ww .  j  av  a 2s.c  o  m*/
@Override
public List<EmergencyInfoImpl> findAllEmergencyInfoByCampus(@PathParam(value = "campus") String campus) {
    List<EmergencyInfoImpl> contacts = new ArrayList<EmergencyInfoImpl>();
    CollectionUtils.collect(getEmergencyInfoDao().findAllEmergencyInfoByCampus(campus),
            new EmergencyInfoTransform(), contacts);
    LOG.debug("Filtering emergency contacts for campus [" + campus + "] and found " + contacts.size());
    return contacts;
}