Example usage for org.apache.commons.collections PredicateUtils allPredicate

List of usage examples for org.apache.commons.collections PredicateUtils allPredicate

Introduction

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

Prototype

public static Predicate allPredicate(Collection predicates) 

Source Link

Document

Create a new Predicate that returns true only if all of the specified predicates are true.

Usage

From source file:adalid.commons.util.ColUtils.java

public static <T> Collection<T> allFilter(Collection<T> collection, Predicate... predicates) {
    if (collection == null || collection.isEmpty() || predicates == null) {
        return collection;
    } else {/*from  ww w.j  av  a  2  s .c o m*/
        //          Collection<T> list = new ArrayList<T>();
        //          list.addAll(collection);
        Collection<T> list = new ArrayList<>(collection);
        Predicate predicate = PredicateUtils.allPredicate(predicates);
        CollectionUtils.filter(list, predicate);
        return list;
    }
}

From source file:com.googelcode.jpractices.Person.java

/**
     *// w  w w .  ja  va  2s.  c  o  m
     * Here we are adding multiple predicate
     * filters the collection so that final person object will contain
     * firstName as "ganesh" & lastName as "gowtham"
     */
    void filterDataUsingMultipleCriteria() {
        EqualPredicate firstNameEqlPredicate = new EqualPredicate("ganesh");
        BeanPredicate firtsNameBeanPredicate = new BeanPredicate("firstName", firstNameEqlPredicate);
        EqualPredicate lastNameEqlPredicate2 = new EqualPredicate("gowtham");
        BeanPredicate lastNameBeanPredicate2 = new BeanPredicate("lastName", lastNameEqlPredicate2);
        Predicate[] allPredicateArray = { firtsNameBeanPredicate, lastNameBeanPredicate2 };
        Predicate allPredicate = PredicateUtils.allPredicate(allPredicateArray);
        Collection<Person> filteredCollection = CollectionUtils.select(personList, allPredicate);

        for (Person person : filteredCollection) {
            System.out.println(person);
        }
    }

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

public List<AliquotIdBreakdown> getFilteredAliquotIdBreakdownList(final List<AliquotIdBreakdown> list,
        final String aliquotId, final String analyteId, final String sampleId, final String participantId) {
    StringBuilder strLog = new StringBuilder();
    strLog.append("Filter used: aliquotId:").append(aliquotId).append(" analyteId:").append(analyteId)
            .append(" sampleId:").append(sampleId).append(" participantId:").append(participantId);
    logger.debug(strLog);//  w ww.  j  av a 2 s  . c  o m
    if (aliquotId == null && analyteId == null && sampleId == null && participantId == 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> bbPredicateList = new LinkedList<Predicate>();
    bbPredicateList.add(processAliquotIdBreakdownPredicates("aliquotId", aliquotId, ""));
    bbPredicateList.add(processAliquotIdBreakdownPredicates("analyteId", analyteId, ""));
    bbPredicateList.add(processAliquotIdBreakdownPredicates("sampleId", sampleId, ""));
    bbPredicateList.add(processAliquotIdBreakdownPredicates("participantId", participantId, ""));
    Predicate biospecimenBreakdownPredicates = PredicateUtils.allPredicate(bbPredicateList);
    List<AliquotIdBreakdown> fList = (List<AliquotIdBreakdown>) CollectionUtils.select(list,
            biospecimenBreakdownPredicates);
    return fList;
}

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

@Override
public List<PendingUUID> getFilteredPendingUUIDList(final List<PendingUUID> list, final List<String> bcr,
        final List<String> center, final String batch, final String plateId) {
    final StringBuilder strLog = new StringBuilder();
    strLog.append("Filter used: Bcr:").append(bcr).append(" Center:").append(center).append(" Batch:")
            .append(batch).append(" Plate Id:").append(plateId);
    logger.debug(strLog);//from  w  w  w.java 2 s.  com
    if (bcr == null && center == null && batch == null && plateId == null) {
        return list;
    }
    final List<Predicate> pUUIDPredicateList = new LinkedList<Predicate>();
    pUUIDPredicateList.add(new Predicate() {
        public boolean evaluate(Object o) {
            if (batch == null || "".equals(batch)) {
                return true;
            }
            return batch.equals(((PendingUUID) o).getBatchNumber());
        }
    });
    pUUIDPredicateList.add(new Predicate() {
        public boolean evaluate(Object o) {
            if (plateId == null || "".equals(plateId)) {
                return true;
            }
            return plateId.equals(((PendingUUID) o).getPlateId());
        }
    });
    commonService.genORPredicateList(PendingUUID.class, pUUIDPredicateList, bcr, BCR);
    commonService.genORPredicateList(PendingUUID.class, pUUIDPredicateList, center, CENTER);
    final Predicate pendingUUIDPredicates = PredicateUtils.allPredicate(pUUIDPredicateList);
    final List<PendingUUID> fList = (List<PendingUUID>) CollectionUtils.select(list, pendingUUIDPredicates);
    return fList;
}

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

public List<LatestArchive> getFilteredLatestArchiveList(final List<LatestArchive> list,
        final List<String> archiveType, final String dateFromStr, final String dateToStr) {
    final StringBuilder strLog = new StringBuilder();
    final DateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT_US_STRING);
    strLog.append("Filter used: archiveType:").append(archiveType).append(" dateFrom:").append(dateFromStr)
            .append(" dateTo:").append(dateToStr);
    logger.debug(strLog);/*from  w w  w . j  a  v a2s  .  c o m*/
    if (archiveType == null && dateFromStr == null && dateToStr == null) {
        return list; //quick test so we don't have to evaluate the predicates
    }
    final List<Predicate> archPredicateList = new LinkedList<Predicate>();
    archPredicateList.add(
            commonService.genDatePredicate(LatestArchive.class, "dateAdded", false, dateFromStr, dateFormat));
    archPredicateList
            .add(commonService.genDatePredicate(LatestArchive.class, "dateAdded", true, dateToStr, dateFormat));
    commonService.genORPredicateList(LatestArchive.class, archPredicateList, archiveType, ARCHIVE_TYPE);
    final Predicate latestArchivePredicates = PredicateUtils.allPredicate(archPredicateList);
    final List<LatestArchive> fList = (List<LatestArchive>) CollectionUtils.select(list,
            latestArchivePredicates);
    return fList;
}

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  a  v a 2 s.  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:gov.nih.nci.ncicb.tcga.dcc.datareports.service.BamTelemetryReportServiceImpl.java

@Override
public List<BamTelemetry> getFilteredBamTelemetryList(final List<BamTelemetry> list, final String aliquotUUID,
        final String aliquotId, final String dateFrom, final String dateTo, final List<String> disease,
        final List<String> center, final List<String> dataType, final List<String> analyteCode,
        final List<String> libraryStrategy) {
    final StringBuilder strLog = new StringBuilder();
    final DateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT_US_STRING);
    strLog.append("Filter used: aliquotUUID:").append(aliquotUUID).append("aliquotID").append(aliquotId)
            .append(" disease:").append(disease).append(" center:").append(center).append(" dataType:")
            .append(dataType).append(" analyteCode:").append(analyteCode).append(" dateFrom:").append(dateFrom)
            .append(" dateTo:").append(dateTo).append(" libraryStrategy:").append(libraryStrategy);
    logger.debug(strLog);//from   ww w.  j av  a 2 s. c  om
    if (aliquotId == null && aliquotUUID == null && disease == null && center == null && dataType == null
            && analyteCode == null && dateFrom == null && dateTo == null && libraryStrategy == null) {
        return list;
    }

    final List<Predicate> bamPredicateList = new LinkedList<Predicate>();
    bamPredicateList.add(new Predicate() {
        public boolean evaluate(Object o) {
            boolean isValid = true;

            if (StringUtils.isNotEmpty(aliquotUUID)) {
                isValid = (((BamTelemetry) o).getAliquotUUID()).equalsIgnoreCase(aliquotUUID);
            } else if (StringUtils.isNotEmpty(aliquotId)) {
                isValid = (((BamTelemetry) o).getAliquotId()).startsWith(aliquotId);
            } else {
                return isValid;
            }
            return isValid;
        }
    });
    bamPredicateList.add(
            commonService.genDatePredicate(BamTelemetry.class, "dateReceived", false, dateFrom, dateFormat));
    bamPredicateList
            .add(commonService.genDatePredicate(BamTelemetry.class, "dateReceived", true, dateTo, dateFormat));
    commonService.genORPredicateList(BamTelemetry.class, bamPredicateList, disease, DISEASE);
    commonService.genORPredicateList(BamTelemetry.class, bamPredicateList, center, CENTER);
    commonService.genORPredicateList(BamTelemetry.class, bamPredicateList, dataType, DATA_TYPE);
    commonService.genORPredicateList(BamTelemetry.class, bamPredicateList, analyteCode, ANALYTE_CODE);
    commonService.genORPredicateList(BamTelemetry.class, bamPredicateList, libraryStrategy, LIBRARY_STRATEGY);

    Predicate bamTelemetryPredicates = PredicateUtils.allPredicate(bamPredicateList);
    List<BamTelemetry> fList = (List<BamTelemetry>) CollectionUtils.select(list, bamTelemetryPredicates);
    return fList;
}

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

@Test
public void genListPredicates() {
    List<String> strList = new LinkedList<String>() {
        {/*from   ww w . j a  va  2s . c  o m*/
            add("GBM");
        }
    };
    List<Predicate> pList = commonService.genListPredicates(Aliquot.class, strList, "disease");
    List<Aliquot> fList = (List<Aliquot>) CollectionUtils.select(makeMockAliquotRows(),
            PredicateUtils.allPredicate(pList));
    assertEquals(1, pList.size());
    assertEquals(2, fList.size());
}

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

@Override
public List<ProjectCase> getFilteredProjectCaseList(final List<ProjectCase> list, final List<String> disease) {
    final StringBuilder strLog = new StringBuilder();
    final ProjectCase total = new ProjectCase();
    total.setDisease(TOTALS);/* w  w  w. j  a v a2  s  . c o  m*/
    total.setDiseaseName("Totals");
    strLog.append("Filter used: Disease:").append(disease);
    logger.debug(strLog);
    if (disease == null) {
        return list;
    }
    final List<Predicate> pcPredicateList = new LinkedList<Predicate>();
    commonService.genORPredicateList(ProjectCase.class, pcPredicateList, disease,
            DatareportsCommonConstants.DISEASE);
    final Predicate projectCasePredicates = PredicateUtils.allPredicate(pcPredicateList);
    final List<ProjectCase> fList = (List<ProjectCase>) CollectionUtils.select(list, projectCasePredicates);
    for (final ProjectCase pc : fList) {
        processTotals(total, pc);
    }
    fList.add(total);
    return fList;
}

From source file:org.apache.atlas.repository.util.FilterUtil.java

public static Predicate getPredicateFromSearchFilter(SearchFilter searchFilter) {
    List<Predicate> predicates = new ArrayList<>();

    final String type = searchFilter.getParam(SearchFilter.PARAM_TYPE);
    final String name = searchFilter.getParam(SearchFilter.PARAM_NAME);
    final String supertype = searchFilter.getParam(SearchFilter.PARAM_SUPERTYPE);
    final String notSupertype = searchFilter.getParam(SearchFilter.PARAM_NOT_SUPERTYPE);

    // Add filter for the type/category
    if (StringUtils.isNotBlank(type)) {
        predicates.add(getTypePredicate(type));
    }/*from ww w . ja  v a 2  s  . co m*/

    // Add filter for the name
    if (StringUtils.isNotBlank(name)) {
        predicates.add(getNamePredicate(name));
    }

    // Add filter for the supertype
    if (StringUtils.isNotBlank(supertype)) {
        predicates.add(getSuperTypePredicate(supertype));
    }

    // Add filter for the supertype negation
    if (StringUtils.isNotBlank(notSupertype)) {
        predicates.add(new NotPredicate(getSuperTypePredicate(notSupertype)));
    }

    return PredicateUtils.allPredicate(predicates);
}