Groovy web console

subscribe to the feed Subscribe
to this
site

Script

Published 2 months ago by Nayana with tags TCS
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
count = [:]
def addToList(value)
{
 if(count.containsKey(value))
 {
  if(count[value]>=5) return false;
  else return count[value]++;
 }
 else
 {
  count[value] = 1;
  return true;
 }
}
DataMap = ['BRNT-METNET-3B 4/1/3':'Alcatel', 'NMAL-METNET-2A 1/1/6':'Alcatel', 'NMAL-METNET-2A 1/1/7':'Alcatel', 'NMAL-METNET-2A 1/1/8':'Alcatel', 'NMAL-METNET-2A 1/1/9':'Alcatel', 'NMAL-METNET-2A 1/2/6':'Alcatel', 'NMAL-METNET-2A 2/1/6':'Alcatel']
resultMap = [:]
for (ele in DataMap)
{
 if(addToList(ele.key.split(' ')[0]))
    resultMap[ele.key] = ele.value;
}
println(resultMap)