So I'm making a research on which method in groovy makes faster result.
Let's say we have:
def storage = [{item:"apple", amount:3, color: "red"}, {item:"mango", amount:5, color: "yellow"}]
Is doing this:
def someMap = [:]
storage.each {
someMap[it.item] = [amount: it.amount, color: it.color]
}
So when we need to get the amount of an item, we do this:
someMap["apple"].amount
Better than doing this? :
def storageFindByItem = { itemName ->
return storage.find{
i -> i.item == itemName
}
}
So when we need to get the amount of an item, we do this:
storageFindByItem("apple").amount