Uploaded image for project: 'Commons Collections'
  1. Commons Collections
  2. COLLECTIONS-182

[collections] Change CollectionUtils.forAllDo to return the Closure

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 3.1
    • 4.0-alpha1, 4.0
    • None
    • None
    • Operating System: All
      Platform: All

    • 35955

    Description

      I frequently use CollectionUtils.forAllDo with a Closure that determines some
      kind of aggregate value across the members of the Collection. For example, and
      this is entirely manufactured, say I have an Order with a collection of
      LineItems. Order might use a SumClosure to count the number of actual items (not
      LineItem objects) on the Order or to compute the sum of the LineItems cost. It
      would be convenient in these cases if I could use the return of forAllDo to
      chain method calls like this:

      public BigDecimal getTotal()

      { return CollectionUtils.forAllDo(lineItems, new SumTotalClosure()).total(); }

      As it is, I have to make do with the somewhat less compact:

      public BigDecimal getTotal()

      { SumTotalClosure closure = new SumTotalClosure(); CollectionUtils.forAllDo(lineItems, closure); return closure.total(); }

      Thanks for considering it.

      Regards,
      Jim Cakalic

      Attachments

        Activity

          People

            Unassigned Unassigned
            james.cakalic@charter.net Jim Cakalic
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: