package leigh.conflux.nodegraph;

import leigh.eo.EO;
import leigh.mecha.log.MechaLogger;
import leigh.mecha.log.MechaLoggerFactory;
import leigh.mecha.nodegraph.ProcessorState;

import java.io.Serializable;

public class CountNode extends AggregateNode {
    private static final MechaLogger logger = MechaLoggerFactory.getLogger(CountNode.class);
    public static final String TYPE = "count";
    int value;

    public CountNode(String id) {
        super(id);
    }

    @Override
    public void start(ProcessorState state) {
        value = 0;
        logger.info("Count starting...");
    }

    @Override
    public void processRow(EO row, String key, ProcessorState state) {
        value++;
        logger.info("Counted row");
    }

    @Override
    public Serializable finish(ProcessorState state) {
        return value;
    }
}
