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:com.perceptive.epm.perkolcentral.bl.ImageNowLicenseBL.java

@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.SERIALIZABLE, readOnly = true, rollbackFor = ExceptionWrapper.class)
public ArrayList<Imagenowlicenses> getLicensesToBeProvided() throws ExceptionWrapper {
    try {/*  www. j a v  a 2s .c o m*/
        ArrayList<Imagenowlicenses> imagenowlicensesArrayList = new ArrayList<Imagenowlicenses>(
                imageNowLicenseDataAccessor.getAllImageNowLicenses().values());
        CollectionUtils.filter(imagenowlicensesArrayList, new Predicate() {
            @Override
            public boolean evaluate(Object o) {
                return !((Imagenowlicenses) o).isIsProvided(); //To change body of implemented methods use File | Settings | File Templates.
            }
        });
        return imagenowlicensesArrayList;
    } catch (Exception ex) {
        throw new ExceptionWrapper(ex);
    }
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.publico.FinalDegreeWorkProposalsDispatchAction.java

private void filterBranchList(ActionForm form, HttpServletRequest request) {
    DynaActionForm finalWorkForm = (DynaActionForm) form;
    String branchOID = (String) finalWorkForm.get("branchOID");

    if (branchOID != null && !branchOID.equals("") && StringUtils.isNumeric(branchOID)) {
        Collection headers = (Collection) request.getAttribute("publishedFinalDegreeWorkProposalHeaders");
        CollectionUtils.filter(headers, new FILTER_INFOPROSAL_HEADERS_BY_BRANCH_PREDICATE(branchOID));
    }//from w w w  .j a  v  a  2s .  c  o m
}

From source file:com.tlabs.eve.api.character.TrainingQueue.java

public final List<SkillInTraining> list(boolean activeOnly) {
    if (!activeOnly) {
        return this.list();
    }/*from  w  w  w .  j  a  v  a 2 s .c  om*/

    final long now = System.currentTimeMillis();
    final List<SkillInTraining> r = new ArrayList<SkillInTraining>(this.training.size());
    CollectionUtils.filter(r, new Predicate() {
        @Override
        public boolean evaluate(Object object) {
            SkillInTraining t = (SkillInTraining) object;
            return t.getEndTime() > now;
        }
    });
    return r;
}

From source file:au.com.jwatmuff.eventmanager.model.misc.PoolPlayerSequencer.java

public static List<PlayerPoolInfo> getPlayerSequence(Database database, int poolID) {
    int numPlayerPositions = getNumberOfPlayerPositions(database, poolID);
    List<PlayerPoolInfo> players = new ArrayList<PlayerPoolInfo>(PlayerPoolInfo.getForPool(database, poolID));
    List<PlayerPoolInfo> newPlayers = new ArrayList<PlayerPoolInfo>();

    CollectionUtils.filter(players, new Predicate() {
        @Override/*from w w  w.java2 s .c om*/
        @SuppressWarnings("unchecked")
        public boolean evaluate(Object player) {
            return ((PlayerPoolInfo) player).getPlayerPool().isApproved();
        }
    });

    boolean repositionPlayers = false;
    for (PlayerPoolInfo player : players) {
        if (player.getPlayerPool().getPlayerPosition() > numPlayerPositions) {
            repositionPlayers = true;
        }
    }

    if (repositionPlayers) {
        Collections.sort(players, PLAYERS_COMPARATOR_POSITION);
        newPlayers.addAll(players);
    } else {
        Collections.sort(players, PLAYERS_COMPARATOR_POSITION);

        // create a new list with null entries so that player pool position reflects
        // the index of each player in the list
        int index = 1;
        for (PlayerPoolInfo player : players) {
            while (index < player.getPlayerPool().getPlayerPosition()) {
                newPlayers.add(null);
                index++;
            }
            newPlayers.add(player);
            index++;
        }
    }

    // finally, insert any additional nulls to make the length of the list
    // equal to the number of player positions in the pool
    for (int index = newPlayers.size() + 1; index <= numPlayerPositions; index++)
        newPlayers.add(null);

    return newPlayers;
}

From source file:de.hybris.platform.b2bacceleratorfacades.user.populators.B2BCustomerPopulator.java

protected void populateRoles(final B2BCustomerModel source, final CustomerData target) {
    final List<String> roles = new ArrayList<String>();
    final Set<PrincipalGroupModel> roleModels = new HashSet<PrincipalGroupModel>(source.getGroups());
    CollectionUtils.filter(roleModels,
            PredicateUtils.notPredicate(PredicateUtils.instanceofPredicate(B2BUnitModel.class)));
    CollectionUtils.filter(roleModels,//w ww  .  j a v  a2s  .c  om
            PredicateUtils.notPredicate(PredicateUtils.instanceofPredicate(B2BUserGroupModel.class)));
    for (final PrincipalGroupModel role : roleModels) {
        // only display allowed usergroups
        if (getB2BUserGroupsLookUpStrategy().getUserGroups().contains(role.getUid())) {
            roles.add(role.getUid());
        }
    }
    target.setRoles(roles);
}

From source file:com.jxt.web.service.AgentInfoServiceImpl.java

@Override
public Set<AgentInfo> getAgentsByApplicationNameWithoutStatus(String applicationName, long timestamp) {
    if (applicationName == null) {
        throw new NullPointerException("applicationName must not be null");
    }/*from   w  w  w .j av a 2  s. co  m*/
    if (timestamp < 0) {
        throw new IllegalArgumentException("timestamp must not be less than 0");
    }

    List<String> agentIds = this.applicationIndexDao.selectAgentIds(applicationName);
    List<AgentInfo> agentInfos = this.agentInfoDao.getAgentInfos(agentIds, timestamp);
    CollectionUtils.filter(agentInfos, PredicateUtils.notNullPredicate());
    if (CollectionUtils.isEmpty(agentInfos)) {
        return Collections.emptySet();
    }
    return new HashSet<>(agentInfos);
}

From source file:com.perceptive.epm.perkolcentral.action.ImageNowLicenseAction.java

private void getSpecificGroupsThatRequireINLicense() throws ExceptionWrapper {
    try {/*from  ww w  . j a v  a 2s.c  o  m*/
        if (rallyGroups == null)
            return;
        ArrayList<GroupBO> groupBOArrayList = new ArrayList<GroupBO>(groupsBL.getAllGroups().values());
        CollectionUtils.filter(groupBOArrayList, new Predicate() {
            @Override
            public boolean evaluate(Object o) {
                return ((GroupBO) o).getGroupId().trim().equalsIgnoreCase("22");
            }
        });
        for (GroupBO groupBO : groupBOArrayList) {
            rallyGroups.add(groupBO);
        }
    } catch (Exception ex) {
        throw new ExceptionWrapper(ex);
    }
}

From source file:info.magnolia.test.mock.MockContent.java

@Override
public Collection<Content> getChildren(final ContentFilter filter, final String namePattern,
        Comparator<Content> orderCriteria) {
    // copy//w  w  w .j  ava  2 s.  co m
    final Collection<MockNode> children = ((MockNode) node).getChildren().values();
    final Collection<Content> contentChildren = new ArrayList<Content>();
    for (MockNode current : children) {
        contentChildren.add(wrapAsContent(current));
    }

    final Predicate filterPredicate = new Predicate() {
        @Override
        public boolean evaluate(Object object) {
            return filter.accept((Content) object);
        }
    };

    CollectionUtils.filter(contentChildren, filterPredicate);

    if (namePattern != null) {
        CollectionUtils.filter(contentChildren, new NamePatternFilter(namePattern));
    }

    return contentChildren;
}

From source file:com.projity.reports.view.ReportView.java

private void makeViewer() throws JRException {
    if (!dirty)//  w  w w. j a  v a 2s .c  o m
        return;

    documentFrame.showWaitCursor(true);

    if (cache != null) { // remove old listener
        cache.removeNodeModelListener(this);
    }

    DataSource dataSource;

    SpreadSheetFieldArray fa = null;
    if (fieldArray != null) {
        fa = (SpreadSheetFieldArray) fieldArray.clone();
        CollectionUtils.filter(fa, new Predicate() {
            public boolean evaluate(Object arg0) {
                return !((Field) arg0).isGraphical(); // get rid of fields that can't be shown
            }
        });
    }
    JasperReport report = ReportUtil.getReport(reportDefinition, coord.getProjectTimeIterator(), fa);

    viewName = DataSourceProvider.getViewName(report);
    //System.out.println("viewName="+viewName);
    documentFrame.setComboBoxesViewName(viewName);

    NodeModel model = null;
    PredicatedNodeFilterIterator iterator;
    if (viewName == DataSourceProvider.REPORT_VIEW) { // special case to just use project
        cache = null;
        ArrayList list = new ArrayList();
        list.add(project);
        iterator = GeneralFilteredIterator.instance(list.iterator());
    } else {
        model = updateCacheForView(viewName);
        if (cache == null) {
            iterator = GeneralFilteredIterator.instance(model.iterator());
            //for (Iterator i=GeneralFilteredIterator.instance(model.iterator());i.hasNext();) System.out.println("Report model iterator: "+i.next());
        } else {
            iterator = GeneralFilteredIterator.instance(cache.getIterator());
            //for (Iterator i=GeneralFilteredIterator.instance(cache.getIterator());i.hasNext();) System.out.println("Report cache iterator: "+i.next());
        }
    }
    dataSource = DataSourceProvider.createDataSource(report, project, iterator, model);

    // projet name is used as report's title
    // and passed as a parameter
    HashMap params = new HashMap();
    params.put("projectName", project.getName()); //$NON-NLS-1$

    JasperPrint jasperPrint = JasperFillManager.fillReport(report, params, dataSource);
    if (viewer != null) {
        viewer.changeReport(jasperPrint);
    } else {
        viewer = new ReportViewer(jasperPrint);
        add(viewer, BorderLayout.CENTER);
    }
    // add new listener
    if (cache != null) {
        cache.addNodeModelListener(this);
    }
    dirty = false;

    documentFrame.showWaitCursor(false);

}

From source file:adalid.core.Display.java

public List<? extends DisplayField> getRootFields() {
    List<? extends DisplayField> fields = new ArrayList<>(getFields());
    CollectionUtils.filter(fields, new IsDisplayRootField());
    Collections.sort(fields, byPropertySequenceNumber);
    return fields;
}