Is there a way to find the Mean of a named property in a LinkedHashMap belonging to each of a Collection of Agents, without iterating the collection?
In plain Java terms, that could be restated as "find the Mean of a property stored in a LinkedHashMap belonging to each item of a List". Indeed, it has to be done from a List, as the Agent collection has to be filtered first, based upon the value of a variable.
Duplicating the LinkedHashMap property in a standalone parameter is not an option, as there are actually 135 of them, which is one reason why they're in the LinkedHashMap, and it would therefore negate any performance benefit when compared to iterating the one for which the mean is required at any given point.
In response to Benjamin's question, here's my current code to do it manually, where sParam is the stub of the LinkedHashMap item name and iSegment is the unique:
// Iterate the Products:
for (Product oProduct : Products.findAll(
p -> p.v_active == true
)) {
// Add the Segment value for this Param:
iCountProducts++;
dblTotal += oProduct.v_paramMap.getOrDefault(sParam + Integer.toString(iSegment), 0.0);
}
// Calculate the mean:
dblReturn = dblTotal / iCountProducts;
I'm simply wondering if there's an averageWhere style that can be adapted to this situation. No biggie if not - the above runs 1000 times in 0.008 seconds.