Example usage for org.apache.commons.collections CollectionUtils forAllDo

List of usage examples for org.apache.commons.collections CollectionUtils forAllDo

Introduction

In this page you can find the example usage for org.apache.commons.collections CollectionUtils forAllDo.

Prototype

public static void forAllDo(Collection collection, Closure closure) 

Source Link

Document

Executes the given closure on each element in the collection.

Usage

From source file:org.kuali.kfs.module.cam.document.web.struts.BarcodeInventoryErrorAction.java

/**
 * Searches and replaces BCIE document data on the document
 * // ww w.ja  v a 2  s  . c  o  m
 * @param mapping
 * @param form
 * @param request
 * @param response
 * @return ActionForward
 * @throws Exception
 */
public ActionForward searchAndReplace(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    BarcodeInventoryErrorForm barcodeInventoryErrorForm = (BarcodeInventoryErrorForm) form;
    BarcodeInventoryErrorDocument document = barcodeInventoryErrorForm.getBarcodeInventoryErrorDocument();
    List<BarcodeInventoryErrorDetail> barcodeInventoryErrorDetails = document.getBarcodeInventoryErrorDetail();

    // Validating search criteria
    if (validateGlobalReplaceFields(document)) {
        BarcodeInventoryErrorDetailPredicate predicatedClosure = new BarcodeInventoryErrorDetailPredicate(
                barcodeInventoryErrorForm.getBarcodeInventoryErrorDocument());

        // searches and replaces
        CollectionUtils.forAllDo(barcodeInventoryErrorDetails, predicatedClosure);

        document.setBarcodeInventoryErrorDetail(barcodeInventoryErrorDetails);
        barcodeInventoryErrorForm.setDocument(document);
    }
    // Validating.
    this.invokeRules(document, false);

    // Search fields initialization.
    barcodeInventoryErrorForm.getBarcodeInventoryErrorDocument().resetSearchFields();

    // Reseting the checkboxes
    barcodeInventoryErrorForm.resetCheckBoxes();

    // Displaying JSP
    return mapping.findForward(KFSConstants.MAPPING_BASIC);
}

From source file:org.kuali.kfs.module.cam.utils.BarcodeInventoryErrorDetailPredicateTest.java

/**
 *     /*from  w  w w  .  jav a  2  s  .  c om*/
 * test the UpdateAssetInformation
 */
public void testUpdateAssetInformation() {
    BarcodeInventoryErrorDetail barcodeInventoryErrorDetail;
    BarcodeInventoryErrorDetail barcodeInventoryErrorExpectedDetail;

    BarcodeInventoryErrorDocument barcodeInventoryErrorDocument = BarcodeInventoryErrorDetailPredicateFixture.DATA
            .getBarcodeInventoryErrorDocument();
    List<BarcodeInventoryErrorDetail> barcodeInventoryErrorDetails = BarcodeInventoryErrorDetailPredicateFixture.DATA
            .getBarcodeInventoryDetail();
    List<BarcodeInventoryErrorDetail> barcodeInventoryErrorExpectedDetails = BarcodeInventoryErrorDetailPredicateFixture.DATA
            .getExpectedResults();

    BarcodeInventoryErrorDetailPredicate predicatedClosure = new BarcodeInventoryErrorDetailPredicate(
            barcodeInventoryErrorDocument);

    // searches and replaces
    CollectionUtils.forAllDo(barcodeInventoryErrorDetails, predicatedClosure);

    for (int row = 0; row < barcodeInventoryErrorDetails.size(); row++) {
        barcodeInventoryErrorDetail = barcodeInventoryErrorDetails.get(row);
        barcodeInventoryErrorExpectedDetail = barcodeInventoryErrorExpectedDetails.get(row);

        assertTrue("Replacement failed.",
                barcodeInventoryErrorDetail.getCampusCode()
                        .equals(barcodeInventoryErrorExpectedDetail.getCampusCode())
                        && barcodeInventoryErrorDetail.getBuildingCode()
                                .equals(barcodeInventoryErrorExpectedDetail.getBuildingCode())
                        && barcodeInventoryErrorDetail.getBuildingRoomNumber()
                                .equals(barcodeInventoryErrorExpectedDetail.getBuildingRoomNumber())
                        && barcodeInventoryErrorDetail.getBuildingSubRoomNumber()
                                .equals(barcodeInventoryErrorExpectedDetail.getBuildingSubRoomNumber())
                        && barcodeInventoryErrorDetail.getAssetConditionCode()
                                .equals(barcodeInventoryErrorExpectedDetail.getAssetConditionCode()));
    }
}

From source file:org.mifos.reports.cashconfirmationreport.BranchCashConfirmationReportBO.java

public void addCenterIssues(List<BranchCashConfirmationInfoBO> centerIssues) {
    CollectionUtils.forAllDo(centerIssues, new Closure() {
        @Override/*from  w ww . j  a v  a  2s. c om*/
        public void execute(Object input) {
            addCenterIssue((BranchCashConfirmationInfoBO) input);
        }
    });
}

From source file:org.mmadsen.sim.transmissionlab.analysis.ClusterTraitFrequencyFileSnapshot.java

public void process() {
    this.log.debug("Entering ClusterTraitFrequencyFileSnapshot.process()");
    IAgentPopulation population = this.model.getPopulation();
    // return immediately if the population isn't clustered, because we can't do anything.
    if (population.isPopulationClustered() == false) {
        return;//from  w w  w  . ja  va 2 s .c o m
    }

    /** nothing below here is executed if the population isn't structured into discrete clusters **/

    // manual hack to ensure that we only record files every N ticks
    if (this.intervalCount != 1) {
        this.intervalCount--;
        return;
    }

    int modelTick = (int) Math.round(this.model.getTickCount());
    int numClusters = population.getNumClusters();
    this.curSortedTraitCounts.clear();
    Map<Integer, Integer> totalTraitsAcrossClusters = new TreeMap<Integer, Integer>();

    for (int c = 0; c < numClusters; c++) {
        this.log.debug("Processing cluster #" + c);

        List<IAgent> agentList = population.getAgentListForCluster(c);

        this.freqMap.clear();
        this.curSortedTraitCounts.add(new ArrayList<TraitCount>());

        // fill up the frequency map
        CollectionUtils.forAllDo(agentList, this.freqCounter);

        // At this point, we've got all the counts, so let's prepare a sorted List
        // of TraitCounts for further processing
        ArrayList<TraitCount> refClusterCount = this.curSortedTraitCounts.get(c);
        refClusterCount.addAll(this.freqMap.values());

        // now we count traits ACROSS all cluster - we'll be interested in whether some
        // traits spread to more than 1 cluster.
        for (TraitCount tc : refClusterCount) {
            this.log.debug("analyzing refClusterCount for: " + tc.getTrait());
            int trait = tc.getTrait();
            if (totalTraitsAcrossClusters.containsKey(trait)) {
                int cnt = totalTraitsAcrossClusters.get(trait);
                cnt++;
                totalTraitsAcrossClusters.put(trait, cnt);
            } else {
                totalTraitsAcrossClusters.put(trait, 1);
            }
        }
        this.log.debug("totalTraitsAcrossClusters: " + totalTraitsAcrossClusters.toString());

    }

    this.sharedClusterTraitCountsByTick.put(modelTick, totalTraitsAcrossClusters);
    this.model.storeSharedObject(TRAITS_SHARED_ACROSS_CLUSTER_COUNTS, this.sharedClusterTraitCountsByTick);

    this.log.debug("recording file snapshot at " + this.model.getTickCount());

    this.recordStats(this.curSortedTraitCounts);

    this.intervalCount = this.recordingInterval;
    this.log.debug("Leaving TraitFrequencyFileSnapshot.process()");
}

From source file:org.mmadsen.sim.transmissionlab.analysis.IndividualTraitFrequencyAnalyzer.java

@SuppressWarnings("unchecked")
public void process() {
    this.log.debug("Entering TraitFrequencyAnalyzer.process at time " + this.model.getTickCount());
    // cache a fresh copy of the agent list since it may have changed due to other module's actions
    IAgentPopulation population = this.model.getPopulation();
    List<IAgent> agentList = population.getAgentList();

    // clear out the frequency map, and current list of sorted TraitCounts and recount
    // DO NOT clear out residenceTimeMap, however, since it's cumulative over the course of the run
    this.freqMap.clear();
    this.curSortedTraitCounts = null;
    this.curTurnover = 0.0;

    // fill up the frequency map
    CollectionUtils.forAllDo(agentList, this.freqCounter);

    // At this point, we've got all the counts, so let's prepare a sorted List
    // of TraitCounts for further processing
    this.curSortedTraitCounts = new ArrayList<TraitCount>();
    this.curSortedTraitCounts.addAll(this.freqMap.values());

    // update the residence time map for traits seen in this tick
    for (TraitCount trait : this.curSortedTraitCounts) {
        int agentVariant = trait.getTrait();

        if (this.residenceTimeMap.containsKey(agentVariant)) {
            // we've seen the variant before; increment the count.
            TraitCount tc = this.residenceTimeMap.get(agentVariant);
            tc.increment();//from ww w .  j a  v a2s .  c o m
            this.residenceTimeMap.put(agentVariant, tc);

        } else {
            // this is first time we've seen this variant, initialize the count
            this.residenceTimeMap.put(agentVariant, new TraitCount(agentVariant));
        }
    }

    // now update the list of trait residence times for the OpenHistogram, since it doesn't use Maps
    this.cumTraitResidenceTimeCounts.clear();
    this.cumTraitResidenceTimeCounts.addAll(this.residenceTimeMap.values());

    // capture the number of traits present in the population currently into the historical list
    this.traitCountHistory.add(this.curSortedTraitCounts.size());
    Collections.sort(curSortedTraitCounts);
    Collections.reverse(curSortedTraitCounts);

    // MEM: refactored out of the Sequence class to allow the simulation to run in batch mode
    this.curTurnover = this.calculateTurnover();

    // this is the right time to call the graph step() -- prevSortedTraitCounts still
    // represents tickCount - 1, and curSortedTraitCounts represents this tick.
    if (!this.isBatchRun) {
        this.turnGraph.step();
        this.totalVariabilityGraph.step();
        this.residenceTimeHistogram.step();
    }

    // store the current version of the turnoverHistory list in the shared repository in case
    // another module wants the current snapshot, for moving averages or something similiar
    this.model.storeSharedObject(TURNOVER_HISTORY_KEY, this.turnoverHistory);
    this.model.storeSharedObject(TRAIT_COUNT_HISTORY_KEY, this.traitCountHistory);
    this.model.storeSharedObject(AGENT_TRAIT_TOPN_KEY, this.agentsInTopNHistory);
    this.model.storeSharedObject(TRAIT_RESIDENCE_TIME_KEY, this.residenceTimeMap);
    this.model.storeSharedObject(TRAIT_TOPN_RESIDENCE_MAP_KEY, this.cumTraitTopNResidenceTimes);

    // housekeeping - store cur in prev for comparison next time around
    // and cache the current trait counts in the model shared repository for
    // other modules to use - note that inter-step comparisons *within* this class don't use
    // the shared repository - we're writing the object to the repository for other classes
    this.model.storeSharedObject(TRAIT_COUNT_LIST_KEY, this.curSortedTraitCounts);
    this.prevSortedTraitCounts = this.curSortedTraitCounts;
    this.log.debug("Leaving TraitFrequencyAnalyzer.process at time " + this.model.getTickCount());
}

From source file:org.mmadsen.sim.transmissionlab.analysis.TraitFrequencyAnalyzer.java

@SuppressWarnings("unchecked")
public void process() {
    this.log.debug("Entering TraitFrequencyAnalyzer.process at time " + this.model.getTickCount());
    // cache a fresh copy of the agent list since it may have changed due to other module's actions
    IAgentPopulation population = this.model.getPopulation();
    List<IAgent> agentList = population.getAgentList();

    // clear out the frequency map, and current list of sorted TraitCounts and recount
    // DO NOT clear out residenceTimeMap, however, since it's cumulative over the course of the run
    this.freqMap.clear();
    this.curSortedTraitCounts = null;
    this.curTurnover = 0.0;

    // fill up the frequency map
    CollectionUtils.forAllDo(agentList, this.freqCounter);

    // At this point, we've got all the counts, so let's prepare a sorted List
    // of TraitCounts for further processing
    this.curSortedTraitCounts = new ArrayList<TraitCount>();
    this.curSortedTraitCounts.addAll(this.freqMap.values());

    // update the residence time map for traits seen in this tick
    for (TraitCount trait : this.curSortedTraitCounts) {
        int agentVariant = trait.getTrait();

        if (this.residenceTimeMap.containsKey(agentVariant)) {
            // we've seen the variant before; increment the count.
            TraitCount tc = this.residenceTimeMap.get(agentVariant);
            tc.increment();//from ww  w .  ja  va2  s.  c o  m
            this.residenceTimeMap.put(agentVariant, tc);

        } else {
            // this is first time we've seen this variant, initialize the count
            this.residenceTimeMap.put(agentVariant, new TraitCount(agentVariant));
        }
    }

    // now update the list of trait residence times for the OpenHistogram, since it doesn't use Maps
    this.cumTraitResidenceTimeCounts.clear();
    this.cumTraitResidenceTimeCounts.addAll(this.residenceTimeMap.values());

    // capture the number of traits present in the population currently into the historical list
    this.traitCountHistory.add(this.curSortedTraitCounts.size());
    Collections.sort(curSortedTraitCounts);
    Collections.reverse(curSortedTraitCounts);

    // MEM: refactored out of the Sequence class to allow the simulation to run in batch mode
    this.curTurnover = this.calculateTurnover();

    // this is the right time to call the graph step() -- prevSortedTraitCounts still
    // represents tickCount - 1, and curSortedTraitCounts represents this tick.
    if (!this.isBatchRun) {
        this.turnGraph.step();
        this.totalVariabilityGraph.step();
        this.residenceTimeHistogram.step();
    }

    // store the current version of the turnoverHistory list in the shared repository in case
    // another module wants the current snapshot, for moving averages or something similiar
    this.model.storeSharedObject(TURNOVER_HISTORY_KEY, this.turnoverHistory);
    this.model.storeSharedObject(TRAIT_COUNT_HISTORY_KEY, this.traitCountHistory);
    this.model.storeSharedObject(AGENT_TRAIT_TOPN_KEY, this.agentsInTopNHistory);
    this.model.storeSharedObject(TRAIT_RESIDENCE_TIME_KEY, this.residenceTimeMap);
    this.model.storeSharedObject(TRAIT_TOPN_RESIDENCE_MAP_KEY, this.cumTraitTopNResidenceTimes);

    // housekeeping - store cur in prev for comparison next time around
    // and cache the current trait counts in the model shared repository for 
    // other modules to use - note that inter-step comparisons *within* this class don't use
    // the shared repository - we're writing the object to the repository for other classes
    this.model.storeSharedObject(TRAIT_COUNT_LIST_KEY, this.curSortedTraitCounts);
    this.prevSortedTraitCounts = this.curSortedTraitCounts;
    this.log.debug("Leaving TraitFrequencyAnalyzer.process at time " + this.model.getTickCount());
}

From source file:org.mmadsen.sim.transmissionlab.rules.ModalConformistTransmissionRule.java

private IAgentPopulation transmit(IAgentPopulation population) {
    List<IAgent> agentList = population.getAgentList();

    try {// w ww  .  jav  a  2s .co m
        this.switchingProbability = (Double) this.model.getSimpleModelPropertyByName("switchingProbability");
    } catch (RepastException ex) {
        System.out.println("FATAL EXCEPTION: " + ex.getMessage());
        System.exit(1);
    }

    Map<Integer, TraitCount> frequencyMap = new HashMap<Integer, TraitCount>();
    Closure freqCounter = new TraitFrequencyCounterClosure(this.log, frequencyMap);

    // fill up the frequency map
    CollectionUtils.forAllDo(agentList, freqCounter);

    // At this point, we've got all the counts, so let's prepare a sorted List
    // of TraitCounts for further processing
    List<TraitCount> curSortedTraitCounts = new ArrayList<TraitCount>();
    curSortedTraitCounts.addAll(frequencyMap.values());

    // sort the list - in this case the highest value will be last since we haven't reversed the list
    Collections.sort(curSortedTraitCounts);

    // MUST MODIFY IN PLACE!
    return population;
}

From source file:org.mule.test.config.ExceptionHelperTestCase.java

@Test
public void filteredStackIncludingNonMuleCode() {
    int calls = 5;
    try {//  w  ww .j a va 2  s  .  c  o m
        generateStackEntries(calls, new Closure() {
            @Override
            public void execute(Object input) {
                CollectionUtils.forAllDo(Collections.singleton(null), new Closure() {
                    @Override
                    public void execute(Object input) {
                        throw new RuntimeException(
                                new DefaultMuleException(MessageFactory.createStaticMessage("foo")));
                    }
                });
            }
        });
        fail("Expected exception");
    } catch (Exception e) {
        assertThat(ExceptionHelper.getExceptionStack(e),
                StringByLineMatcher.matchesLineByLine("foo (org.mule.api.DefaultMuleException)",
                        "  org.mule.test.config.ExceptionHelperTestCase$1$1.execute:",
                        "  org.apache.commons.collections.CollectionUtils.forAllDo:",
                        "  org.mule.test.config.ExceptionHelperTestCase$1.execute:",
                        "  org.mule.test.config.ExceptionHelperTestCase.generateStackEntries:",
                        "  (" + (calls + 13) + " more...)")); // recursive
    }
}

From source file:org.mule.util.queue.PersistentXaTransactionContext.java

public int size(QueueStore queue) {
    final AtomicInteger addSize = new AtomicInteger(0);
    CollectionUtils.forAllDo(this.transactionJournal.getLogEntriesForTx(xid), new Closure() {
        @Override//from   w  w  w.j  a  va  2s.c om
        public void execute(Object value) {
            if (((XaQueueTxJournalEntry) value).isAdd() || ((XaQueueTxJournalEntry) value).isAddFirst()) {
                addSize.incrementAndGet();
            }
        }
    });
    return queue.getSize() + addSize.get();
}

From source file:org.opencastproject.metadata.dublincore.DublinCoreCatalog.java

@Override
@SuppressWarnings("unchecked")
public List<String> get(EName property, final String language) {
    RequireUtil.notNull(property, "property");
    RequireUtil.notNull(language, "language");
    if (LANGUAGE_ANY.equals(language)) {
        return (List<String>) CollectionUtils.collect(getValuesAsList(property), new Transformer() {
            @Override//www . j a v  a2  s .  co m
            public Object transform(Object o) {
                return ((CatalogEntry) o).getValue();
            }
        });
    } else {
        final List<String> values = new ArrayList<String>();
        final boolean langUndef = LANGUAGE_UNDEFINED.equals(language);
        CollectionUtils.forAllDo(getValuesAsList(property), new Closure() {
            @Override
            public void execute(Object o) {
                CatalogEntry c = (CatalogEntry) o;
                String lang = c.getAttribute(XML_LANG_ATTR);
                if ((langUndef && lang == null) || (language.equals(lang)))
                    values.add(c.getValue());
            }
        });
        return values;
    }
}