Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-3622

gpath regression: lists of lists are no longer flattened as in Groovy 1.0

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Not A Problem
    • 1.6
    • 1.6.4, 1.7-beta-1
    • None
    • None
    • Groovy 1.5.7 and 1.6.0

    Description

      Groovy in Action listing 7.23 no longer works, because when a gpath property refers to a list, this list is no longer flattenend.

      So the original listing:

      class Invoice {
        List items
        Date date
      }
      class LineItem {
        Product product
        int count
        int total() {
          return product.dollar * count
        }
      }
      class Product {
        String name
        def dollar
      }
      def ulcDate = new Date(107,0,1)
      def ulc = new Product(dollar:1499, name:'ULC')
      def ve = new Product(dollar:499, name:'Visual Editor')
      def invoices = [
        new Invoice(date:ulcDate, items: [
          new LineItem(count:5, product:ulc),
          new LineItem(count:1, product:ve)
        ]),
        new Invoice(date:[107,1,2], items: [
          new LineItem(count:4, product:ve)
        ])
      ]
      assert [5*1499, 499, 4*499] == invoices.items*.total()
      assert ['ULC'] ==
        invoices.items.grep{it.total() > 7000}.product.name
      def searchDates = invoices.grep{
        it.items.any{it.product == ulc}
      }.date*.toString()
      assert [ulcDate.toString()] == searchDates
      

      would need to change its assertions to

      assert [5*1499, 499, 4*499] == invoices.items.flatten()*.total()
      assert ['ULC'] ==
        invoices.items.flatten().grep{it.total() > 7000}.product.name
      def searchDates = invoices.grep{
        it.items.flatten().any{it.product == ulc}
      }.date*.toString()
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            codevise Dierk König
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: