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

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

Introduction

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

Prototype

public static <I, O> Collection<O> collect(Iterator<I> inputIterator,
        Transformer<? super I, ? extends O> transformer) 

Source Link

Document

Transforms all elements from the inputIterator with the given transformer and adds them to the outputCollection.

Usage

From source file:ch.algotrader.entity.security.CombinationImpl.java

@Override
public String toString() {

    String name = StringUtils//from  w w  w .j ava  2 s . co  m
            .join(CollectionUtils.collect(getComponents(), new Transformer<Component, String>() {
                @Override
                public String transform(Component component) {
                    return component.getQuantity() + " " + component.getSecurity();
                }
            }), " + ");
    if (StringUtils.isNotBlank(name)) {
        return name;
    }
    if (StringUtils.isNotBlank(getSymbol())) {
        return getSymbol();
    } else {
        return "EMPTY_COMBINATION";
    }
}

From source file:dk.nsi.minlog.ws.ws.MinlogudtraekserviceImpl.java

/**
 * Webservice which lists all the logentries from the request.
 */// ww  w .  j a  v  a2  s .c  o m
@Override
@Transactional(readOnly = true)
// We will never modify, so lets optimize.
@Protected(minAuthLevel = 3)
// aspect which check our request-header and populates the dgws context.
@ResponsePayload
public ListLogStatementsResponse listLogStatements(@RequestPayload ListLogStatementsRequest request,
        SoapHeader soapHeader) {
    final ListLogStatementsResponse response = new ListLogStatementsResponse();
    final List<LogEntry> logEntries = logEntryDao.findByCPRAndDates(request.getCprNR(),
            nullableDateTime(request.getFraDato()), nullableDateTime(request.getTilDato()));

    logger.debug("Found " + logEntries.size() + " log entries for " + request.getCprNR());

    // Convert all the domain model entries into jaxb and set it on the
    // response.
    response.getLogEntry().addAll(CollectionUtils.collect(logEntries,
            new Transformer<LogEntry, dk.nsi.minlog._2012._05._24.LogEntry>() {
                @Override
                public dk.nsi.minlog._2012._05._24.LogEntry transform(LogEntry registering) {
                    return toJaxbType(registering);
                }
            }));

    // Cpr is set for the entire response.
    response.setCprNrBorger(request.getCprNR());
    return response;
}

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

/**
 * {@inheritDoc}//  w  w  w  .  j a v a2  s. c  o  m
 */
@Override
@ManagedAttribute(description = "Gets current open Positions")
public Collection<PositionVO> getDataPositions() {

    String baseQuery = "from PositionImpl as p join fetch p.strategy join fetch p.security as s join fetch s.securityFamily ";

    Collection<Position> positions;
    if (this.isServer) {
        if (this.commonConfig.isDisplayClosedPositions()) {
            positions = this.lookupService.find(Position.class, baseQuery + "order by p.id", QueryType.HQL,
                    true);
        } else {
            positions = this.lookupService.find(Position.class,
                    baseQuery + "where p.quantity != 0 order by p.id", QueryType.HQL, true);
        }
    } else {
        if (this.commonConfig.isDisplayClosedPositions()) {
            positions = this.lookupService.find(Position.class,
                    baseQuery + "where p.strategy.name = :strategyName order by p.id", QueryType.HQL, true,
                    new NamedParam("strategyName", this.engine.getStrategyName()));
        } else {
            positions = this.lookupService.find(Position.class,
                    baseQuery + "where p.strategy.name = :strategyName and p.quantity != 0 order by p.id",
                    QueryType.HQL, true, new NamedParam("strategyName", this.engine.getStrategyName()));
        }
    }
    PositionVOProducer converter = new PositionVOProducer(this.marketDataCacheService);
    return CollectionUtils.collect(positions, converter::convert);
}

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

/**
 * {@inheritDoc}// ww  w.j  a  v a 2s .c  om
 */
@Override
@ManagedAttribute(description = "Gets the latest Transactions")
public Collection<TransactionVO> getDataTransactions() {

    Validate.notEmpty(this.engine.getStrategyName(), "Strategy name is empty");

    Collection<Transaction> transactions;
    if (this.isServer) {
        transactions = this.lookupService.getDailyTransactions();
    } else {
        transactions = this.lookupService.getDailyTransactionsByStrategy(this.engine.getStrategyName());
    }

    TransactionVOProducer converter = new TransactionVOProducer(this.commonConfig);
    return CollectionUtils.collect(transactions, converter::convert);
}

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

protected static void demoListTransforms(List<MyClass> list) {
    Collection<String> strList1 = CollectionUtils.collect(list, getMyString);
    Collection<String> strList2 = CollectionUtils.collect(list, getMyStringF2);
    Collection<Integer> intList = CollectionUtils.collect(list, getOther);

    printValues("xform1", strList1);
    printValues("xform2", strList2);
    printValues("otherXform", intList);
}

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

protected static void demoClosures(List<MyClass> list) {
    CollectionUtils.forAllDo(list, incAndReturn);
    printValues("List has incremented each", CollectionUtils.collect(list, getOther));

    CollectionUtils.forAllDo(list, inc);
    printValues("List has incremented each again", CollectionUtils.collect(list, getOther));
}

From source file:org.kuali.student.repository.viewer.GitGraphDetailsPanel.java

public void setSelectedCommit(RevCommit commit, int inEdges) {

    inEdgesLabel.setText(String.valueOf(inEdges));

    objectIdLabel.setText(commit.getId().name().substring(0, 8));

    this.commitMessage.setText(commit.getFullMessage());
    this.committer.setText(commit.getCommitterIdent().getName());

    this.commitDate.setText(DateFormatUtils.ISO_DATE_FORMAT.format(commit.getCommitterIdent().getWhen()));

    Transformer<RevCommit, String> transformer = new Transformer<RevCommit, String>() {

        /* (non-Javadoc)
         * @see org.apache.commons.collections15.Transformer#transform(java.lang.Object)
         *//*from  www . ja  va  2s.c o  m*/
        @Override
        public String transform(RevCommit input) {

            RevCommit vertex = input;

            if (simplify)
                vertex = RevCommitVertexUtils.findSimplifiedVertex(branchHeadCommitToBranchNameMap, input);

            String objectIdString = vertex.getId().name().substring(0, 8);

            return objectIdString;
        }

    };

    Collection<String> parentIds = CollectionUtils.collect(Arrays.asList(commit.getParents()), transformer);

    this.parentIdsLabel.setText(StringUtils.join(parentIds, ", "));

    String branchName = branchHeadCommitToBranchNameMap.get(commit);

    if (branchName == null)
        branchNamePanel.setVisible(false);
    else {
        branchNamePanel.setVisible(true);
        branchNameLabel.setText(branchName);
    }

}

From source file:org.openanzo.glitter.query.Projection.java

public void prettyPrint(StringBuilder buffer) {
    buffer.append("Projection(");

    if (this.isDistinct())
        buffer.append("DISTINCT, ");

    if (this.isReduced())
        buffer.append("REDUCED, ");

    if (this.isSelectStar)
        buffer.append("*");
    else {//from  w  ww .  jav  a 2 s .  co  m
        for (int i = 0; i < this.projectedExpressions.size(); i++) {
            Expression e = this.projectedExpressions.get(i);
            Variable var = this.projectedAs.get(i);
            if (i > 0)
                buffer.append(", ");
            if (expressionWrapsVariable(e, var)) {
                buffer.append(PrettyPrinter.print(var));
            } else {
                buffer.append("ProjectAs(");
                buffer.append(PrettyPrinter.print(e));
                buffer.append(", ");
                buffer.append(PrettyPrinter.print(var));
                buffer.append(")");
            }
        }
    }

    if (groupByVars != null && !groupByVars.isEmpty()) {
        buffer.append(", ");
        buffer.append("GroupBy(");
        buffer.append(
                StringUtils.join(CollectionUtils.collect(this.groupByVars, new Transformer<Variable, String>() {
                    public String transform(Variable input) {
                        return PrettyPrinter.print(input);
                    }
                }), ", "));
        buffer.append(")");
    }
    buffer.append(")");
}