// Collect the results for all states
for (Map<String, Object> row : stats) {
ContentState state = (ContentState) row.get("state");
Long msgCount = (Long) row.get("msgCount");
Long wordCount = (Long) row.get("wordCount");
LocaleId localeId = (LocaleId) row.get("locale");
TransUnitCount transUnitCount =
transUnitCountMap.get(localeId.getId());
if (transUnitCount == null) {
transUnitCount = new TransUnitCount();
transUnitCountMap.put(localeId.getId(), transUnitCount);
}
TransUnitWords transUnitWords =
transUnitWordsMap.get(localeId.getId());
if (transUnitWords == null) {
transUnitWords = new TransUnitWords();
transUnitWordsMap.put(localeId.getId(), transUnitWords);
}
transUnitCount.set(state, msgCount.intValue());
transUnitWords.set(state, wordCount.intValue());
}
for (TransUnitCount stat : transUnitCountMap.values()) {
stat.set(
ContentState.New,
StatisticsUtil.calculateUntranslated(
new Long(stat.getTotal()), stat));
}
for (TransUnitWords stat : transUnitWordsMap.values()) {
stat.set(
ContentState.New,
StatisticsUtil.calculateUntranslated(
new Long(stat.getTotal()), stat));
}
// Merge into a single Stats object
for (String locale : transUnitCountMap.keySet()) {
ContainerTranslationStatistics newStats =
new ContainerTranslationStatistics();
newStats.addStats(new TranslationStatistics(transUnitCountMap
.get(locale), locale));
newStats.addStats(new TranslationStatistics(transUnitWordsMap
.get(locale), locale));
if (newStats.getStats(locale, StatUnit.MESSAGE) != null
&& newStats.getStats(locale, StatUnit.WORD) != null) {
returnStats.put(new LocaleId(locale), newStats);
}
}
return returnStats;
}