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

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

Introduction

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

Prototype

Predicate

Source Link

Usage

From source file:com.perceptive.epm.perkolcentral.businessobject.EmployeeBO.java

public String getSpecificRoleInScrumTeam() {
    if (CollectionUtils.exists(groups, new Predicate() {
        @Override/*from  w  w w .  ja v  a  2s. c o  m*/
        public boolean evaluate(Object o) {
            return ((GroupBO) o).getGroupId()
                    .equalsIgnoreCase(String.valueOf(GroupEnum.SCRUM_MASTERS.getCode()));
        }
    })) {
        return "SCRUM MASTER";
    }
    if (CollectionUtils.exists(groups, new Predicate() {
        @Override
        public boolean evaluate(Object o) {
            return ((GroupBO) o).getGroupId().equalsIgnoreCase(String.valueOf(GroupEnum.DEV_MANAGER.getCode()));
        }
    })) {
        return "DEVELOPMENT MANAGER";
    }
    if (CollectionUtils.exists(groups, new Predicate() {
        @Override
        public boolean evaluate(Object o) {
            return ((GroupBO) o).getGroupId().equalsIgnoreCase(String.valueOf(GroupEnum.VERTICAL_QA.getCode()));
        }
    })) {
        return "QA";
    }
    if (CollectionUtils.exists(groups, new Predicate() {
        @Override
        public boolean evaluate(Object o) {
            return ((GroupBO) o).getGroupId().equalsIgnoreCase(String.valueOf(GroupEnum.VERTICAL_TW.getCode()));
        }
    })) {
        return "TECH. WRITER";
    }
    if (CollectionUtils.exists(groups, new Predicate() {
        @Override
        public boolean evaluate(Object o) {
            return ((GroupBO) o).getGroupId().equalsIgnoreCase(String.valueOf(GroupEnum.VERTICAL_UX.getCode()));
        }
    })) {
        return "UX";
    }
    if (CollectionUtils.exists(groups, new Predicate() {
        @Override
        public boolean evaluate(Object o) {
            return ((GroupBO) o).getGroupId()
                    .equalsIgnoreCase(String.valueOf(GroupEnum.VERTICAL_DEV.getCode()));
        }
    })) {
        return "DEVELOPMENT";
    }
    return specificRoleInScrumTeam;
}

From source file:gov.nih.nci.ncicb.tcga.dcc.datareports.service.AliquotReportServiceImpl.java

public List<Aliquot> getFilteredAliquotList(final List<Aliquot> list, final String aliquot,
        final List<String> disease, final List<String> center, final List<String> platform,
        final String bcrBatch, final List<String> levelOne, final List<String> levelTwo,
        final List<String> levelThree) {
    StringBuilder strLog = new StringBuilder();
    strLog.append("Filter used: aliquot:").append(aliquot).append(" disease:").append(disease)
            .append(" center:").append(center).append(" platform:").append(platform).append(" bcrBatch:")
            .append(bcrBatch).append(" levelOne:").append(levelOne).append(" levelTwo:").append(levelTwo)
            .append(" levelThree:").append(levelThree);
    logger.debug(strLog);/*from  w w  w . j  av  a2s. co  m*/
    if (aliquot == null && disease == null && center == null && platform == null && bcrBatch == null
            && levelOne == null && levelTwo == null && levelThree == null) {
        return list; //quick test so we don't have to evaluate the predicates
    }
    //Cool predicates to do my sql behavior WHERE .. AND ... in java collections 
    List<Predicate> aliPredicateList = new LinkedList<Predicate>();
    aliPredicateList.add(new Predicate() {
        public boolean evaluate(Object o) {
            if (aliquot == null || "".equals(aliquot)) {
                return true;
            }
            return (((Aliquot) o).getAliquotId()).startsWith(aliquot);
        }
    });
    aliPredicateList.add(new Predicate() {
        public boolean evaluate(Object o) {
            if (bcrBatch == null || "".equals(bcrBatch)) {
                return true;
            }
            return bcrBatch.equals(((Aliquot) o).getBcrBatch());
        }
    });
    commonService.genORPredicateList(Aliquot.class, aliPredicateList, disease, DISEASE);
    commonService.genORPredicateList(Aliquot.class, aliPredicateList, center, CENTER);
    commonService.genORPredicateList(Aliquot.class, aliPredicateList, platform, PLATFORM);
    commonService.genORPredicateList(Aliquot.class, aliPredicateList, levelOne, LEVEL_ONE);
    commonService.genORPredicateList(Aliquot.class, aliPredicateList, levelTwo, LEVEL_TWO);
    commonService.genORPredicateList(Aliquot.class, aliPredicateList, levelThree, LEVEL_THREE);

    Predicate aliquotPredicates = PredicateUtils.allPredicate(aliPredicateList);
    List<Aliquot> fList = (List<Aliquot>) CollectionUtils.select(list, aliquotPredicates);
    return fList;
}

From source file:com.google.gwt.dev.shell.mac.WebKitDispatchAdapter.java

@SuppressWarnings("unchecked")
public String[] getFields() {
    try {// w w w  .  j a  va  2  s  .co  m
        DispatchClassInfo classInfo = classLoader.getClassInfoFromClassName(getTarget().getClass().getName());
        Collection<Field> selected = CollectionUtils.select(classInfo.getMembers(), new Predicate() {
            public boolean evaluate(Object object) {
                return object instanceof Field;
            }
        });
        String[] result = new String[selected.size()];
        int index = 0;
        for (Field field : selected) {
            String jsFieldName = "@" + field.getDeclaringClass().getName() + "::" + field.getName();
            result[index++] = Jsni.WBP_MEMBER + classLoader.getDispId(jsFieldName);
        }
        return result;
    } catch (Throwable e) {
        return new String[0];
    }
}

From source file:edu.common.dynamicextensions.xmi.XMIUtilities.java

/**
 * Finds and returns the first model element having the given
 * <code>name</code> in the <code>modelPackage</code>, returns
 * <code>null</code> if not found.
 *
 * @param modelPackage The modelPackage to search
 * @param name the name to find./*w w w  . j a v  a  2  s.  c  o  m*/
 * @return the found model element.
 */
public static Object find(org.omg.uml.UmlPackage modelPackage, final String name) {
    return CollectionUtils.find(

            modelPackage.getModelManagement().getModel().refAllOfType(), new Predicate() {

                public boolean evaluate(Object object) {
                    return (((ModelElement) object).getName()).equals(name);
                }
            });
}

From source file:com.exxonmobile.ace.hybris.test.job.AccountManagerJob.java

public void acctMgrApproveOrRejectAction(final String orderCode, final boolean approve) {
    final String decision = approve ? APPROVE.toString() : REJECT.toString();
    LOG.info(String.format("Attempting to apply decision: %s  on order: %s", orderCode, decision));

    final EmployeeModel employee = getUserService().getUserForUID(ACCOUNTMANAGERUID, EmployeeModel.class);

    final Collection<WorkflowActionModel> workFlowActionModelList = new ArrayList<WorkflowActionModel>(
            getB2bWorkflowIntegrationService().getWorkflowActionsForUser(employee));

    LOG.debug(ACCOUNTMANAGERUID + " has actions count:" + workFlowActionModelList.size());
    CollectionUtils.filter(workFlowActionModelList, new Predicate() {
        @Override/* w  ww  . j  a  va2  s .  c o m*/
        public boolean evaluate(final Object object) {
            final WorkflowActionModel workflowActionModel = (WorkflowActionModel) object;

            if (APPROVAL.name().equals(workflowActionModel.getQualifier())) {
                return CollectionUtils.exists(workflowActionModel.getAttachmentItems(), new Predicate() {
                    @Override
                    public boolean evaluate(final Object object) {
                        if (object instanceof OrderModel) {
                            LOG.debug("This approval action is for order " + ((OrderModel) object).getCode()
                                    + " vs " + orderCode);
                            return (orderCode.equals(((OrderModel) object).getCode()));
                        }
                        return false;
                    }
                });
            } else {
                return false;
            }
        }
    });

    LOG.debug(String.format("Employee %s has %s actions to %s for this order %s", employee.getUid(),
            Integer.toString(workFlowActionModelList.size()), decision, orderCode));

    for (final WorkflowActionModel workflowActionModel : workFlowActionModelList) {
        getB2bWorkflowIntegrationService().decideAction(workflowActionModel, decision);
        LOG.debug("Decided for ActionCode" + workflowActionModel.getCode() + " to " + decision);
    }
}

From source file:com.arkea.jenkins.openstack.heat.HOTPlayer.java

@SuppressWarnings("rawtypes")
@Override/*from w  w  w .  j a  v  a  2s.co m*/
public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) {

    // Specific logger with color
    ConsoleLogger cLog = new ConsoleLogger(listener.getLogger(), "HOT Player", bundle.isDebug());
    try {

        // Variable in context
        EnvVarsUtils eVU = new EnvVarsUtils(build, listener, cLog);

        // Global configuration
        HOTPlayerSettings hPS = (HOTPlayerSettings) Jenkins.getInstance()
                .getDescriptor(HOTPlayerSettings.class);

        // Project OpenStack to use
        ProjectOS projectOS = (ProjectOS) CollectionUtils.find(hPS.getProjects(), new Predicate() {
            public boolean evaluate(Object o) {
                return project.equals(((ProjectOS) o).getProject());
            }
        });

        // Test if the project is found
        if (projectOS != null) {

            // Client OpenStack inject during test or client failed
            if (clientOS == null || !clientOS.isConnectionOK()) {
                clientOS = new OpenStack4jClient(projectOS);
            }

            // Delete stack if it exists ?
            if (this.bundle.isExist()) {
                if (!StackOperationsUtils.deleteStack(eVU.getVar(bundle.getName()), clientOS, cLog,
                        hPS.getTimersOS())) {
                    return false;
                }
            }

            // Create stack
            if (!StackOperationsUtils.createStack(eVU, bundle, projectOS, clientOS, cLog, hPS.getTimersOS())) {
                return false;
            }
        } else {
            cLog.logError(Messages.project_notFound(project));
            return false;
        }

    } catch (Exception e) {
        cLog.logError(Messages.processing_failed(bundle.getName()) + ExceptionUtils.getStackTrace(e));
        return false;
    }
    return true;
}

From source file:flex2.compiler.mxml.gen.DescriptorGenerator.java

/**
 *
 *//*from  w  w w .  ja  v  a2  s. co m*/
private static void addDescriptorProperties(CodeFragmentList list, Model model,
        final Set<String> includePropNames, boolean includeDesignLayer, String indent) {
    //  ordinary properties
    Iterator propIter = includePropNames == null ? model.getPropertyInitializerIterator(false)
            : new FilterIterator(model.getPropertyInitializerIterator(false), new Predicate() {
                public boolean evaluate(Object obj) {
                    return includePropNames.contains(((NamedInitializer) obj).getName());
                }
            });

    //  visual children
    Iterator vcIter = (model instanceof MovieClip && ((MovieClip) model).hasChildren())
            ? ((MovieClip) model).children().iterator()
            : Collections.EMPTY_LIST.iterator();

    // designLayer ?
    Boolean hasDesignLayer = (includeDesignLayer && (model.layerParent != null)
            && model.getType().isAssignableTo(model.getStandardDefs().INTERFACE_IVISUALELEMENT));

    if (propIter.hasNext() || vcIter.hasNext() || hasDesignLayer) {
        if (!list.isEmpty()) {
            list.add(indent, ",", 0);
        }

        list.add(indent, "propertiesFactory: function():Object { return {", 0);
        indent += DescriptorGenerator.INDENT;

        while (propIter.hasNext()) {
            NamedInitializer init = (NamedInitializer) propIter.next();
            if (!init.isStateSpecific()) {
                list.add(indent, init.getName(), ": ", init.getValueExpr(),
                        (propIter.hasNext() || vcIter.hasNext() || hasDesignLayer ? "," : ""),
                        init.getLineRef());
            }
        }

        if (hasDesignLayer) {
            list.add(indent, "designLayer", ": ", model.layerParent.getId(), (vcIter.hasNext() ? "," : ""),
                    model.getXmlLineNumber());
        }

        if (vcIter.hasNext()) {
            list.add(indent, "childDescriptors: [", 0);

            // Generate each child descriptor unless the child as explicitly filtered out.
            boolean isFirst = true;
            while (vcIter.hasNext()) {
                VisualChildInitializer init = (VisualChildInitializer) vcIter.next();
                Model child = (MovieClip) init.getValue();
                if (child.isDescriptorInit()) {
                    if (!isFirst) {
                        list.add(indent, ",", 0);
                    }

                    addDescriptorInitializerFragments(list, child, indent + DescriptorGenerator.INDENT);
                    isFirst = false;
                }

            }

            list.add(indent, "]", 0);
        }

        indent = indent.substring(0, indent.length() - INDENT.length());
        list.add(indent, "}}", 0);
    }
}

From source file:com.perceptive.epm.perkolcentral.bl.EmployeeBL.java

public EmployeeBO getEmployeeByEmployeeUID(String employeeUID) throws ExceptionWrapper {
    try {/*from   w  ww . ja  va2s.c  o  m*/
        ArrayList<EmployeeBO> employeeBOArrayList = new ArrayList<EmployeeBO>(getAllEmployees().values());
        final String UID = employeeUID;
        return (EmployeeBO) CollectionUtils.find(employeeBOArrayList, new Predicate() {
            @Override
            public boolean evaluate(Object o) {
                return ((EmployeeBO) o).getEmployeeUid().trim().equalsIgnoreCase(UID.trim()); //To change body of implemented methods use File | Settings | File Templates.
            }
        });
    } catch (Exception ex) {
        throw new ExceptionWrapper(ex);
    }
}

From source file:hr.fer.zemris.vhdllab.platform.manager.workspace.DefaultWorkspaceManager.java

@Override
public File getFile(String projectName, final String fileName) {
    Validate.notNull(projectName, "Project name can't be null");
    Validate.notNull(fileName, "File name can't be null");
    String key = makeKey(projectName, fileName);
    if (getFileIdentifiers().containsKey(key)) {
        return getFileIdentifiers().get(key);
    }/*from w w  w .  j a v  a  2  s .  c  o m*/
    Set<File> predefinedFiles = getWorkspace().getPredefinedFiles();
    File found = (File) CollectionUtils.find(predefinedFiles, new Predicate() {
        @Override
        public boolean evaluate(Object object) {
            File predefined = (File) object;
            return predefined.getName().equalsIgnoreCase(fileName);
        }
    });
    return new File(found, getProject(projectName));
}

From source file:BackupRestoreTest.java

private static void checkRestoreTo(final String passwordData, final String passwordMeta,
        final Collection<String> repoPatern, List<String> argList) throws Exception {
    CipherProvider dataCipherProvider = new CipherProvider();
    dataCipherProvider.setPassword(passwordData);
    CipherProvider metaCipherProvider = new CipherProvider();
    metaCipherProvider.setPassword(passwordMeta);

    String repoPathStr = REPO_TST;
    Repository repository = new Repository(repoPathStr, dataCipherProvider, metaCipherProvider);

    VOConfig cfg = new VOConfig(REPO_TST, ID_BCK_TST, getExcl("*.excl"), getExcl("*Excl"), argList);

    BackupService backup = new BackupService(cfg, repository);
    final String bck = backup.run();

    // check repo content
    List<String> contentRepo = getContentDir(REPO_TST + File.separator + "data", false);
    printContent(contentRepo);/*from  w  w w  . j  av  a  2s .  c o m*/
    checkCollectionIn(repoPatern, contentRepo);

    RestoreService restore = new RestoreService(bck, repository, argList, RESTORE_TST);
    restore.run();

    // check new dir content
    List<String> contentRestore = getContentDir(RESTORE_TST, false);
    // TODO Lebeda - do check with date - on source tst files must be dat prepared on setup test
    printContent(contentRestore);
    Assert.assertEquals(16, contentRestore.size());
    Assert.assertTrue(0 == CollectionUtils.countMatches(contentRestore, new Predicate() {
        @Override
        public boolean evaluate(final Object object) {
            String s = (String) object;
            return StringUtils.contains(s, "excl");
        }
    }));
    Assert.assertTrue(CollectionUtils.isSubCollection(getContentRestorePatern(), contentRestore));
}