Example usage for org.apache.commons.collections15 CollectionUtils filter

List of usage examples for org.apache.commons.collections15 CollectionUtils filter

Introduction

In this page you can find the example usage for org.apache.commons.collections15 CollectionUtils filter.

Prototype

public static <E> void filter(Iterable<E> iterable, Predicate<? super E> predicate) 

Source Link

Document

Filter the iterable by applying a Predicate to each element.

Usage

From source file:ch.algotrader.service.HistoricalDataServiceImpl.java

private void updateBars(final long securityId, final Duration barSize, List<Bar> bars) {

    // get the last Bar int the Database
    final Bar lastBar = CollectionUtil
            .getSingleElementOrNull(this.barDao.findBarsBySecurityAndBarSize(1, securityId, barSize));

    // remove all Bars prior to the lastBar
    if (lastBar != null) {

        CollectionUtils.filter(bars, new Predicate<Bar>() {
            @Override/*w w w. j  a  v  a2 s. co  m*/
            public boolean evaluate(Bar bar) {
                return bar.getDateTime().compareTo(lastBar.getDateTime()) > 0;
            }
        });
    }

    // save the Bars
    this.barDao.saveAll(bars);

    if (LOGGER.isInfoEnabled()) {
        LOGGER.info("created {} new bars for security {}", bars.size(), securityId);
    }
}

From source file:org.drugis.addis.entities.analysis.RandomEffectsMetaAnalysis.java

List<RelativeEffect<? extends Measurement>> getFilteredRelativeEffects(
        Class<? extends RelativeEffect<?>> type) {
    final List<RelativeEffect<? extends Measurement>> relativeEffects = getRelativeEffects(type);
    CollectionUtils.filter(relativeEffects, new Predicate<RelativeEffect<? extends Measurement>>() {
        public boolean evaluate(RelativeEffect<? extends Measurement> re) {
            return re.isDefined();
        }//from w  ww .j a v  a  2  s. c  om
    });
    return relativeEffects;
}

From source file:org.drugis.addis.imports.ClinicaltrialsImporter.java

private static String createCentersNote(ClinicalStudy studyImport) {
    StringBuilder noteBuilder = new StringBuilder();
    for (LocationStruct l : studyImport.getLocation()) {
        FacilityStruct f = l.getFacility();
        AddressStruct a = f.getAddress();
        List<String> fields = new ArrayList<String>(Arrays
                .asList(new String[] { f.getName(), a.getZip(), a.getCity(), a.getState(), a.getCountry() }));
        CollectionUtils.filter(fields, PredicateUtils.notNullPredicate());
        noteBuilder.append(StringUtils.join(fields, ", "));
        noteBuilder.append('\n');
    }/* w w w  .  j  av  a 2  s  .  c o m*/
    return noteBuilder.toString();
}

From source file:org.drugis.mtc.jags.JagsSyntaxModel.java

private String getDerivations() {
    Collection<String> lines = NetworkModel.transformTreatmentPairs(d_network,
            new Transformer<Pair<Treatment>, String>() {
                public String transform(Pair<Treatment> input) {
                    Treatment ti = input.getFirst();
                    Treatment tj = input.getSecond();
                    BasicParameter p = new BasicParameter(ti, tj);
                    BasicParameter q = new BasicParameter(tj, ti);
                    if (!d_pmtz.getParameters().contains(p) && !d_pmtz.getParameters().contains(q)) {
                        String e = expressRelativeEffect(ti, tj, s_rTransform);
                        return "\t`" + p + "` = function(x) { " + e + " }";
                    }/*from w w w . j  a  v  a2s.  c  o m*/
                    return null;
                }
            });
    CollectionUtils.filter(lines, PredicateUtils.notNullPredicate());
    return StringUtils.join(lines, ",\n");
}

From source file:org.drugis.mtc.parameterization.AbstractDataStartingValueGenerator.java

protected List<EstimateWithPrecision> estimateRelativeEffects(final BasicParameter p) {
    final Pair<Treatment> treatments = new Pair<Treatment>(p.getBaseline(), p.getSubject());
    Set<Study> studies = new HashSet<Study>(d_network.getStudies());
    CollectionUtils.filter(studies, new Predicate<Study>() {
        public boolean evaluate(Study study) {
            return study.getTreatments().containsAll(treatments);
        }//from   ww w  .java2 s . c  o m
    });

    List<EstimateWithPrecision> estimates = new ArrayList<EstimateWithPrecision>(studies.size());
    for (Study s : studies) {
        estimates.add(estimateRelativeEffect(s, p));
    }
    return estimates;
}

From source file:org.jcodec.containers.mp4.boxes.NodeBox.java

public void filter(Predicate<Box> predicate) {
    CollectionUtils.filter(boxes, predicate);
}