All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.dbstarll.utils.lang.line.LineOperateExecutor Maven / Gradle / Ivy

The newest version!
package io.github.dbstarll.utils.lang.line;

/**
 * 行处理器执行接口.
 *
 * @param  行处理返回的类型
 * @author dbstar
 */
public class LineOperateExecutor> extends AbstractLineOperateExecutor {
    private final LineOperator operator;

    protected LineOperateExecutor(LineOperator operator) {
        this.operator = operator;
    }

    public static > LineOperateExecutor build(LineOperator operator) {
        return new LineOperateExecutor(operator);
    }

    @Override
    protected final int operate(final Iterable lines, long startTime) {
        int count = 0;
        for (String line : lines) {
            operate(line);
            if (++count % 10000 == 0) {
                report(count, startTime, startTime = System.currentTimeMillis(), true);
            }
        }
        return count;
    }

    protected void operate(String line) {
        try {
            countResult(operator.operate(line));
        } catch (Throwable ex) {
            logger.warn("operate failed for line: " + line, ex);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy