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:eu.delving.services.TestDataSetCycle.java

@Test
public void testHarvestCycle() throws IOException, FileStoreException, MetadataException {
    // import//from w w w .java2  s  . c  om
    Ear importEar = new Ear("Import First Time");
    factory.getDataSetStore().importFile(MockInput.sampleFile(), importEar);
    Assert.assertTrue("import first time", importEar.getResultBoolean());
    Facts facts = Facts.read(new FileInputStream(FACTS_FILE));
    factory.getDataSetStore().setFacts(facts);
    // upload
    DataSetClient client = new DataSetClient(new ClientContext());
    Ear uploadFactsEar = new Ear("UploadFacts");
    client.uploadFile(FileType.FACTS, MockFileStoreFactory.SPEC, FACTS_FILE, uploadFactsEar);
    Assert.assertTrue("upload facts", uploadFactsEar.getResultBoolean());
    Ear uploadSourceEar = new Ear("UploadSource First Time");
    client.uploadFile(FileType.SOURCE, MockFileStoreFactory.SPEC, factory.getDataSetStore().getSourceFile(),
            uploadSourceEar);
    Assert.assertTrue("upload source first time", uploadSourceEar.getResultBoolean());
    // harvest
    Harvester harvester = new Harvester();
    Harvey harvey = new Harvey("first");
    harvester.perform(harvey);
    Assert.assertTrue("harvest", harvey.waitUntilFinished());
    // import again
    importEar = new Ear("Import Again");
    factory.getDataSetStore().importFile(getHarvestedFile("first"), importEar);
    Assert.assertTrue("import again", harvey.waitUntilFinished());
    // change facts
    facts = factory.getDataSetStore().getFacts();
    SourceStream.adjustPathsForHarvest(facts);
    factory.getDataSetStore().setFacts(facts);
    uploadFactsEar = new Ear("UploadFacts Again");
    client.uploadFile(FileType.FACTS, MockFileStoreFactory.SPEC, factory.getDataSetStore().getFactsFile(),
            uploadFactsEar);
    Assert.assertTrue("upload facts", uploadFactsEar.getResultBoolean());
    // upload source again
    uploadSourceEar = new Ear("UploadSource Again");
    client.uploadFile(FileType.SOURCE, MockFileStoreFactory.SPEC, factory.getDataSetStore().getSourceFile(),
            uploadSourceEar);
    Assert.assertTrue("upload source again", uploadSourceEar.getResultBoolean());
    // harvest again
    harvey = new Harvey("again");
    harvester.perform(harvey);
    Assert.assertTrue("harvest again", harvey.waitUntilFinished());
    // compare
    Assert.assertEquals("harvested files different sizes", getHarvestedFile("first").length(),
            getHarvestedFile("again").length());
    List<String> firstLines = FileUtils.readLines(getHarvestedFile("first"), "UTF-8");
    List<String> againLines = FileUtils.readLines(getHarvestedFile("again"), "UTF-8");
    Predicate predicate = new Predicate() {
        @Override
        public boolean evaluate(Object o) {
            return !((String) o).contains("<datestamp>");
        }
    };
    CollectionUtils.filter(firstLines, predicate);
    CollectionUtils.filter(againLines, predicate);
    Assert.assertEquals("lines remaining are different", firstLines.size(), againLines.size());
    for (int walk = 0; walk < firstLines.size(); walk++) {
        Assert.assertEquals("Line " + walk + " different", firstLines.get(walk), againLines.get(walk));
    }
}

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> getLicensesRequestedByMe(String employeeUIDWhoRequestedLicense)
        throws ExceptionWrapper {
    try {//  w  w  w .  j  a  va 2  s .  co  m
        ArrayList<Imagenowlicenses> imagenowlicensesArrayList = new ArrayList<Imagenowlicenses>(
                imageNowLicenseDataAccessor.getAllImageNowLicensesByRequestor(employeeUIDWhoRequestedLicense)
                        .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:de.hybris.platform.b2bacceleratorfacades.order.impl.DefaultB2BCheckoutFacade.java

@Override
public List<B2BCostCenterData> getActiveVisibleCostCenters() {
    final Collection costCenters = CollectionUtils.select(b2bCostCenterService.getAllCostCenters(),
            new Predicate() {
                @Override//from ww w . ja v  a  2  s . c o m
                public boolean evaluate(final Object object) {
                    return ((B2BCostCenterModel) object).getActive().booleanValue();
                }
            });
    return Converters.convertAll(costCenters, getB2bCostCenterConverter());
}

From source file:net.sourceforge.fenixedu.domain.student.importation.ExportExistingStudentsFromImportationProcess.java

public static List<DgesStudentImportationProcess> readPendingJobs(final ExecutionYear executionYear) {
    List<DgesStudentImportationProcess> jobList = new ArrayList<DgesStudentImportationProcess>();

    CollectionUtils.select(executionYear.getDgesBaseProcessSet(), new Predicate() {

        @Override/*from   w  w  w  . ja  va  2s. c om*/
        public boolean evaluate(Object arg0) {
            return (arg0 instanceof ExportExistingStudentsFromImportationProcess)
                    && ((QueueJob) arg0).getIsNotDoneAndNotCancelled();
        }
    }, jobList);

    return jobList;
}

From source file:net.sourceforge.fenixedu.dataTransferObject.CurricularCourseScopesForPrintDTO.java

private CurricularYearForPrintDTO getSelectedCurricularYear(final InfoCurricularCourseScope scope,
        DegreeCurricularPlanForPrintDTO selectedCurricularPlan) {
    CurricularYearForPrintDTO selectedCurricularYear = (CurricularYearForPrintDTO) CollectionUtils
            .find(selectedCurricularPlan.getYears(), new Predicate() {

                @Override/*w w  w.  j  av a2 s  .com*/
                public boolean evaluate(Object arg0) {
                    CurricularYearForPrintDTO curricularYearForPrintDTO = (CurricularYearForPrintDTO) arg0;
                    if (curricularYearForPrintDTO.getYear()
                            .equals(scope.getInfoCurricularSemester().getInfoCurricularYear().getYear())) {
                        return true;
                    }

                    return false;
                }

            });
    if (selectedCurricularYear == null) {
        selectedCurricularYear = new CurricularYearForPrintDTO(
                scope.getInfoCurricularSemester().getInfoCurricularYear().getYear());
        selectedCurricularPlan.getYears().add(selectedCurricularYear);

    }

    return selectedCurricularYear;
}

From source file:de.hybris.platform.b2bacceleratorfacades.order.populators.B2BUnitPopulator.java

protected B2BUnitData populateUnitRelations(final B2BUnitModel source, final B2BUnitData target) {
    // unit's budgets
    if (CollectionUtils.isNotEmpty(source.getBudgets())) {
        target.setBudgets(Converters.convertAll(source.getBudgets(), getB2BBudgetConverter()));
    }//ww  w  . j a  va 2  s.c o  m

    // unit's cost centers
    if (CollectionUtils.isNotEmpty(source.getCostCenters())) {
        target.setCostCenters(Converters.convertAll(
                CollectionUtils.select(source.getCostCenters(),
                        new BeanPropertyValueEqualsPredicate(B2BCostCenterModel.ACTIVE, Boolean.TRUE)),
                getB2BCostCenterConverter()));
    }

    // unit approvers
    if (CollectionUtils.isNotEmpty(source.getApprovers())) {
        final UserGroupModel approverGroup = userService.getUserGroupForUID(B2BConstants.B2BAPPROVERGROUP);
        target.setApprovers(
                Converters.convertAll(CollectionUtils.select(source.getApprovers(), new Predicate() {
                    @Override
                    public boolean evaluate(final Object object) {
                        final B2BCustomerModel b2bCustomerModel = (B2BCustomerModel) object;
                        return userService.isMemberOfGroup(b2bCustomerModel, approverGroup);
                    }
                }), getB2BCustomerConverter()));
    }

    // unit addresses
    if (CollectionUtils.isNotEmpty(source.getAddresses())) {
        target.setAddresses(Converters.convertAll(source.getAddresses(), getAddressConverter()));
    }

    // unit's  customers
    final Collection<B2BCustomerModel> b2BCustomers = getB2BUnitService().getUsersOfUserGroup(source,
            B2BConstants.B2BCUSTOMERGROUP, false);
    if (CollectionUtils.isNotEmpty(b2BCustomers)) {
        target.setCustomers(Converters.convertAll(b2BCustomers, getB2BCustomerConverter()));
    }

    // unit's  managers
    final Collection<B2BCustomerModel> managers = getB2BUnitService().getUsersOfUserGroup(source,
            B2BConstants.B2BMANAGERGROUP, false);
    if (CollectionUtils.isNotEmpty(managers)) {
        target.setManagers(Converters.convertAll(managers, getB2BCustomerConverter()));
    }

    // unit's administrators
    final Collection<B2BCustomerModel> administrators = getB2BUnitService().getUsersOfUserGroup(source,
            B2BConstants.B2BADMINGROUP, false);
    if (CollectionUtils.isNotEmpty(administrators)) {
        target.setAdministrators(Converters.convertAll(administrators, getB2BCustomerConverter()));
    }

    final Collection<PrincipalModel> accountManagers = new HashSet<PrincipalModel>();
    if (source.getAccountManager() != null) {
        accountManagers.add(source.getAccountManager());
    }
    if (CollectionUtils.isNotEmpty(source.getAccountManagerGroups())) {
        for (final UserGroupModel userGroupModel : source.getAccountManagerGroups()) {
            accountManagers.addAll(userGroupModel.getMembers());
        }
    }
    if (CollectionUtils.isNotEmpty(accountManagers)) {
        target.setAccountManagers(Converters.convertAll(accountManagers, getPrincipalConverter()));
    }

    return target;
}

From source file:edu.northwestern.bioinformatics.studycalendar.web.subject.SubjectCentricScheduleController.java

@SuppressWarnings({ "unchecked" })
private boolean canUpdateSchedule(List<UserStudySubjectAssignmentRelationship> assignments) {
    Collection<UserStudySubjectAssignmentRelationship> update = select(assignments, new Predicate() {
        public boolean evaluate(Object o) {
            UserStudySubjectAssignmentRelationship r = (UserStudySubjectAssignmentRelationship) o;
            return r.getCanUpdateSchedule();
        }// w w  w  .ja v a2  s .c om
    });

    return isNotEmpty(update);
}

From source file:com.architexa.diagrams.relo.jdt.parts.MethodEditPart.java

@Override
public void buildContextMenu(IMenuManager menu) {

    if (this.getModel() instanceof UserCreatedFragment) {
        super.buildContextMenu(menu);
        return;//from  w  w w  .jav a2  s .c  o  m
    }

    IAction action;

    action = new Action("Open in Embedded Java Editor") {
        @Override
        public void run() {
            MethodEditPart.this.execute(MethodEditPart.this.getExpandCmd());
            CompoundCommand actionCmd = new CompoundCommand();
            MethodEditPart.this.realizeParent(actionCmd);
            if (actionCmd.size() > 0)
                MethodEditPart.this.execute(actionCmd);
        }
    };
    menu.appendToGroup(RSEContextMenuProvider.GROUP_RSE_TOOLS, action);

    menu.appendToGroup(RSEContextMenuProvider.GROUP_RSE_TOOLS,
            getRelAction("Show Called Methods", DirectedRel.getFwd(RJCore.calls)));
    menu.appendToGroup(RSEContextMenuProvider.GROUP_RSE_TOOLS,
            getRelAction("Show Calling Methods", DirectedRel.getRev(RJCore.calls)));
    Predicate refPred = new Predicate() {
        Resource methodRes = getElementRes();

        public boolean evaluate(Object arg0) { // arg0 is a Type this method references
            if (!(arg0 instanceof Resource))
                return true;

            // Don't show references from this
            // method to a class containing it
            Resource parent = methodRes;
            while (parent != null) {
                if (arg0.equals(parent))
                    return false;
                parent = (Resource) getRepo().getStatement((Resource) null, RSECore.contains, parent)
                        .getSubject();
            }
            return true;
        }
    };
    menu.appendToGroup(RSEContextMenuProvider.GROUP_RSE_TOOLS,
            getRelAction("Show Referenced Types", DirectedRel.getFwd(RJCore.refType), refPred));
    menu.appendToGroup(RSEContextMenuProvider.GROUP_RSE_TOOLS,
            getRelAction("Show Referencing Methods", DirectedRel.getRev(RJCore.refType)));

    action = new Action("Show Declaring Class") {
        @Override
        public void run() {
            CompoundCommand actionCmd = new CompoundCommand();
            MethodEditPart.this.realizeParent(actionCmd);
            if (actionCmd.size() > 0)
                MethodEditPart.this.execute(actionCmd);
        }
    };
    menu.appendToGroup(RSEContextMenuProvider.GROUP_RSE_TOOLS, action);

    // Calling super last because this will create the java doc actions and 
    // we want them at the bottom of the context menu group not the beginning

    // add separator before java doc actions
    menu.appendToGroup(RSEContextMenuProvider.GROUP_RSE_TOOLS, new Separator());
    super.buildContextMenu(menu);
}

From source file:net.sourceforge.fenixedu.domain.student.importation.ExportDegreeCandidaciesByDegreeForPasswordGeneration.java

public static List<ExportDegreeCandidaciesByDegreeForPasswordGeneration> readDoneJobs(
        final ExecutionYear executionYear) {
    List<ExportDegreeCandidaciesByDegreeForPasswordGeneration> jobList = new ArrayList<ExportDegreeCandidaciesByDegreeForPasswordGeneration>();

    CollectionUtils.select(executionYear.getDgesBaseProcessSet(), new Predicate() {

        @Override//from ww  w. jav  a 2  s .co m
        public boolean evaluate(Object arg0) {
            return (arg0 instanceof ExportDegreeCandidaciesByDegreeForPasswordGeneration)
                    && ((QueueJob) arg0).getDone();
        }
    }, jobList);

    return jobList;
}

From source file:de.hybris.platform.acceleratorservices.cronjob.SiteMapMediaJob.java

protected SiteMapGenerator getGeneratorForSiteMapPage(final SiteMapPageEnum siteMapPageEnum) {

    return (SiteMapGenerator) CollectionUtils.find(getGenerators(), new Predicate() {
        @Override//from w w  w  . j a  v a  2s . c o m
        public boolean evaluate(final Object o) {
            return ((SiteMapGenerator) o).getSiteMapPageEnum().equals(siteMapPageEnum);
        }
    });
}