Example usage for org.apache.commons.collections Predicate evaluate

List of usage examples for org.apache.commons.collections Predicate evaluate

Introduction

In this page you can find the example usage for org.apache.commons.collections Predicate evaluate.

Prototype

public boolean evaluate(T object);

Source Link

Document

Use the specified parameter to perform a test that returns true or false.

Usage

From source file:au.edu.uq.cmm.paul.grabber.Analyser.java

private Statistics gatherStats(List<Group> grouped, Predicate predicate) {
    int datasetsInFolder = 0;
    int datasetsInDatabase = 0;
    int datasetsUnmatchedInFolder = 0;
    int groupsUnmatchedInDatabase = 0;
    int groupsWithDuplicatesInDatabase = 0;
    int groupsInDatabase = 0;
    for (Group group : grouped) {
        if (group.getInFolder() != null && predicate.evaluate(group.getInFolder())) {
            datasetsInFolder++;/*from w ww  .  ja  va2 s .  co  m*/
            if (group.getAllInDatabase().size() == 0) {
                datasetsUnmatchedInFolder++;
            }
        }
        int inDatabase = 0;
        boolean matched = false;
        for (DatasetMetadata dataset : group.getAllInDatabase()) {
            if (predicate.evaluate(dataset)) {
                inDatabase++;
                if (group.inFolder != null && matches(group.inFolder, dataset)) {
                    matched = true;
                }
            }
        }
        datasetsInDatabase += inDatabase;
        if (!matched && group.inFolder != null) {
            groupsUnmatchedInDatabase++;
        }
        if (inDatabase > 1) {
            groupsWithDuplicatesInDatabase++;
        }
        if (inDatabase > 0) {
            groupsInDatabase++;
        }
    }
    return new Statistics(datasetsInFolder, datasetsInDatabase, groupsInDatabase,
            groupsWithDuplicatesInDatabase, datasetsUnmatchedInFolder, groupsUnmatchedInDatabase);
}

From source file:module.workflow.domain.utils.WorkflowCommentCounter.java

/**
 * @param user user// w  w  w.  jav a2s. c o m
 * @param className classname
 * @return the processes of unread comments for the given person for the
 *         given classToFilter type of process NOTE: It relies on the logs
 *         of the user to retrieve the comments (as it should be more
 *         efficient and there is a direct relation between a comment and a
 *         log)
 */
public Set<WorkflowProcess> getProcessesWithUnreadComments(final User user, final String className) {

    Set<WorkflowProcess> processes = new HashSet<WorkflowProcess>();
    Predicate searchPredicate = new Predicate() {

        @Override
        public boolean evaluate(Object arg0) {
            if (className != null && classToFilter.toString().contentEquals(className)) {
                return classToFilter.isAssignableFrom(arg0.getClass())
                        && ((WorkflowProcess) arg0).hasUnreadCommentsForUser(user);
            } else if (className != null) {
                return false;
            }
            return classToFilter.isAssignableFrom(arg0.getClass())
                    && ((WorkflowProcess) arg0).hasUnreadCommentsForUser(user);
        }
    };

    for (WorkflowLog log : user.getUserLogsSet()) {
        WorkflowProcess process = log.getProcess();
        if (searchPredicate.evaluate(process)) {
            processes.add(process);
        }
    }
    return processes;

}

From source file:com.projity.pm.dependency.DependencyService.java

/**
 * Connect tasks sequentially.//from w  w w.  ja v  a  2s  .  c o m
 * Circularities will be tested, and an exception thrown if any circularity would occur
 *
 * @param tasks
 * @param eventSource
 * @throws InvalidAssociationException
 */
public void connect(List tasks, Object eventSource, Predicate canBeSuccessorCondition)
        throws InvalidAssociationException {
    ArrayList newDependencies = new ArrayList();
    // try making new dependencies between all items earlier to all items later, thereby checking all possible circularities
    HasDependencies pred;
    HasDependencies succ;
    Object temp;
    for (int i = 0; i < tasks.size() - 1; i++) {
        temp = tasks.get(i);
        if (!(temp instanceof HasDependencies))
            continue;
        pred = (HasDependencies) temp;
        for (int j = i + 1; j < tasks.size(); j++) {
            temp = tasks.get(j);
            if (!(temp instanceof HasDependencies))
                continue;
            succ = (HasDependencies) temp;
            if (canBeSuccessorCondition != null && !canBeSuccessorCondition.evaluate(succ)) // allow exclusion of certain nodes that we don't want to be successors
                continue;
            if (succ.getPredecessorList().findLeft(pred) != null) // if dependency already exists, skip it
                continue;
            if (ClassUtils.isObjectReadOnly(succ))
                continue;
            Dependency test = Dependency.getInstance(pred, succ, DependencyType.FS, 0); // make a new one
            test.testValid(false); // test for circularity, throws if bad
            if (j == i + 1) // only add sequential ones
                newDependencies.add(test);
        }
    }
    Iterator d = newDependencies.iterator();
    while (d.hasNext()) {
        connect((Dependency) d.next(), eventSource);
    }

}

From source file:com.projity.exchange.ServerFileImporter.java

protected void prepareResources(List srcResources, Predicate resourceFilter, boolean resourceDescriptorsOnly)
        throws Exception {

    ResourceMappingForm form = getResourceMapping();
    if (form == null)
        return;/* w  ww. j a  va2  s .c o m*/

    //server resources
    Vector projityResources = new Vector();
    EnterpriseResourceData unassigned = new EnterpriseResourceData();
    unassigned.setUniqueId(EnterpriseResource.UNASSIGNED_ID);
    unassigned.setName(Messages.getString("Text.Unassigned")); //$NON-NLS-1$
    form.setUnassignedResource(unassigned);
    projityResources.add(unassigned);
    try {
        Session session = SessionFactory.getInstance().getSession(false);
        projityResources.addAll((Collection) SessionFactory.call(session,
                resourceDescriptorsOnly ? "retrieveResourceDescriptors" : "retrieveResourceHierarchy", null,
                null));
        if (projityResources != null && projityResources.size() > 0)
            form.setUnassignedResource(projityResources.get(0));
    } catch (Exception e) {
        form.setLocal(true);
        return;
    }
    form.setResources(projityResources);

    //imported resources
    List resourcesToMap = new ArrayList();
    Object resource;
    if (srcResources != null)
        for (Iterator i = srcResources.iterator(); i.hasNext();) {
            resource = i.next();
            if (resourceFilter == null || resourceFilter.evaluate(resource))
                resourcesToMap.add(resource);
        }
    form.setImportedResources(resourcesToMap);

    MergeField mergeField = new ResourceMappingForm.MergeField("name", "name", "name"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    form.addMergeField(mergeField);
    //      if (!form.isJunit()) //claur
    //         form.setMergeField(mergeField);
    mergeField = new ResourceMappingForm.MergeField("emailAddress", "emailAddress", "email"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    form.addMergeField(mergeField);
    mergeField = new ResourceMappingForm.MergeField("uniqueId", "externalId", "id"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    form.addMergeField(mergeField);
}

From source file:net.sourceforge.fenixedu.domain.CurricularCourse.java

@Override
public void applyToCurricularCourses(final ExecutionYear executionYear, final Predicate predicate) {
    predicate.evaluate(this);
}

From source file:module.siadap.domain.wrappers.UnitSiadapWrapper.java

private void getUnitAttachedPersons(Unit unit, Collection<PersonSiadapWrapper> employees,
        boolean continueToSubunits, Predicate predicate, Collection<AccountabilityType> unitAccTypesToUse,
        AccountabilityType... accountabilities) {

    UnitSiadapWrapper wrapper = new UnitSiadapWrapper(unit, getYear());
    Collection<Person> children = wrapper.getChildPersons(accountabilities);

    for (Person person : children) {
        PersonSiadapWrapper personWrapper = new PersonSiadapWrapper(person, getConfiguration().getYear());
        if (predicate == null || predicate.evaluate(personWrapper)) {
            employees.add(personWrapper);
        }//from  ww w . j a  va 2  s  . c  o m
    }

    if (continueToSubunits) {
        for (Unit subUnit : wrapper.getChildUnits(unitAccTypesToUse.toArray(new AccountabilityType[0]))) {
            getUnitAttachedPersons(subUnit, employees, continueToSubunits, predicate, unitAccTypesToUse,
                    accountabilities);
        }
    }
}

From source file:com.phoenixst.plexus.DefaultGraph.java

public Object getNode(Predicate nodePredicate) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(instanceString + ".getNode( " + nodePredicate + " )");
    }/*from  www.jav  a2  s . c o  m*/
    Object node;

    if (nodePredicate == null || nodePredicate == TruePredicate.INSTANCE) {
        Iterator i = nodeMap.keySet().iterator();
        node = i.hasNext() ? i.next() : null;

    } else if (nodePredicate == FalsePredicate.INSTANCE) {
        node = null;

    } else if (nodePredicate instanceof EqualPredicate) {
        Object testNode = ((EqualPredicate) nodePredicate).getTestObject();
        AdjacencyList adj = (AdjacencyList) nodeMap.get(testNode);
        node = (adj != null) ? adj.node : null;

    } else {
        node = null;
        for (Iterator i = nodeMap.keySet().iterator(); i.hasNext();) {
            Object testNode = i.next();
            if (nodePredicate.evaluate(testNode)) {
                node = testNode;
                break;
            }
        }
    }

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("  " + instanceString + ".getNode() returning " + node);
    }
    return node;
}

From source file:org.apache.atlas.repository.store.graph.AtlasTypeDefGraphStore.java

@Override
public AtlasTypesDef searchTypesDef(SearchFilter searchFilter) throws AtlasBaseException {
    final AtlasTypesDef typesDef = new AtlasTypesDef();
    Predicate searchPredicates = FilterUtil.getPredicateFromSearchFilter(searchFilter);

    for (AtlasEnumType enumType : typeRegistry.getAllEnumTypes()) {
        if (searchPredicates.evaluate(enumType)) {
            typesDef.getEnumDefs().add(enumType.getEnumDef());
        }//from ww  w.  j  a  va 2 s.  c om
    }

    for (AtlasStructType structType : typeRegistry.getAllStructTypes()) {
        if (searchPredicates.evaluate(structType)) {
            typesDef.getStructDefs().add(structType.getStructDef());
        }
    }

    for (AtlasClassificationType classificationType : typeRegistry.getAllClassificationTypes()) {
        if (searchPredicates.evaluate(classificationType)) {
            typesDef.getClassificationDefs().add(classificationType.getClassificationDef());
        }
    }

    for (AtlasEntityType entityType : typeRegistry.getAllEntityTypes()) {
        if (searchPredicates.evaluate(entityType)) {
            typesDef.getEntityDefs().add(entityType.getEntityDef());
        }
    }

    return typesDef;
}

From source file:org.apache.cayenne.ashwood.graph.FilterArcIterator.java

public FilterArcIterator(ArcIterator<E, V> iterator, Predicate acceptOrigin, Predicate acceptDestination,
        Predicate acceptArc) {//  w  w  w. j  a va2s .  c  om

    this.iterator = iterator;
    this.acceptOrigin = acceptOrigin;
    this.acceptDestination = acceptDestination;
    this.acceptArc = acceptArc;
    nextOrigin = iterator.getOrigin();
    if (!acceptOrigin.evaluate(nextOrigin))
        nextOrigin = null;
    nextDst = iterator.getDestination();
    if (!acceptDestination.evaluate(nextDst))
        nextDst = null;
}

From source file:org.apache.cayenne.modeler.dialog.autorelationship.InferRelationshipsControllerBase.java

public boolean updateSelection(Predicate predicate) {
    boolean modified = false;

    for (InferredRelationship entity : inferredRelationships) {
        boolean select = predicate.evaluate(entity);

        if (select) {
            if (selectedEntities.add(entity)) {
                modified = true;/*from  w  ww.j  av a 2  s. com*/
            }
        } else {
            if (selectedEntities.remove(entity)) {
                modified = true;
            }
        }
    }

    if (modified) {
        firePropertyChange(SELECTED_PROPERTY, null, null);
    }

    return modified;
}