package org.gcube.phd; import java.util.HashMap; import java.util.Map; import java.util.SortedMap; import java.util.TreeMap; import org.gcube.common.scope.impl.ScopeBean; import org.gcube.common.scope.impl.ScopeBean.Type; import org.gcube.context.ContextElaborator; public class StatisticsCollector extends ContextElaborator { private Map contextCount; private SortedMap sortedMap; public StatisticsCollector() {} @Override public void elaborateContext(ScopeBean scopeBean) throws Exception { Type type = scopeBean.type(); Integer integer = contextCount.get(type); if(integer == null) { integer = 0; } contextCount.put(type, integer + 1); ContextStatistic contextStatistic = new ContextStatistic(scopeBean); sortedMap.put(scopeBean, contextStatistic); } public SortedMap getStatistics() throws Exception{ if(sortedMap == null) { contextCount = new HashMap<>(); sortedMap = new TreeMap<>(); all(); } return sortedMap; } public Map getContextCount() throws Exception { if(contextCount == null) { contextCount = new HashMap<>(); sortedMap = new TreeMap<>(new ScopeBeanComparator()); all(); } return contextCount; } }