Reputation: 490
Lets say, I am fetching the data from excel and I need to map two things.
ID and the corresponding Dates, Excel data look like this :-
ID Dates
N1#N1 2018-10-09,2018-10-10#2018-10-11
Actual output should look like this :-
{N1=2018-10-09,2018-10-10} {N1=2018-10-11}
I have tried below code:-
//Fetching from using in soap ui
String id = context.expand('${Data#ID}')
String dt = context.expand('${Data#Dates}')
List arrId = id.split('#')
def strD
LinkedHashMap < String, String > dateMap= new LinkedHashMap <
String, String > ()
for(int i=0; i<arrId.size(); i++) {
strD = dt.split("#").asType(List)[i]
dateMap.put(arrId[i],strD)
}
log.info dateMap
Could anyone help me on this?
Upvotes: 0
Views: 145
Reputation: 3016
Try this:
def ids = "N1#N1".split('#')
def dts = "2018-10-09,2018-10-10#2018-10-11".split('#')
List<Map> result = (0..ids.size()-1).collect{
[(ids[it]): dts[it]]
}
assert result == [[N1:"2018-10-09,2018-10-10"], [N1:"2018-10-11"]]
Upvotes: 1