Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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.flatten()*.total() //1
- assert ['ULC'] == invoices.items.flatten().grep{it.total() > 7000}.product.name //2
- def searchDates = invoices.grep{
- it.items.any{ it.product == ulc }
- }.date*.toString() //3
- assert [ulcDate.toString()] == searchDates
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement