Java 创建新地图<;字符串,列表<;字符串>&燃气轮机;使用其他地图中的选择性元素<;字符串,列表<;字符串>&燃气轮机;
我试图创建一个新的Java 创建新地图<;字符串,列表<;字符串>&燃气轮机;使用其他地图中的选择性元素<;字符串,列表<;字符串>&燃气轮机;,java,regex,collections,groovy,Java,Regex,Collections,Groovy,我试图创建一个新的Map headErrors,其中包含来自另一个Map invoiceErrorLines 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
Map headErrors
,其中包含来自另一个Map invoiceErrorLines
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+(\\d+)?+”
,但包含未报告的发票
当我打印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]]
谢谢你的回答。我很感激。你能帮我解决这个问题吗?