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.jbpm.kie.services.api.DeploymentIdResolver.java

@SuppressWarnings("unchecked")
public static Collection<String> matchDeployments(String deploymentId,
        Collection<String> availableDeployments) {
    Collection<String> matched = CollectionUtils.select(availableDeployments,
            new GroupAndArtifactMatchPredicate(deploymentId));

    return matched;
}

From source file:org.jenkins.plugins.appaloosa.AppaloosaPublisher.java

@Override
public Collection<? extends Action> getProjectActions(AbstractProject<?, ?> project) {
    ArrayList<AppaloosaBuildAction> actions = new ArrayList<AppaloosaBuildAction>();
    RunList<? extends AbstractBuild<?, ?>> builds = project.getBuilds();

    Collection predicated = CollectionUtils.select(builds, new Predicate() {
        public boolean evaluate(Object o) {
            Result r = ((AbstractBuild<?, ?>) o).getResult();
            return r != null && r.isBetterOrEqualTo(Result.SUCCESS);
        }/*w w w.j a va  2 s  . c om*/
    });

    ArrayList<AbstractBuild<?, ?>> filteredList = new ArrayList<AbstractBuild<?, ?>>(predicated);

    Collections.reverse(filteredList);
    for (AbstractBuild<?, ?> build : filteredList) {
        List<AppaloosaBuildAction> appaloosaActions = build.getActions(AppaloosaBuildAction.class);
        if (appaloosaActions != null && appaloosaActions.size() > 0) {
            for (AppaloosaBuildAction action : appaloosaActions) {
                actions.add(new AppaloosaBuildAction(action));
            }
            break;
        }
    }

    return actions;
}

From source file:org.jumpmind.db.platform.AbstractDdlBuilder.java

/**
 * Processes the changes. The default argument performs several passes:
 * <ol>// w  w w.  j  a v  a 2  s .  c  o m
 * <li>
 * {@link org.jumpmind.db.alter.RemoveForeignKeyChange} and
 * {@link org.jumpmind.db.alter.RemoveIndexChange} come first to allow for
 * e.g. subsequent primary key changes or column removal.</li>
 * <li>{@link org.jumpmind.db.alter.RemoveTableChange} comes after the
 * removal of foreign keys and indices.</li>
 * <li>These are all handled together:<br/>
 * {@link org.jumpmind.db.alter.RemovePrimaryKeyChange}<br/>
 * {@link org.jumpmind.db.alter.AddPrimaryKeyChange}<br/>
 * {@link org.jumpmind.db.alter.PrimaryKeyChange}<br/>
 * {@link org.jumpmind.db.alter.RemoveColumnChange}<br/>
 * {@link org.jumpmind.db.alter.AddColumnChange}<br/>
 * {@link org.jumpmind.db.alter.ColumnAutoIncrementChange} <br/>
 * {@link org.jumpmind.db.alter.ColumnDefaultValueChange} <br/>
 * {@link org.jumpmind.db.alter.ColumnRequiredChange}<br/>
 * {@link org.jumpmind.db.alter.ColumnDataTypeChange}<br/>
 * {@link org.jumpmind.db.alter.ColumnSizeChange}<br/>
 * The reason for this is that the default algorithm rebuilds the table for
 * these changes and thus their order is irrelevant.</li>
 * <li>{@link org.jumpmind.db.alter.AddTableChange}<br/>
 * needs to come after the table removal (so that tables of the same name
 * are removed) and before the addition of foreign keys etc.</li>
 * <li>{@link org.jumpmind.db.alter.AddForeignKeyChange} and
 * {@link org.jumpmind.db.alter.AddIndexChange} come last after
 * table/column/primary key additions or changes.</li>
 * </ol>
 */
@SuppressWarnings("unchecked")
protected void processChanges(Database currentModel, Database desiredModel, List<IModelChange> changes,
        StringBuilder ddl) {
    CallbackClosure callbackClosure = new CallbackClosure(this, "processChange",
            new Class[] { Database.class, Database.class, null, StringBuilder.class },
            new Object[] { currentModel, desiredModel, null, ddl });

    // 1st pass: removing external constraints and indices
    applyForSelectedChanges(changes, new Class[] { RemoveForeignKeyChange.class, RemoveIndexChange.class },
            callbackClosure);

    // 2nd pass: removing tables
    applyForSelectedChanges(changes, new Class[] { RemoveTableChange.class }, callbackClosure);

    // 3rd pass: changing the structure of tables
    Predicate predicate = new MultiInstanceofPredicate(new Class[] { RemovePrimaryKeyChange.class,
            AddPrimaryKeyChange.class, PrimaryKeyChange.class, RemoveColumnChange.class, AddColumnChange.class,
            ColumnAutoIncrementChange.class, ColumnDefaultValueChange.class, ColumnRequiredChange.class,
            ColumnDataTypeChange.class, ColumnSizeChange.class, CopyColumnValueChange.class });

    processTableStructureChanges(currentModel, desiredModel, CollectionUtils.select(changes, predicate), ddl);

    // 4th pass: adding tables
    applyForSelectedChanges(changes, new Class[] { AddTableChange.class }, callbackClosure);
    // 5th pass: adding external constraints and indices
    applyForSelectedChanges(changes, new Class[] { AddForeignKeyChange.class, AddIndexChange.class },
            callbackClosure);
}

From source file:org.kuali.kfs.fp.document.web.struts.AuxiliaryVoucherForm.java

/**
 * This method generates a proper list of valid accounting periods that the user can select from.
 *
 * @see org.kuali.kfs.fp.document.web.struts.VoucherForm#populateAccountingPeriodListForRendering()
 *//*from   ww  w  .ja va  2s.  c o  m*/
@Override
public void populateAccountingPeriodListForRendering() {
    // grab the list of valid accounting periods
    ArrayList accountingPeriods = new ArrayList(
            SpringContext.getBean(AccountingPeriodService.class).getOpenAccountingPeriods());
    // now, validate further, based on the rules from AuxiliaryVoucherDocumentRule
    ArrayList filteredAccountingPeriods = new ArrayList();
    filteredAccountingPeriods.addAll(
            CollectionUtils.select(accountingPeriods, new OpenAuxiliaryVoucherPredicate(this.getDocument())));
    // if our auxiliary voucher doc contains an accounting period already, make sure the collection has it too!
    if (this.getDocument() instanceof AuxiliaryVoucherDocument) {
        AuxiliaryVoucherDocument avDoc = (AuxiliaryVoucherDocument) this.getDocument();
        if (avDoc != null && avDoc.getAccountingPeriod() != null
                && !filteredAccountingPeriods.contains(avDoc.getAccountingPeriod())) {
            // this is most likely going to happen because the approver is trying
            // to approve a document after the grace period of an accounting period
            // or a fiscal year has switched over when the document was first created;
            // as such, it's probably a good bet that the doc's accounting period
            // belongs at the top of the list
            filteredAccountingPeriods.add(0, avDoc.getAccountingPeriod());
        }
    }
    // set into the form for rendering
    setAccountingPeriods(filteredAccountingPeriods);
    // set the chosen accounting period into the form
    populateSelectedVoucherAccountingPeriod();
}

From source file:org.kuali.mobility.computerlabs.dao.ComputerLabsDaoImpl.java

@Override
public Lab getLab(String labUid) {
    Lab myLab = null;/*from  w  w  w  . j a v a2 s  .c  om*/
    for (LabGroup g : getLabGroups()) {
        for (Location l : g.getLocations()) {
            Collection<? extends Lab> myLabs = CollectionUtils.select(l.getLabs(),
                    new LabPredicate(null, labUid));
            if (null != myLabs && myLabs.size() > 0) {
                myLab = (Lab) (myLabs.toArray())[0];
                break;
            }
        }
    }
    if (myLab == null) {
        LOG.error("Lab not found for UID " + labUid);
    }
    return myLab;
}

From source file:org.kuali.mobility.computerlabs.dao.ComputerLabsDaoImpl.java

@Override
public List<? extends Lab> getLabs(String locationId, String buildingCode) {
    List<? extends Lab> myLabs = new ArrayList<Lab>();
    for (LabGroup g : getLabGroups()) {
        Collection<? extends Location> myLocations = CollectionUtils.select(g.getLocations(),
                new LocationPredicate(locationId));
        for (Location l : myLocations) {
            myLabs.addAll(CollectionUtils.select(l.getLabs(), new LabPredicate(buildingCode, null)));
        }//from w  w  w.j a  v a  2  s  . co  m
    }
    return myLabs;
}

From source file:org.kuali.mobility.computerlabs.dao.ComputerLabsDaoImpl.java

@Override
public LabGroup getLabGroup(String groupId) {
    LabGroup myGroup = null;//from w  w w  .  ja v  a 2s  .  co  m
    Collection<? extends LabGroup> myGroups = CollectionUtils.select(getLabGroups(),
            new LabGroupPredicate(groupId));

    if (myGroups != null) {
        if (myGroups.size() > 1) {
            LOG.debug("Multiple groups found for id. This shouldn't happen.");
        } else {
            LabGroupTransform transform = new LabGroupTransform();
            for (Object obj : myGroups) {
                myGroup = transform.transform(obj);
            }
        }
    }
    return myGroup;
}

From source file:org.kuali.mobility.dining.service.DiningServiceImpl.java

@GET
@Path("/diningHallGroup")
@Override//from w w w .j av a  2  s.c om
public DiningHallGroup getDiningHallGroup(@QueryParam(value = "name") String name) {
    DiningHallGroup diningHallGroup = null;
    Collection<? extends DiningHallGroup> diningHallGroups = CollectionUtils
            .select(getDao().getDiningHallGroups(), new DiningHallNamePredicate(name));
    if (diningHallGroups.size() > 1) {
        ErrorMessage error = new ErrorMessage();
        error.setName("Ambiguous request");
        error.setDescription("Multiple dining halls found for request.");
        diningHallGroup = new DiningHallGroup();
    } else {
        diningHallGroup = (DiningHallGroup) ((diningHallGroups.toArray())[0]);
    }
    return diningHallGroup;
}

From source file:org.kuali.mobility.emergencyinfo.dao.EmergencyInfoWSDaoImpl.java

@Override
public List<? extends EmergencyInfo> findAllEmergencyInfoByCampus(String campus) {
    if (null == contacts) {
        initData();/*from ww  w  .  jav a2s.com*/
    }
    List<? extends EmergencyInfo> campusContacts = new ArrayList<EmergencyInfoImpl>();
    campusContacts.addAll(CollectionUtils.select(contacts, new CampusPredicate(campus)));
    return campusContacts;
}

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

@GET
@Path("/findEvent")
@Override/*from w ww. ja  v a2  s. c o  m*/
public EventImpl getEvent(@QueryParam(value = "campus") String campus,
        @QueryParam(value = "categoryId") String categoryId, @QueryParam(value = "eventId") String eventId) {
    Event event;

    getDao().initData(campus, categoryId);

    List<Event> events = (List<Event>) CollectionUtils.select(getDao().getEvents(),
            new EventPredicate(campus, categoryId, eventId));

    if (events == null || events.isEmpty()) {
        LOG.info("No events matched the criteria.");
        event = null;
    } else if (events.size() > 1) {
        LOG.info("Multiple events found that match the criteria.");
        event = events.get(0);
    } else {
        event = events.get(0);
    }

    return (EventImpl) (new EventTransform().transform(event));
}