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.base2.kagura.core.report.connectors.FakeDataReportConnector.java

/**
 * {@inheritDoc}//w  ww.  j  a  va 2  s . c om
 */
@Override
public void runReport(Map<String, Object> extra) {
    rows = new ArrayList<Map<String, Object>>(data != null ? data : new ArrayList<Map<String, Object>>());
    if (parameterConfig != null) {
        for (final ParamConfig paramConfig : parameterConfig) {
            if (paramRules == null)
                continue;
            final FakeReportConfig.ParamToColumnRule paramToColumnRule = paramRules.get(paramConfig.getName());
            if (paramToColumnRule == null)
                continue;
            try {
                if (StringUtils.isBlank(BeanUtils.getProperty(paramConfig, "value")))
                    continue;
            } catch (IllegalAccessException e) {
                e.printStackTrace();
                continue;
            } catch (InvocationTargetException e) {
                e.printStackTrace();
                continue;
            } catch (NoSuchMethodException e) {
                e.printStackTrace();
                continue;
            }
            switch (paramToColumnRule.getMapRule()) {
            case Exact:
                rows = (List<Map<String, Object>>) CollectionUtils.select(rows,
                        new ExactEquals(paramToColumnRule, paramConfig));
                break;
            case SubString:
                rows = (List<Map<String, Object>>) CollectionUtils.select(rows,
                        new SubstringOrExact(paramToColumnRule, paramConfig));
                break;
            case IntegerRange:
                rows = (List<Map<String, Object>>) CollectionUtils.select(rows,
                        new IntegerRange(paramToColumnRule, paramConfig));
                break;
            }
        }
    }
}

From source file:com.jpmorgan.assgn.sss02mvn.service.StockTradeServiceImpl.java

@Override
public double calculateStockPrice(String pstocksymbol, int minutes) throws Exception {
    double stockPrice = 0.0;

    logger.debug("Trades in the original collection: " + getTradesNumber());

    @SuppressWarnings("unchecked")
    Collection<Trade> trades = CollectionUtils.select(stockTradeRepository.getTrades(),
            new StockPredicate(pstocksymbol, minutes));

    logger.debug(/*from  w w  w.ja v a2s .  c om*/
            "Trades in the filtered collection by [" + pstocksymbol + "," + minutes + "]: " + trades.size());

    // Calculate the summation
    double shareQuantityAcum = 0.0;
    double tradePriceAcum = 0.0;
    for (Trade trade : trades) {
        // Calculate the summation of Trade Price x Quantity
        tradePriceAcum += (trade.getPrice() * trade.getShareQuantity());
        // Acumulate Quantity
        shareQuantityAcum += trade.getShareQuantity();
    }

    // calculate the stock price
    if (shareQuantityAcum > 0.0) {
        stockPrice = tradePriceAcum / shareQuantityAcum;
    }

    return stockPrice;
}

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

protected B2BUnitData populateChildrenUnits(final B2BUnitModel source, final B2BUnitData target) {
    final List<B2BUnitData> childUnits = new ArrayList<B2BUnitData>();
    final Set<PrincipalModel> members = source.getMembers();
    final Collection<B2BUnitModel> childrenUnits = CollectionUtils.select(members,
            PredicateUtils.instanceofPredicate(B2BUnitModel.class));
    for (final B2BUnitModel unit : childrenUnits) {
        childUnits.add(this.populateUnit(unit, new B2BUnitData()));
    }//from   www . ja  va2 s  .  c  om
    target.setChildren(childUnits);
    return target;
}

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  www  .j a v a 2s  . c om
    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:edu.kit.sharing.test.SharingTestService.java

@Override
public IEntityWrapper<? extends IDefaultReferenceId> getReferences(String pDomain, String pDomainUniqueId,
        String pGroupId, HttpContext hc) {
    final GroupId gid = new GroupId(pGroupId);

    Collection rs = CollectionUtils.select(references, new Predicate() {

        @Override/* w  w w .j a  va 2 s  . c  o  m*/
        public boolean evaluate(Object o) {
            return ((ReferenceId) o).getGroupId().equals(gid);
        }
    });

    List<ReferenceId> referenceIds = new LinkedList<>();
    for (Object r : rs) {
        referenceIds.add(((ReferenceId) r));
    }
    return new ReferenceIdWrapper(referenceIds);
}

From source file:net.sourceforge.fenixedu.domain.teacher.TeacherService.java

public List<DegreeTeachingService> getDegreeTeachingServiceByProfessorship(final Professorship professorship) {
    return (List<DegreeTeachingService>) CollectionUtils.select(getDegreeTeachingServices(), new Predicate() {
        @Override/*from w ww. ja  v  a2s . c om*/
        public boolean evaluate(Object arg0) {
            DegreeTeachingService degreeTeachingService = (DegreeTeachingService) arg0;
            return degreeTeachingService.getProfessorship() == professorship;
        }
    });
}

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 ww  w  . ja v  a  2s .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:net.sourceforge.fenixedu.dataTransferObject.degreeAdministrativeOffice.gradeSubmission.MarkSheetManagementCreateBean.java

@Atomic
public MarkSheet createOldMarkSheet(Person person) {
    final Collection<MarkSheetEnrolmentEvaluationBean> enrolmentEvaluationBeanList = CollectionUtils
            .select(getAllEnrolmentEvalutionBeans(), new Predicate() {
                @Override//from  w ww  . ja  va 2s.  co m
                public boolean evaluate(Object arg0) {
                    return ((MarkSheetEnrolmentEvaluationBean) arg0).hasAnyGradeValue();
                }

            });

    return getCurricularCourse().createOldNormalMarkSheet(getExecutionPeriod(), getTeacher(),
            getEvaluationDate(), getMarkSheetType(), enrolmentEvaluationBeanList, person);
}

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

public static List buildLabelValueBeansForList(List executionDegrees, MessageResources messageResources) {
    List copyExecutionDegrees = new ArrayList();
    copyExecutionDegrees.addAll(executionDegrees);
    List result = new ArrayList();
    Iterator iter = executionDegrees.iterator();
    while (iter.hasNext()) {
        final InfoExecutionDegree infoExecutionDegree = (InfoExecutionDegree) iter.next();
        List equalDegrees = (List) CollectionUtils.select(copyExecutionDegrees, new Predicate() {
            @Override//  w ww .j av a 2  s . c  om
            public boolean evaluate(Object arg0) {
                InfoExecutionDegree infoExecutionDegreeElem = (InfoExecutionDegree) arg0;
                if (infoExecutionDegree.getInfoDegreeCurricularPlan().getInfoDegree().getSigla().equals(
                        infoExecutionDegreeElem.getInfoDegreeCurricularPlan().getInfoDegree().getSigla())) {
                    return true;
                }
                return false;
            }
        });
        if (equalDegrees.size() == 1) {
            copyExecutionDegrees.remove(infoExecutionDegree);

            String degreeType = null;
            if (messageResources != null) {
                degreeType = messageResources.getMessage(infoExecutionDegree.getInfoDegreeCurricularPlan()
                        .getInfoDegree().getDegreeType().toString());
            }
            if (degreeType == null) {
                degreeType = infoExecutionDegree.getInfoDegreeCurricularPlan().getInfoDegree().getDegreeType()
                        .toString();
            }

            result.add(new LabelValueBean(
                    degreeType + "  "
                            + infoExecutionDegree.getInfoDegreeCurricularPlan().getInfoDegree().getNome(),
                    infoExecutionDegree.getExternalId().toString()));
        } else {
            String degreeType = null;
            if (messageResources != null) {
                degreeType = messageResources.getMessage(infoExecutionDegree.getInfoDegreeCurricularPlan()
                        .getInfoDegree().getDegreeType().toString());
            }
            if (degreeType == null) {
                degreeType = infoExecutionDegree.getInfoDegreeCurricularPlan().getInfoDegree().getDegreeType()
                        .toString();
            }

            result.add(
                    new LabelValueBean(
                            degreeType + "  "
                                    + infoExecutionDegree.getInfoDegreeCurricularPlan().getInfoDegree()
                                            .getNome()
                                    + " - " + infoExecutionDegree.getInfoDegreeCurricularPlan().getName(),
                            infoExecutionDegree.getExternalId().toString()));
        }
    }
    return result;

}

From source file:BackupService.java

/**
 * Main method to start backup action.//from w w  w  . j av a  2s .  com
 *
 * @return Index ID of backup (technicaly name of create index file)
 * @throws Exception
 */
public String run() throws Exception {
    logger.info("Backup started for '{}', to repository '{}'", idBackup, repository.getFullPath());

    Set<VOBackupFile> oldFileSet = repository.getOldBackupIndex(idBackup);
    logger.info("Found {} files in old indexes.", oldFileSet.size());

    Map<VOBackupFile, VOBackupFile> oldFileIndex = new HashMap<>(oldFileSet.size());
    for (VOBackupFile voBackupFile : oldFileSet) {
        oldFileIndex.put(voBackupFile, voBackupFile);
    }
    logger.trace("Index prepared");

    // explore source paths
    List<VOBackupFile> newFileList = exploreBackupFiles();
    sumary.setFounded(newFileList.size());

    logger.trace("finding directories.");
    sumary.setDirs(CollectionUtils.select(newFileList, new Predicate() {
        @Override
        public boolean evaluate(Object object) {
            return (((VOBackupFile) object).isDirectory());
        }
    }).size());
    logger.trace("finding empty files.");
    sumary.setEmptyFiles(CollectionUtils.select(newFileList, new Predicate() {
        @Override
        public boolean evaluate(Object object) {
            return (((VOBackupFile) object).getSize() == 0) && !((VOBackupFile) object).isDirectory();
        }
    }).size());

    logger.trace("start comparing.");
    // find unchanged items
    int cnt = 0;
    for (VOBackupFile voBackupFile : newFileList) {
        if (voBackupFile.unPrepared() && oldFileIndex.containsKey(voBackupFile)) {
            VOBackupFile voBackupFileOld = oldFileIndex.get(voBackupFile);
            //                        (VOBackupFile) CollectionUtils.find(oldFileSet, PredicateUtils.equalPredicate(voBackupFile));
            if (voBackupFileOld != null) {
                voBackupFile.setFileHash(voBackupFileOld.getFileHash());
                voBackupFile.setCheckSumBck(voBackupFileOld.getCheckSumBck());
                cnt++;
            } else {
                logger.trace("Wrog finding old object.");
            }
        }
    }
    sumary.setNonChanged(cnt);
    logger.info("Found {} unchanged files.", cnt);

    // for unprepared items do backup
    cnt = 0;
    for (VOBackupFile voBackupFile : newFileList) {
        if (voBackupFile.unPrepared()) {
            try {
                repository.saveContentToRepo(voBackupFile, oldFileSet);
                cnt++;
            } catch (Exception e) {
                sumary.getErrors().add(voBackupFile.getPath() + " - " + e.getMessage());
                logger.error("Unable to backup " + voBackupFile.getPath() + ": ", e);
            }
        }
    }
    sumary.setProcessed(cnt);
    logger.info("Processed {} changed or new files.", cnt);

    // store index in repository meta
    VOBackupIndex backupIndex = new VOBackupIndex(newFileList);
    backupIndex.setConfig(cfg);
    backupIndex.setSummary(sumary);

    // check before save
    VOCheckIndex voCheckIndex = repository.checkIndex(backupIndex, false, false);
    if (voCheckIndex.allOk()) {
        logger.info("check index: OK");
    } else {
        logger.error("check index: {}", voCheckIndex.toString());
    }
    backupIndex.setCheck(voCheckIndex);

    String indexFileName = repository.saveBackupIndex(backupIndex, idBackup);

    logger.info(sumary.toString());
    logger.info("Backup ended");
    return indexFileName;
}