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 void select(Collection inputCollection, Predicate predicate, Collection outputCollection) 

Source Link

Document

Selects all elements from input collection which match the given predicate and adds them to outputCollection.

Usage

From source file:org.onexus.website.api.pages.browser.BrowserPageStatus.java

@Override
public List<WidgetStatus> getActiveWidgetStatuses(ORI parentOri) {

    BrowserPageConfig pageConfig = getConfig();
    TabConfig tabConfig = pageConfig.getTab(currentTabId);
    ViewConfig viewConfig = tabConfig.getView(currentView);

    List<WidgetConfig> widgetConfigs = new ArrayList<WidgetConfig>();
    Predicate visible = new VisiblePredicate(parentOri, getEntitySelections());
    CollectionUtils.select(ViewConfig.getSelectedWidgetConfigs(pageConfig, viewConfig.getLeft(),
            viewConfig.getTop(), viewConfig.getTopRight(), viewConfig.getMain()), visible, widgetConfigs);

    List<WidgetStatus> statuses = new ArrayList<WidgetStatus>();
    for (WidgetConfig config : widgetConfigs) {
        WidgetStatus status = getWidgetStatus(config.getId());
        if (status != null) {
            statuses.add(status);//from   w  ww.ja v  a2  s.  com
        }
    }

    return statuses;
}

From source file:org.onexus.website.api.pages.browser.layouts.AbstractLayout.java

public List<WidgetConfig> filterWidgets(String selectedWidgets) {
    List<WidgetConfig> widgets = ViewConfig.getSelectedWidgetConfigs(getPageConfig(), selectedWidgets);
    VisiblePredicate predicate = new VisiblePredicate(getPageStatus().getORI(),
            getPageStatus().getEntitySelections());
    List<WidgetConfig> visibleWidgets = new ArrayList<WidgetConfig>();
    CollectionUtils.select(widgets, predicate, visibleWidgets);
    return visibleWidgets;
}

From source file:org.onexus.website.api.widgets.tableviewer.TableViewer.java

public TableViewer(String componentId, IModel<TableViewerStatus> status) {
    super(componentId, status);

    onEventFireUpdate(EventQueryUpdate.class, EventAddFilter.class, EventRemoveFilter.class);

    if (status.getObject() == null) {
        status.setObject(getStatus());//from  ww  w .  j a v  a  2 s .  c  o m
    }

    Integer sessionRowsPerPage = getSession().getMetaData(DEFAULT_ROWS_PER_PAGE);
    final Integer rowsPerPage = sessionRowsPerPage == null ? 20 : sessionRowsPerPage;

    this.dataProvider = new EntitiesRowProvider(status, rowsPerPage) {

        @Override
        protected Query getQuery() {
            return TableViewer.this.getQuery();
        }

        @Override
        protected void addTaskStatus(Progress progressStatus) {
            //TODO
        }

    };

    // Create the columns from the config
    int ccs = getStatus().getCurrentColumnSet();
    List<IColumnConfig> columnsConfig = getConfig().getColumnSets().get(ccs).getColumns();
    final List<IColumn<IEntityTable, String>> columns = new ArrayList<IColumn<IEntityTable, String>>();

    ORI parentURI = getQuery().getOn();

    List<IColumnConfig> visibleColumnsConfig = new ArrayList<IColumnConfig>(columnsConfig.size());
    BrowserPageStatus pageStatus = findParentStatus(BrowserPageStatus.class);

    Predicate sortablePredicate;
    if (pageStatus != null) {
        sortablePredicate = new VisiblePredicate(getPageBaseOri(), pageStatus.getEntitySelections());
        Predicate filter = new VisiblePredicate(getPageBaseOri(), pageStatus.getEntitySelections());
        CollectionUtils.select(columnsConfig, filter, visibleColumnsConfig);
    } else {
        sortablePredicate = new VisiblePredicate(getPageBaseOri(), Collections.EMPTY_LIST);
        visibleColumnsConfig = columnsConfig;
    }

    boolean tableSort = sortablePredicate.evaluate(getConfig().getSortable());
    for (IColumnConfig columnConfig : visibleColumnsConfig) {
        String columnSortStr = columnConfig.getSortable();
        boolean columnSort = sortablePredicate.evaluate(columnSortStr);
        columnConfig.addColumns(columns, parentURI, Strings.isEmpty(columnSortStr) ? tableSort : columnSort);
    }

    // Disable default status order if the table is not sortable.
    if (!tableSort) {
        getStatus().setOrder(null);
    }

    add(new OnDomReadyPanel("datatable") {
        @Override
        protected Panel onDomReadyPanel(String componentId) {

            Boolean forceCount = getConfig().getForceCount();
            if (forceCount != null && forceCount.booleanValue()) {
                dataProvider.forceCount();
            }

            return new DataTablePanel("datatable", columns, dataProvider, rowsPerPage);
        }
    });

}

From source file:org.openlmis.distribution.service.FacilityDistributionService.java

private void filterProductVials(List<ProductVial> productVials, List<ProductVial> childProductVials,
        List<ProductVial> adultProductVials) {
    CollectionUtils.select(productVials, new Predicate() {
        @Override/*from   ww w  .  ja va 2s  .  co m*/
        public boolean evaluate(Object o) {
            return ((ProductVial) o).getChildCoverage();
        }
    }, childProductVials);
    CollectionUtils.selectRejected(productVials, new Predicate() {
        @Override
        public boolean evaluate(Object o) {
            return ((ProductVial) o).getChildCoverage();
        }
    }, adultProductVials);
}

From source file:org.openlmis.distribution.service.FacilityDistributionService.java

private void filterTargetGroupProducts(List<TargetGroupProduct> targetGroupProducts,
        List<TargetGroupProduct> childrenTargetGroupProducts,
        List<TargetGroupProduct> adultTargetGroupProducts) {
    CollectionUtils.select(targetGroupProducts, new Predicate() {
        @Override//  ww  w  .  j  a  v  a2  s .  com
        public boolean evaluate(Object o) {
            return ((TargetGroupProduct) o).getChildCoverage();
        }
    }, childrenTargetGroupProducts);
    CollectionUtils.selectRejected(targetGroupProducts, new Predicate() {
        @Override
        public boolean evaluate(Object o) {
            return ((TargetGroupProduct) o).getChildCoverage();
        }
    }, adultTargetGroupProducts);
}

From source file:org.opennms.web.svclayer.outage.DateProcessRowsCallback.java

/** {@inheritDoc} */
@Override/*from   w w w. ja v  a  2 s  .  co m*/
public Collection filterRows(TableModel model, Collection rows) throws Exception {
    boolean filtered = model.getLimit().isFiltered();
    boolean cleared = model.getLimit().isCleared();

    if (!filtered || cleared) {
        return rows;
    }

    if (filtered) {
        Collection collection = new ArrayList();
        Predicate filterPredicate = new DateFilterPredicate(model);
        CollectionUtils.select(rows, filterPredicate, collection);

        return collection;
    }

    return rows;
}

From source file:org.openvpms.web.component.im.contact.ContactHelper.java

/**
 * Returns contacts for the specified party that match the predicate.
 *
 * @param party     the party/*from  ww w . java2  s  .co  m*/
 * @param predicate the predicate
 * @param sortNode  the node to sort on
 * @return the matching contacts
 */
private static List<Contact> getContacts(Party party, Predicate predicate, String sortNode) {
    List<Contact> result = new ArrayList<Contact>();
    CollectionUtils.select(party.getContacts(), predicate, result);
    if (result.size() > 1) {
        SortConstraint[] sort = { new NodeSortConstraint("preferred", false),
                new NodeSortConstraint(sortNode, true) };
        IMObjectSorter.sort(result, sort);
    }
    return result;
}

From source file:org.openvpms.web.component.im.layout.ArchetypeNodes.java

/**
 * Returns all nodes matching a predicate, in appropriate order.
 *
 * @param archetype the archetype// ww w.j  av  a  2  s  . com
 * @param predicate the predicate to select nodes
 * @return the matching nodes
 */
private List<NodeDescriptor> getNodes(ArchetypeDescriptor archetype, Predicate predicate) {
    List<NodeDescriptor> result = new ArrayList<NodeDescriptor>();
    CollectionUtils.select(archetype.getAllNodeDescriptors(), predicate, result);
    reorder(result);
    return result;
}

From source file:org.openvpms.web.component.im.lookup.LookupFilter.java

/**
 * Returns the filtered lookups.//from  w  w  w.  j a va 2s. co m
 *
 * @return the filtered lookups
 */
public List<Lookup> getLookups() {
    List<Lookup> result = new ArrayList<Lookup>();
    CollectionUtils.select(query.getLookups(), predicate, result);
    return result;
}

From source file:org.projectforge.business.fibu.kost.reporting.Report.java

/**
 * Diese initiale Liste der Buchungsliste wird sofort bezglich Exclude- und Include-Filter selektiert und das Ergebnis gesetzt.
 * @param buchungssaetze vor Selektion./*from   w w w.  j  a  v a 2  s  .c o m*/
 */
public void select(final List<BuchungssatzDO> list) {
    final Predicate regExpPredicate = new Predicate() {
        public boolean evaluate(final Object obj) {
            final BuchungssatzDO satz = (BuchungssatzDO) obj;
            final String kost1 = KostFormatter.format(satz.getKost1());
            final String kost2 = KostFormatter.format(satz.getKost2());

            // 1st of all the Blacklists
            if (match(reportObjective.getKost1ExcludeRegExpList(), kost1, false) == true) {
                return false;
            }
            if (match(reportObjective.getKost2ExcludeRegExpList(), kost2, false) == true) {
                return false;
            }
            // 2nd the whitelists
            final boolean kost1Match = match(reportObjective.getKost1IncludeRegExpList(), kost1, true);
            final boolean kost2Match = match(reportObjective.getKost2IncludeRegExpList(), kost2, true);
            return kost1Match == true && kost2Match == true;
        }
    };
    this.buchungssaetze = new ArrayList<BuchungssatzDO>();
    this.buchungssatzSet = new HashSet<BuchungssatzDO>();
    this.businessAssessment = null;
    this.businessAssessmentTable = null;
    this.childReports = null;
    this.duplicates = null;
    this.other = null;
    CollectionUtils.select(list, regExpPredicate, this.buchungssaetze);
    for (final BuchungssatzDO satz : this.buchungssaetze) {
        this.buchungssatzSet.add(satz);
    }
}