public void addInPlace(SentenceKey key, SentenceStatistics sentenceStatistics) { for (Map<SentenceKey, EnsembleStatistics> impl : this.impl) { EnsembleStatistics stats = impl.get(key); if (stats == null) { stats = new EnsembleStatistics(new LinkedList<SentenceStatistics>()); impl.put(key, stats); } stats.addInPlace(sentenceStatistics); } }
public TrainingStatistics merge(TrainingStatistics other) { Map<SentenceKey, EnsembleStatistics> newStats = new HashMap<>(); // Add elements from this statistics for (Map<SentenceKey, EnsembleStatistics> map : this.impl) { for (SentenceKey key : map.keySet()) { newStats.put(key, new EnsembleStatistics(map.get(key))); } } // Add elements from other statistics for (Map<SentenceKey, EnsembleStatistics> map : other.impl) { for (SentenceKey key : map.keySet()) { EnsembleStatistics existing = newStats.get(key); if (existing == null) { existing = new EnsembleStatistics(new LinkedList<SentenceStatistics>()); newStats.put(key, existing); } existing.addInPlace(map.get(key)); } } // Return return new TrainingStatistics(Maybe.Just(newStats)); }