package com.qmth.distributed.print.business.listener;

import com.alibaba.fastjson.JSON;
import com.qmth.boot.tools.excel.listener.ObjectListener;

import java.util.Collection;
import java.util.LinkedList;
import java.util.List;

/**
 * @Description: 收集器
 * @Author: CaoZixuan
 * @Date: 2024-03-21
 */
public class ObjectCollector<E> implements ObjectListener<E> {

    private final List<E> successList;

    private final List<String> errorList;

    public ObjectCollector() {
        this.successList = new LinkedList<>();
        this.errorList = new LinkedList<>();
    }

    @Override
    public void output(E obj) {
        successList.add(obj);
    }

    @Override
    public void error(int rowIndex, Collection<String> collection) {
        errorList.add(rowIndex + JSON.toJSONString(collection));
    }

    public List<E> getSuccessList() {
        return successList;
    }

    public List<String> getErrorList() {
        return errorList;
    }
}
