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

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

Introduction

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

Prototype

public static void filter(Collection collection, Predicate predicate) 

Source Link

Document

Filter the collection by applying a Predicate to each element.

Usage

From source file:org.squashtest.tm.domain.library.structures.LibraryGraph.java

public List<T> filter(Predicate predicate) {
    List<T> result = new ArrayList<>(getNodes());

    CollectionUtils.filter(result, predicate);
    return result;
}

From source file:org.squashtest.tm.domain.library.structures.LibraryTree.java

public List<T> getLeaves() {
    List<T> leaves = new ArrayList<>(getAllNodes());
    CollectionUtils.filter(leaves, new Predicate() {
        @Override/*from   ww  w  .  j  a v a 2  s.  co m*/
        public boolean evaluate(Object object) {
            return ((T) object).getChildren().isEmpty();
        }
    });
    return leaves;
}

From source file:org.squashtest.tm.domain.milestone.Milestone.java

public boolean isOneVersionAlreadyBound(RequirementVersion version) {

    // check that no other version of this requirement is bound already to this milestone
    Collection<RequirementVersion> allVersions = new ArrayList<>(
            version.getRequirement().getRequirementVersions());
    CollectionUtils.filter(allVersions, new Predicate() {

        @Override//from   w w  w  .  j  ava 2 s .c om
        public boolean evaluate(Object reqV) {
            return ((RequirementVersion) reqV).getMilestones().contains(Milestone.this);
        }
    });

    return CollectionUtils.containsAny(requirementVersions, allVersions);

}

From source file:org.squashtest.tm.service.internal.campaign.CampaignTestPlanManagerServiceImpl.java

@Override
@PreAuthorize(CAN_LINK_CAMPAIGN_BY_ID)//from   w  w w  .  ja v  a  2  s  .  co  m
public void addTestCasesToCampaignTestPlan(final List<Long> testCasesIds, long campaignId) {
    // nodes are returned unsorted
    List<TestCaseLibraryNode> nodes = testCaseLibraryNodeDao.findAllByIds(testCasesIds);

    // now we resort them according to the order in which the testcaseids were given
    IdentifiersOrderComparator comparator = new IdentifiersOrderComparator(testCasesIds);
    Collections.sort(nodes, comparator);

    List<TestCase> testCases = new TestCaseNodeWalker().walk(nodes);

    final Optional<Milestone> activeMilestone = activeMilestoneHolder.getActiveMilestone();

    if (activeMilestone.isPresent()) {
        CollectionUtils.filter(testCases, new Predicate() {

            @Override
            public boolean evaluate(Object tc) {
                return ((TestCase) tc).getAllMilestones().contains(activeMilestone.get());
            }
        });
    }

    Campaign campaign = campaignDao.findById(campaignId);

    /*
     * Feat 3700 campaign test plans are now populated the same way than iteration
     * are
     */
    for (TestCase testCase : testCases) {

        Set<Dataset> datasets = testCase.getDatasets();

        if (datasets.isEmpty()) {
            CampaignTestPlanItem itp = new CampaignTestPlanItem(testCase);
            campaignTestPlanItemDao.persist(itp);
            campaign.addToTestPlan(itp);
        } else {
            for (Dataset ds : datasets) {
                CampaignTestPlanItem itp = new CampaignTestPlanItem(testCase, ds);
                campaignTestPlanItemDao.persist(itp);
                campaign.addToTestPlan(itp);
            }
        }
    }
}

From source file:org.squashtest.tm.service.internal.campaign.IterationTestPlanManagerServiceImpl.java

@Override
@PreAuthorize("hasPermission(#iteration, 'LINK') " + OR_HAS_ROLE_ADMIN)
public List<IterationTestPlanItem> addTestPlanItemsToIteration(final List<Long> testNodesIds,
        Iteration iteration) {/*w ww  .j a v  a2 s .co m*/

    // nodes are returned unsorted
    List<TestCaseLibraryNode> nodes = testCaseLibraryNodeDao.findAllByIds(testNodesIds);

    // now we resort them according to the order in which the testcaseids were given
    IdentifiersOrderComparator comparator = new IdentifiersOrderComparator(testNodesIds);
    Collections.sort(nodes, comparator);

    List<TestCase> testCases = new TestCaseNodeWalker().walk(nodes);

    final Optional<Milestone> activeMilestone = activeMilestoneHolder.getActiveMilestone();

    if (activeMilestone.isPresent()) {
        CollectionUtils.filter(testCases, new Predicate() {

            @Override
            public boolean evaluate(Object tc) {
                return ((TestCase) tc).getAllMilestones().contains(activeMilestone.get());
            }
        });
    }

    List<IterationTestPlanItem> testPlan = new LinkedList<>();

    for (TestCase testCase : testCases) {
        addTestCaseToTestPlan(testCase, testPlan);
    }
    addTestPlanToIteration(testPlan, iteration.getId());
    return testPlan;
}

From source file:org.squashtest.tm.service.internal.chart.engine.DetailedChartQuery.java

private Collection<ColumnPrototypeInstance> findSubqueriesForStrategy(PerStrategyColumnFinder finder) {
    Collection<ColumnPrototypeInstance> found = new ArrayList<>();

    Collection<? extends ColumnPrototypeInstance> measures = new ArrayList<>(getMeasures());
    CollectionUtils.filter(measures, finder);
    found.addAll(measures);/*  w w  w . j a  va 2s  . co m*/

    Collection<? extends ColumnPrototypeInstance> axes = new ArrayList<>(getAxis());
    CollectionUtils.filter(axes, finder);
    found.addAll(axes);

    Collection<? extends ColumnPrototypeInstance> filters = new ArrayList<>(getFilters());
    CollectionUtils.filter(filters, finder);
    found.addAll(filters);

    return found;
}

From source file:org.squashtest.tm.service.internal.chart.engine.FilterPlanner.java

private Map<ColumnPrototype, Collection<Filter>> findWhereFilters() {
    Collection<Filter> filters = new ArrayList<>(definition.getFilters());

    CollectionUtils.filter(filters, new Predicate() {
        @Override/* ww  w . j a va2s.co m*/
        public boolean evaluate(Object filter) {
            return utils.isWhereClauseComponent((Filter) filter);
        }
    });

    return sortFilters(filters);
}

From source file:org.squashtest.tm.service.internal.chart.engine.FilterPlanner.java

private Map<ColumnPrototype, Collection<Filter>> findHavingFilters() {
    Collection<Filter> filters = new ArrayList<>(definition.getFilters());

    CollectionUtils.filter(filters, new Predicate() {
        @Override/*from w  w  w . java2 s.c om*/
        public boolean evaluate(Object filter) {
            return utils.isHavingClauseComponent((Filter) filter);
        }
    });

    return sortFilters(filters);
}

From source file:org.squashtest.tm.service.internal.customfield.AbstractCustomFieldHelper.java

/**
 * Return the CustomFields referenced by the CustomFieldBindings for the given project and BindableEntity type,
 * ordered by their position. The location argument is optional, if set then only the custom fields that are
 * rendered in at least one of these locations will be returned.
 *
 * @param projectId/* w  ww.  j  a  v a2 s. co m*/
 * @param entityType
 * @return
 */
@SuppressWarnings("unchecked")
protected final List<CustomField> findCustomFields(long projectId, BindableEntity entityType,
        Collection<RenderingLocation> optionalLocations) {

    List<CustomFieldBinding> bindings = cufBindingService.findCustomFieldsForProjectAndEntity(projectId,
            entityType);

    Collections.sort(bindings, new BindingSorter());

    if (optionalLocations != null && !optionalLocations.isEmpty()) {
        CollectionUtils.filter(bindings, new BindingLocationFilter(optionalLocations));
    }

    return (List<CustomField>) CollectionUtils.collect(bindings, new BindingFieldCollector());

}

From source file:org.squashtest.tm.service.internal.project.CustomGenericProjectManagerImpl.java

/**
 * @see org.squashtest.tm.service.project.CustomGenericProjectManager#findSortedProjects(PagingAndMultiSorting,
 *      Filtering))/*from  w w  w.  j a  va  2  s  .  c om*/
 */
@SuppressWarnings("unchecked")
@Override
@Transactional(readOnly = true)
@PreAuthorize(HAS_ROLE_ADMIN_OR_PROJECT_MANAGER)
public PagedCollectionHolder<List<GenericProject>> findSortedProjects(PagingAndMultiSorting sorting,
        Filtering filter) {

    Class<? extends GenericProject> type = permissionEvaluationService.hasRole("ROLE_ADMIN")
            ? GenericProject.class
            : Project.class;
    List<? extends GenericProject> resultset = genericProjectDao.findAllWithTextProperty(type, filter);

    // filter on permission
    List<? extends GenericProject> securedResultset = new LinkedList<>(resultset);
    CollectionUtils.filter(securedResultset, new IsManagerOnObject());

    // Consolidate projects with additional information neeeded to do the
    // sorting
    List<ProjectForCustomCompare> projects = consolidateProjects(securedResultset);
    sortProjects(projects, sorting);

    // manual paging
    int listsize = projects.size();
    int firstIdx = Math.min(listsize, sorting.getFirstItemIndex());
    int lastIdx = Math.min(listsize, firstIdx + sorting.getPageSize());
    projects = projects.subList(firstIdx, lastIdx);

    securedResultset = extractProjectList(projects);

    return new PagingBackedPagedCollectionHolder<>(sorting, listsize, (List<GenericProject>) securedResultset);

}