package lc.conflux.nodegraph;

import lc.eo.EO;
import lc.mecha.log.MechaLogger;
import lc.mecha.log.MechaLoggerFactory;
import lc.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;
    }
}
