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:com.daimler.spm.b2bacceleratoraddon.actions.CheckOrderEntryCostCentersActive.java

protected Collection<AbstractOrderEntryModel> getExpiredCostCenterEntries(final OrderModel cart) {
    return CollectionUtils.select(cart.getEntries(), new Predicate() {
        @Override/*w w  w .  ja  v  a 2 s.c o  m*/
        public boolean evaluate(final Object object) {
            final B2BCostCenterModel costCenter = ((AbstractOrderEntryModel) object).getCostCenter();
            if (costCenter != null && BooleanUtils.isFalse(costCenter.getActive())) {
                return true;
            }
            return false;
        }
    });

}

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

/**
     */*from  w  w w . ja v a2s .c om*/
     * 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:de.hybris.platform.b2bacceleratorservices.company.impl.DefaultB2BCommerceUnitService.java

@Override
public Collection<? extends B2BUnitModel> getAllowedParentUnits(final B2BUnitModel unit) {
    final B2BUnitModel sessionUnitParent = getParentUnit();

    final Set<B2BUnitModel> branch = getSessionService().executeInLocalView(new SessionExecutionBody() {
        @Override/*from   w ww . j  a  v  a 2s.  com*/
        public Object execute() {
            getSearchRestrictionService().disableSearchRestrictions();
            return getB2BUnitService().getBranch(sessionUnitParent);
        }
    });

    final Set<B2BUnitModel> allowedUnits = new HashSet<B2BUnitModel>(
            CollectionUtils.select(branch, new Predicate() {
                @Override
                public boolean evaluate(final Object object) {
                    final PrincipalGroupModel principalGroup = (PrincipalGroupModel) object;
                    return getB2BGroupCycleValidator().validateGroups(unit, principalGroup);

                }
            }));
    final B2BUnitModel parentUnit = getParentUnit(unit);
    if (parentUnit != null) {
        allowedUnits.add(parentUnit);
    }
    return allowedUnits;
}

From source file:ke.co.tawi.babblesms.server.sendsms.tawismsgw.TestPostSMS.java

/**
 * Test method for {@link PostSMS#PostSMS(String, java.util.Map, boolean)}.
 *//*from   ww  w  . j  a va2 s. com*/
@Test
public void testPostThread() {

    // Get all the Contacts of the 'demo' account and make a list of Outgoing SMS
    ContactDAO contactDAO = new ContactDAO(DB_NAME, DB_HOST, DB_USERNAME, DB_PASSWD, DB_PORT);

    Account a = new Account();
    a.setUuid(ACCOUNT_UUID);

    List<Contact> allContacts = contactDAO.getContacts(a);

    PhoneDAO phoneDAO = new PhoneDAO(DB_NAME, DB_HOST, DB_USERNAME, DB_PASSWD, DB_PORT);
    List<Phone> allPhones = new LinkedList<>();

    for (Contact c : allContacts) {
        allPhones.addAll(phoneDAO.getPhones(c));
    }

    System.out.println("All phone size: " + allPhones.size());
    /* for(Phone p : allPhones) {
       System.out.println(p.getNetworkuuid());
    }*/

    List<Phone> safaricomPhones = new LinkedList<>();
    safaricomPhones
            .addAll(CollectionUtils.select(allPhones, new PhonesByNetworkPredicate(Network.SAFARICOM_KE)));
    System.out.println("Safaricom phone size: " + safaricomPhones.size());

    List<List<Phone>> phonePartition = ListPartitioner.partition(safaricomPhones, 10);
    assertEquals(phonePartition.size(), 4);
    assertEquals(phonePartition.get(0).size(), 10);
    assertEquals(phonePartition.get(1).size(), 10);
    assertEquals(phonePartition.get(2).size(), 10);
    //assertEquals(phonePartition.get(3).size(), 9);

    Map<String, String> params;
    PostSMS postThread;

    for (List<Phone> list : phonePartition) {
        params = new HashMap<String, String>();
        params.put("username", SMSGW_USERNAME);
        params.put("password", SMSGW_PASSWORD);
        params.put("source", SOURCE);
        params.put("destination", "254720123456");
        params.put("message", MESSAGE);
        params.put("network", "safaricom_ke");

        System.out.println("Hash to be POSTED: " + StringUtil.mapToString(params));

        //postThread = new PostSMS(SMSGW_URL_HTTP, params, false);   
        //postThread.run();    // Use this when testing. However use 'postThread.start()' when
        // running in an application server.
    }

    // Create a list of Outgoing SMS from the Phones 
    /*
    List<OutgoingLog> logList = new ArrayList<OutgoingLog>();
            
    OutgoingLog log;
    for(Phone p : allPhones) {
       log = new OutgoingLog();
       log.setOrigin(SOURCE);
       log.setDestination(p.getPhonenumber());
       log.setMessage(MESSAGE);
       log.setSender(ACCOUNT_UUID);
       log.setNetworkuuid(p.getNetworkuuid());
                  
       logList.add(log);
    }
    */
}

From source file:de.hybris.platform.accountsummaryaddon.document.populators.B2BAmountBalancePopulator.java

@Override
public void populate(B2BUnitModel source, B2BAmountBalanceData target) throws ConversionException {
    final Map<B2BNumberOfDayRangeData, String> rangeMap = new LinkedHashMap<B2BNumberOfDayRangeData, String>();
    final List<NumberOfDayRange> ranges = pastDueBalanceDateRangeService.getNumberOfDayRange();

    final SearchResult<B2BDocumentModel> documentsResult = b2bDocumentService.getOpenDocuments(source);
    final List<B2BDocumentModel> documents = documentsResult.getResult();

    for (final NumberOfDayRange dateRange : ranges) {
        final B2BNumberOfDayRangeData range = new B2BNumberOfDayRangeData();
        range.setMinBoundery(dateRange.getMinBoundary());
        range.setMaxBoundery(dateRange.getMaxBoundary());
        rangeMap.put(range, totalAmount(
                CollectionUtils.select(documents, new B2BDocumentDueDateRangePredicate(dateRange))));
    }/*from   ww w  . j  a v a2  s .  c  o  m*/
    target.setDueBalance(rangeMap);
    target.setOpenBalance(totalAmount(documents));
    target.setPastDueBalance(totalAmount(CollectionUtils.select(documents, new B2BDocumentPastDuePredicate())));
    target.setCurrentBalance(
            totalAmount(CollectionUtils.selectRejected(documents, new B2BDocumentPastDuePredicate())));
}

From source file:net.sourceforge.fenixedu.applicationTier.Servico.masterDegree.commons.candidate.WriteCandidateEnrolments.java

protected void run(Set<String> selectedCurricularCoursesIDs, String candidateID, Double credits,
        String givenCreditsRemarks) throws FenixServiceException {

    MasterDegreeCandidate masterDegreeCandidate = FenixFramework.getDomainObject(candidateID);
    if (masterDegreeCandidate == null) {
        throw new NonExistingServiceException();
    }/*from   w  ww.j a  va  2s.c  om*/

    masterDegreeCandidate.setGivenCredits(credits);

    if (credits.floatValue() != 0) {
        masterDegreeCandidate.setGivenCreditsRemarks(givenCreditsRemarks);
    }

    Collection<CandidateEnrolment> candidateEnrolments = masterDegreeCandidate.getCandidateEnrolmentsSet();
    List<String> candidateEnrolmentsCurricularCoursesIDs = (List<String>) CollectionUtils
            .collect(candidateEnrolments, new Transformer() {
                @Override
                public Object transform(Object arg0) {
                    CandidateEnrolment candidateEnrolment = (CandidateEnrolment) arg0;
                    return candidateEnrolment.getCurricularCourse().getExternalId();
                }
            });

    Collection<String> curricularCoursesToEnroll = CollectionUtils.subtract(selectedCurricularCoursesIDs,
            candidateEnrolmentsCurricularCoursesIDs);

    final Collection<Integer> curricularCoursesToDelete = CollectionUtils
            .subtract(candidateEnrolmentsCurricularCoursesIDs, selectedCurricularCoursesIDs);

    Collection<CandidateEnrolment> candidateEnrollmentsToDelete = CollectionUtils.select(candidateEnrolments,
            new Predicate() {
                @Override
                public boolean evaluate(Object arg0) {
                    CandidateEnrolment candidateEnrolment = (CandidateEnrolment) arg0;
                    return (curricularCoursesToDelete
                            .contains(candidateEnrolment.getCurricularCourse().getExternalId()));
                }
            });

    writeFilteredEnrollments(masterDegreeCandidate, curricularCoursesToEnroll);

    for (CandidateEnrolment candidateEnrolmentToDelete : candidateEnrollmentsToDelete) {
        candidateEnrolmentToDelete.delete();
    }
}

From source file:net.sourceforge.fenixedu.dataTransferObject.degreeAdministrativeOffice.gradeSubmission.MarkSheetManagementCreateBean.java

@Atomic
public MarkSheet createMarkSheet(Person person) {
    final Collection<MarkSheetEnrolmentEvaluationBean> enrolmentEvaluationBeanList = CollectionUtils
            .select(getAllEnrolmentEvalutionBeans(), new Predicate() {
                @Override/* w  ww. j  av  a2  s  .c o m*/
                public boolean evaluate(Object arg0) {
                    return ((MarkSheetEnrolmentEvaluationBean) arg0).hasAnyGradeValue();
                }

            });

    return getCurricularCourse().createNormalMarkSheet(getExecutionPeriod(), getTeacher(), getEvaluationDate(),
            getMarkSheetType(), Boolean.FALSE, enrolmentEvaluationBeanList, person);
}

From source file:com.zuora.api.object.Dynamic.java

/**
 * Answers the name and values of the static properties of this object
 * @return the static properties, as string-object pairs
 */// www  .  j  av a2 s .co m
public Collection<Entry<String, Object>> staticProperties() {
    return CollectionUtils.select(propertyValues(), new Predicate() {
        public boolean evaluate(Object object) {
            Entry e = (Entry) object;
            return e.getValue() != null && !EXCLUDED_PROPERTY_NAMES.contains(e.getKey());
        }
    });
}

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);/*from  w  ww  . j a  va 2s.co  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:net.sourceforge.fenixedu.applicationTier.Servico.administrativeOffice.gradeSubmission.EditMarkSheet.java

private static Collection<MarkSheetEnrolmentEvaluationBean> getEnrolmentEvaluationsWithValidGrades(
        Collection<MarkSheetEnrolmentEvaluationBean> enrolmentEvaluationBeans) {

    return CollectionUtils.select(enrolmentEvaluationBeans, new Predicate() {
        @Override/*from w w  w  .  j  ava 2 s  .  c  o  m*/
        public boolean evaluate(Object arg0) {
            MarkSheetEnrolmentEvaluationBean markSheetEnrolmentEvaluationBean = (MarkSheetEnrolmentEvaluationBean) arg0;
            return markSheetEnrolmentEvaluationBean.getGradeValue() != null
                    && markSheetEnrolmentEvaluationBean.getGradeValue().length() != 0;
        }
    });
}