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

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

Introduction

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

Prototype

public static <E> Collection<E> select(Collection<E> inputCollection, Predicate<? super E> predicate) 

Source Link

Document

Selects all elements from input collection which match the given predicate into an output collection.

Usage

From source file:ch.algotrader.esper.EngineManagerImpl.java

@Override
@SuppressWarnings("unchecked")
public void logStatementMetrics() {

    for (Map.Entry<String, Engine> entry : this.engineMap.entrySet()) {
        Engine engine = entry.getValue();

        if (engine.isDeployed("METRICS")) {

            List<StatementMetricVO> metrics = engine.getAllEvents("METRICS");

            // consolidate ON_TRADE_COMPLETED and ON_FIRST_TICK
            for (final String statementName : new String[] { "ON_TRADE_COMPLETED", "ON_FIRST_TICK" }) {

                // select metrics where the statementName startsWith
                Collection<StatementMetricVO> selectedMetrics = CollectionUtils.select(metrics,
                        new Predicate<StatementMetricVO>() {
                            @Override
                            public boolean evaluate(StatementMetricVO metric) {
                                return metric.getStatementName() != null
                                        && metric.getStatementName().startsWith(statementName);
                            }/*from w w  w  .j  ava  2  s  . c om*/
                        });

                // add cpuTime, wallTime and numInput
                if (selectedMetrics.size() > 0) {

                    long cpuTime = 0;
                    long wallTime = 0;
                    long numInput = 0;
                    for (StatementMetricVO metric : selectedMetrics) {

                        cpuTime += metric.getCpuTime();
                        wallTime += metric.getWallTime();
                        numInput += metric.getNumInput();

                        // remove the original metric
                        metrics.remove(metric);
                    }

                    // add a consolidated metric
                    metrics.add(new StatementMetricVO(engine.getStrategyName(), statementName, cpuTime,
                            wallTime, numInput));
                }
            }

            if (LOGGER.isInfoEnabled()) {
                for (StatementMetricVO metric : metrics) {
                    LOGGER.info("{}.{}: {} millis {} events", metric.getEngineURI(), metric.getStatementName(),
                            metric.getWallTime(), metric.getNumInput());
                }
            }
        }
    }
}

From source file:ch.algotrader.simulation.Simulator.java

public Collection<Position> findOpenPositions() {
    return CollectionUtils.select(this.positionsByStrategy.values(), entity -> entity.getQuantity() != 0);
}

From source file:gov.nih.nci.cabig.caaers.domain.report.ReportDefinition.java

/**
 * Will return all the ReportMandatoryFieldDefinition that are not rule based.
 *
 * @return the all non rule based mandatory fields
 *//*from  w w w . ja  v a  2  s.  com*/
@Transient
public Collection<ReportMandatoryFieldDefinition> getAllNonRuleBasedMandatoryFields() {
    return CollectionUtils.select(getMandatoryFields(), new Predicate<ReportMandatoryFieldDefinition>() {
        public boolean evaluate(ReportMandatoryFieldDefinition rd) {
            return !rd.isRuleBased();
        }
    });
}

From source file:gov.nih.nci.cabig.caaers.domain.report.ReportDefinition.java

/**
 * Will return the ReportMandatoryFieldDefinition that are associated to rules.
 *
 * @return the all rule based mandatory fields
 *//*from   w  w  w.  j a va2  s  . c  o m*/
@Transient
public Collection<ReportMandatoryFieldDefinition> getAllRuleBasedMandatoryFields() {
    return CollectionUtils.select(getMandatoryFields(), new Predicate<ReportMandatoryFieldDefinition>() {
        public boolean evaluate(ReportMandatoryFieldDefinition rd) {
            return rd.isRuleBased();
        }
    });
}

From source file:gov.nih.nci.cabig.caaers.domain.report.ReportDefinition.java

/**
 * Will return the ReportMandatoryFieldDefinition that are self referenced.
 *
 * @return the self referenced rule based mandatory fields
 *///from   ww w.  j  av  a2s . c o m
@Transient
public Collection<ReportMandatoryFieldDefinition> getSelfReferencedRuleBasedMandatoryFields() {
    return CollectionUtils.select(getMandatoryFields(), new Predicate<ReportMandatoryFieldDefinition>() {
        public boolean evaluate(ReportMandatoryFieldDefinition rd) {
            return rd.isRuleBased() && rd.isSelfReferenced();
        }
    });
}

From source file:gov.nih.nci.cabig.caaers.domain.report.ReportDefinition.java

/**
 * Will return the ReportMandatoryFieldDefinition that are not self referenced.
 *
 * @return the non self referenced rule based mandatory fields
 *///from w w  w  . j  av a2  s  .  c  o m
@Transient
public Collection<ReportMandatoryFieldDefinition> getNonSelfReferencedRuleBasedMandatoryFields() {
    return CollectionUtils.select(getMandatoryFields(), new Predicate<ReportMandatoryFieldDefinition>() {
        public boolean evaluate(ReportMandatoryFieldDefinition rd) {
            return rd.isRuleBased() && !rd.isSelfReferenced();
        }
    });
}

From source file:ch.algotrader.esper.EngineImpl.java

private String[] findStatementNames(final String statementNameRegex) {

    EPAdministrator administrator = this.serviceProvider.getEPAdministrator();

    // find the first statement that matches the given statementName regex
    Collection<String> names = CollectionUtils.select(Arrays.asList(administrator.getStatementNames()),
            statement -> statement.matches(statementNameRegex));
    return names.toArray(new String[names.size()]);
}

From source file:org.drugis.addis.presentation.wizard.NetworkMetaAnalysisWizardPM.java

/**
 * Create a filtered list of studies that includes only those studies that
 * compare at least two of the definitions on the given variable.
 *//* w w w  .  ja v  a  2s .com*/
public static List<Study> filterStudiesComparing(final Variable var, final Collection<Study> studies,
        final Collection<TreatmentDefinition> defs) {
    return (List<Study>) CollectionUtils.select(studies, new Predicate<Study>() {
        public boolean evaluate(Study s) {
            int count = 0;
            for (TreatmentDefinition def : defs) {
                if (!s.getMeasuredArms(var, def).isEmpty()) {
                    ++count;
                }
            }
            return count > 1;
        }
    });
}

From source file:org.drugis.addis.presentation.wizard.NetworkMetaAnalysisWizardPM.java

/**
 * Create a filtered list of definitions that includes only those definitions that
 * are measured on the given variable in at least one study.
 *//*from  w  w  w .  j a  va  2 s . c  o  m*/
public static List<TreatmentDefinition> filterDefinitionsMeasured(final Variable var,
        Collection<TreatmentDefinition> defs, final Collection<Study> studies) {
    return (List<TreatmentDefinition>) CollectionUtils.select(defs, new Predicate<TreatmentDefinition>() {
        public boolean evaluate(TreatmentDefinition def) {
            for (Study s : studies) {
                if (!s.getMeasuredArms(var, def).isEmpty()) {
                    return true;
                }
            }
            return false;
        }
    });
}

From source file:org.funcito.example.collectionsgeneric.MyClass.java

protected static void demoListFilters(List<MyClass> list) {
    Collection<MyClass> filtered1 = CollectionUtils.select(list, isLengthGT1);
    Collection<MyClass> filtered2 = CollectionUtils.select(list, isLengthGT3);

    printValues("select length > 1", filtered1);
    printValues("select length > 3", filtered2);
}