AbstractAnalyser.java from Tea Stats at Krugle
Show AbstractAnalyser.java syntax highlighted
package net.time4tea.webstats.analyser;
import net.time4tea.webstats.analyser.extractor.ExtractionException;
import net.time4tea.webstats.analyser.extractor.key.KeyFinder;
import net.time4tea.webstats.analyser.extractor.value.ValueFinder;
import net.time4tea.webstats.jms.EnvironmentException;
import net.time4tea.webstats.process.Processor;
import net.time4tea.webstats.record.Record;
import net.time4tea.webstats.statistic.StatisticMap;
import net.time4tea.webstats.statistic.repo.StatisticMapRepository;
import net.time4tea.webstats.util.Bug;
import org.hamcrest.Matcher;
/**
* Originally richja 12-Jul-2007
*/
public class AbstractAnalyser<T extends Record> implements Processor<T> {
protected String name;
protected StatisticMapRepository statisticMapRepository;
protected Matcher<T> filter;
protected KeyFinder<T> visitor;
protected ValueFinder valueFinder;
public AbstractAnalyser(String name, Matcher<T> filter, StatisticMapRepository statisticMapRepository, KeyFinder<T> keyFinder, ValueFinder valueFinder) {
this.name = name;
this.visitor = keyFinder;
this.statisticMapRepository = statisticMapRepository;
this.valueFinder = valueFinder;
this.filter = filter;
}
public boolean process(T record) throws EnvironmentException {
if (record == null) {
return false;
}
if (filter.matches(record)) {
String key = null;
try {
key = visitor.getKey(record);
}
catch (ExtractionException e) {
throw new Bug("Can't get value from record", e);
}
if (key != null) {
getStatisticMap(record).hit(key, valueFinder.getValue(record));
}
}
return true;
}
protected StatisticMap getStatisticMap(T record) throws EnvironmentException {
return statisticMapRepository.getStatisticMapForInstant(name, record.getDate());
}
}
See more files for this project here