You don't need the two loops... And could you change sysMonitors to SortedMap (impl. e.g. by TreeMap) so that the keys don't have to be sorted in every generateXXX method, just to iterate over sysMonitors.entrySet()?