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

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

Introduction

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

Prototype

public static Collection select(Collection inputCollection, Predicate predicate) 

Source Link

Document

Selects all elements from input collection which match the given predicate into an output collection.

Usage

From source file:org.kuali.mobility.events.service.EventsServiceImpl.java

@GET
@Path("/byCategory/{categoryId}")
@Override//from  ww  w. ja v a 2s.co m
public List<EventImpl> getAllEvents(@QueryParam(value = "campus") String campus,
        @PathParam(value = "categoryId") String categoryId) {
    getDao().initData(campus, categoryId);
    List<Event> events = (List<Event>) CollectionUtils.select(getDao().getEvents(),
            new EventPredicate(campus, categoryId, null));
    Collections.sort(events, new EventComparator());

    List<EventImpl> eventList = new ArrayList<EventImpl>();
    CollectionUtils.collect(events, new EventTransform(), eventList);

    return eventList;
}

From source file:org.kuali.mobility.events.service.EventsServiceImpl.java

@GET
@Path("/categories")
@Override/*from  w  w w. j a  v a2 s.  c  o  m*/
public List<CategoryImpl> getCategoriesByCampus(@QueryParam(value = "campus") String campus) {
    List<Category> categories = new ArrayList<Category>();

    LOG.debug("Loading categories for campus [" + campus + "]");
    getDao().initData(campus);

    categories = (List<Category>) CollectionUtils.select(getDao().getCategories(),
            new CategoryPredicate(campus, null));

    LOG.debug("Number of categories for campus [" + campus + "] = " + categories.size());

    List<CategoryImpl> categoryObjs = new ArrayList<CategoryImpl>();
    for (int i = 0; i < categories.size(); i++) {
        Collection events = CollectionUtils.select(getDao().getEvents(),
                new EventPredicate(campus, categories.get(i).getCategoryId(), null));
        if (events.size() > 0) {
            categories.get(i).setHasEvents(true);
        } else {
            categories.get(i).setHasEvents(false);
        }
    }
    CollectionUtils.collect(categories, new CategoryTransform(), categoryObjs);

    return categoryObjs;
}

From source file:org.kuali.mobility.news.dao.NewsDaoImpl.java

public List<? extends NewsSource> findNewsSources(final Long parentId, final Boolean isActive) {
    initData();/*  w ww  . j a  v  a2  s .c o m*/
    return (List<? extends NewsSource>) CollectionUtils.select(getCache().getNewsSources().values(),
            new NewsSourcePredicate(parentId, isActive));
}

From source file:org.kuali.mobility.news.dao.NewsDaoImpl.java

@Override
public List<? extends NewsSource> findAllActiveNewsSources() {
    initData();//  w w  w .  j  a  v a  2 s . c  o  m
    return (List<? extends NewsSource>) CollectionUtils.select(getCache().getNewsSources().values(),
            new NewsSourcePredicate(null, new Boolean(true)));
}

From source file:org.kuali.mobility.news.dao.NewsDaoImpl.java

public List<? extends NewsSource> findAllActiveNewsSources(final Long parentId) {
    initData();/*  w  w w  .ja v  a  2s  . c  o  m*/
    return (List<? extends NewsSource>) CollectionUtils.select(getCache().getNewsSources().values(),
            new NewsSourcePredicate(parentId, new Boolean(true)));
}

From source file:org.kuali.mobility.news.dao.NewsDaoImpl.java

public List<? extends NewsSource> findAllNewsSources(final Long parentId) {
    initData();//from  www . j  a v  a2 s . c o  m
    return (List<? extends NewsSource>) CollectionUtils.select(getCache().getNewsSources().values(),
            new NewsSourcePredicate(parentId, null));
}

From source file:org.kuali.rice.kew.rule.RuleValidationAttributeRemotingTest.java

/**
 * Tests that the TestRuleValidationAttribute exposed by the exporter is invoked (via the resolver).
 * This test assumes that the only rule validation attribute present is the TestRuleValidationAttribute.
 *///from  w  w  w  .j ava  2 s  .c  om
@Test
public void test_resolver() throws Exception {
    TestRuleValidationAttribute.invocations = 0;
    int invocations = 0;
    for (RuleAttribute attrib : (Collection<RuleAttribute>) CollectionUtils
            .select(KEWServiceLocator.getRuleAttributeService().findAll(), RULE_VALIDATION_ATTRIB_PREDICATE)) {
        RuleValidationAttribute rva = resolver.resolveRuleValidationAttribute(attrib.getName(), null);
        assertNotNull("RuleValidationAttribute resolution failed", rva);
        RuleValidationContext ctx = RuleValidationContext.Builder
                .create(org.kuali.rice.kew.api.rule.Rule.Builder.create().build()).build();
        assertNotNull("RuleValidationAttribute returned null result", rva.validate(ctx));
        invocations++;
    }
    Assert.assertEquals("Actual TestRuleValidationAttribute invocations did not match expected invocations",
            invocations, TestRuleValidationAttribute.invocations);
}

From source file:org.kuali.rice.kew.rule.RuleValidationAttributeRemotingTest.java

/**
 * Tests invoking the exported SOAP RuleValidationAttributeExporterService.
 *//*  ww  w  . jav  a 2s . c  o  m*/
@Test
public void test_exporter() throws Exception {
    RuleValidationAttributeExporterService exporter = (RuleValidationAttributeExporterService) bus
            .getService(EXPORTER_SOAP_SERVICE_NAME);
    Assert.assertNotNull("Could not find the RuleValidationAttributeExporterService SOAP endpoint on the bus!",
            exporter);

    TestRuleValidationAttribute.invocations = 0;
    int invocations = 0;
    for (RuleAttribute attrib : (Collection<RuleAttribute>) CollectionUtils
            .select(KEWServiceLocator.getRuleAttributeService().findAll(), RULE_VALIDATION_ATTRIB_PREDICATE)) {
        RuleValidationContext ctx = RuleValidationContext.Builder
                .create(org.kuali.rice.kew.api.rule.Rule.Builder.create().build()).build();
        assertNotNull("RuleValidationAttributeExporterService return value was null",
                exporter.validate(attrib.getName(), ctx));
        invocations++;
    }
    Assert.assertEquals("Actual TestRuleValidationAttribute invocations did not match expected invocations",
            invocations, TestRuleValidationAttribute.invocations);
}

From source file:org.mifos.customers.personnel.persistence.LegacyPersonnelDao.java

@SuppressWarnings("unchecked")
public List<PersonnelBO> getActiveBranchManagersUnderOffice(Short officeId, final RoleBO role)
        throws PersistenceException {
    Map<String, Object> params = new HashMap<String, Object>();
    params.put(CustomerSearchConstants.OFFICEID, officeId);
    params.put(CustomerSearchConstants.PERSONNELSTATUSID, PersonnelStatus.ACTIVE.getValue());
    List activeBranchManagers = executeNamedQuery(NamedQueryConstants.GET_ACTIVE_BRANCH_MANAGER_UNDER_OFFICE,
            params);// w w w  .jav  a2s .c o m
    return (List<PersonnelBO>) CollectionUtils.select(activeBranchManagers, new Predicate() {
        @Override
        public boolean evaluate(Object object) {
            Set<PersonnelRoleEntity> applicableRoles = ((PersonnelBO) object).getPersonnelRoles();
            return CollectionUtils.exists(applicableRoles, new Predicate() {
                @Override
                public boolean evaluate(Object object) {
                    return ((PersonnelRoleEntity) object).getRole().equals(role);
                }
            });
        }
    });
}

From source file:org.mifos.customers.personnel.persistence.PersonnelPersistence.java

@SuppressWarnings("unchecked")
public List<PersonnelBO> getActiveBranchManagersUnderOffice(Short officeId, final RoleBO role)
        throws PersistenceException {
    Map<String, Object> params = new HashMap<String, Object>();
    params.put(CustomerSearchConstants.OFFICEID, officeId);
    params.put(CustomerSearchConstants.PERSONNELSTATUSID, PersonnelStatus.ACTIVE.getValue());
    List activeBranchManagers = executeNamedQuery(NamedQueryConstants.GET_ACTIVE_BRANCH_MANAGER_UNDER_OFFICE,
            params);/*w w  w.ja  v  a 2  s . c  om*/
    return (List<PersonnelBO>) CollectionUtils.select(activeBranchManagers, new Predicate() {
        public boolean evaluate(Object object) {
            Set<PersonnelRoleEntity> applicableRoles = ((PersonnelBO) object).getPersonnelRoles();
            return CollectionUtils.exists(applicableRoles, new Predicate() {
                public boolean evaluate(Object object) {
                    return ((PersonnelRoleEntity) object).getRole().equals(role);
                }
            });
        }
    });
}