使用来自另一个地图 <String, List<String>> 的选择性元素创建一个新地图 <String, List<String>>
Create a new Map <String, List<String>> with selective elements from another Map <String, List<String>>
我正在尝试使用来自另一个 Map <String, List<String>> invoiceErrorLines
的选择性元素创建一个新的 Map <String, List<String>> headErrors
invoiceErrorLines = ['1660277':['Line : 1 Invoice does not foot Reported', 'Line : 2 MATH ERROR'],
'1660278':['Line : 5 Invoice does not foot Reported', 'cl_id is a required field'],
'1660279':['Line : 7 could not parse date ', 'File Error : The file doesnt have delimiter'],
'1660280':['Line : 9 Invoice error']]
def regex = "^Line\s(?:(\d+)\s)?\s*:\s+(\d+)?.+"
def headErrors = invoiceErrorLines.each{ inv ->
inv.value.findAll{it.contains('Invoice does not foot Reported') || !(it ==~ regex) }.groupBy{inv.key}
}
新地图应包含作为键的发票编号及其相应的错误消息,该错误消息与 regex = "^Line\s(?:(\d+)\s)?\s*:\s+(\d+)?.+"
不匹配但包含 Invoice does not foot Reported
当我打印 headErrors
时,我看到的地图与 invoiceErrorLines
相同,但是
我期待 headErrors
如下
headErrors = ['1660277':['Line : 1 Invoice does not foot Reported'],
'1660278':['Line : 5 Invoice does not foot Reported', 'cl_id is a required field'],
'1660279':['File Error : The file doesnt have delimiter']
]
有人可以帮我解决这个问题吗?
有
def headErrors = invoiceErrorLines.collectEntries{ key, value ->
value.findAll{ it.contains('Invoice does not foot Reported') || !(it ==~ regex) }.groupBy{ key }
}
它产生
[1660277:[Line : 1 Invoice does not foot Reported], 1660278:[Line : 5 Invoice does not foot Reported, cl_id is a required field], 1660279:[File Error : The file doesnt have delimiter]]
我正在尝试使用来自另一个 Map <String, List<String>> invoiceErrorLines
Map <String, List<String>> headErrors
invoiceErrorLines = ['1660277':['Line : 1 Invoice does not foot Reported', 'Line : 2 MATH ERROR'],
'1660278':['Line : 5 Invoice does not foot Reported', 'cl_id is a required field'],
'1660279':['Line : 7 could not parse date ', 'File Error : The file doesnt have delimiter'],
'1660280':['Line : 9 Invoice error']]
def regex = "^Line\s(?:(\d+)\s)?\s*:\s+(\d+)?.+"
def headErrors = invoiceErrorLines.each{ inv ->
inv.value.findAll{it.contains('Invoice does not foot Reported') || !(it ==~ regex) }.groupBy{inv.key}
}
新地图应包含作为键的发票编号及其相应的错误消息,该错误消息与 regex = "^Line\s(?:(\d+)\s)?\s*:\s+(\d+)?.+"
不匹配但包含 Invoice does not foot Reported
当我打印 headErrors
时,我看到的地图与 invoiceErrorLines
相同,但是
我期待 headErrors
如下
headErrors = ['1660277':['Line : 1 Invoice does not foot Reported'],
'1660278':['Line : 5 Invoice does not foot Reported', 'cl_id is a required field'],
'1660279':['File Error : The file doesnt have delimiter']
]
有人可以帮我解决这个问题吗?
有
def headErrors = invoiceErrorLines.collectEntries{ key, value ->
value.findAll{ it.contains('Invoice does not foot Reported') || !(it ==~ regex) }.groupBy{ key }
}
它产生
[1660277:[Line : 1 Invoice does not foot Reported], 1660278:[Line : 5 Invoice does not foot Reported, cl_id is a required field], 1660279:[File Error : The file doesnt have delimiter]]