Search in sources :

Example 1 with NotRepeatExecutor

use of com.alibaba.excel.event.NotRepeatExecutor in project easyexcel by alibaba.

the class AbstractWriteHolder method sortAndClearUpHandler.

protected void sortAndClearUpHandler(List<WriteHandler> handlerList, boolean runOwn) {
    // sort
    Map<Integer, List<WriteHandler>> orderExcelWriteHandlerMap = new TreeMap<>();
    for (WriteHandler handler : handlerList) {
        int order = handler.order();
        if (orderExcelWriteHandlerMap.containsKey(order)) {
            orderExcelWriteHandlerMap.get(order).add(handler);
        } else {
            List<WriteHandler> tempHandlerList = new ArrayList<>();
            tempHandlerList.add(handler);
            orderExcelWriteHandlerMap.put(order, tempHandlerList);
        }
    }
    // clean up
    Set<String> alreadyExistedHandlerSet = new HashSet<>();
    List<WriteHandler> cleanUpHandlerList = new ArrayList<>();
    for (Map.Entry<Integer, List<WriteHandler>> entry : orderExcelWriteHandlerMap.entrySet()) {
        for (WriteHandler handler : entry.getValue()) {
            if (handler instanceof NotRepeatExecutor) {
                String uniqueValue = ((NotRepeatExecutor) handler).uniqueValue();
                if (alreadyExistedHandlerSet.contains(uniqueValue)) {
                    continue;
                }
                alreadyExistedHandlerSet.add(uniqueValue);
            }
            cleanUpHandlerList.add(handler);
        }
    }
    // build chain
    if (!runOwn) {
        this.writeHandlerList = new ArrayList<>();
    }
    for (WriteHandler writeHandler : cleanUpHandlerList) {
        buildChain(writeHandler, runOwn);
    }
}
Also used : ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) NotRepeatExecutor(com.alibaba.excel.event.NotRepeatExecutor) WriteHandler(com.alibaba.excel.write.handler.WriteHandler) WorkbookWriteHandler(com.alibaba.excel.write.handler.WorkbookWriteHandler) RowWriteHandler(com.alibaba.excel.write.handler.RowWriteHandler) CellWriteHandler(com.alibaba.excel.write.handler.CellWriteHandler) SheetWriteHandler(com.alibaba.excel.write.handler.SheetWriteHandler) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) HashSet(java.util.HashSet)

Aggregations

NotRepeatExecutor (com.alibaba.excel.event.NotRepeatExecutor)1 CellWriteHandler (com.alibaba.excel.write.handler.CellWriteHandler)1 RowWriteHandler (com.alibaba.excel.write.handler.RowWriteHandler)1 SheetWriteHandler (com.alibaba.excel.write.handler.SheetWriteHandler)1 WorkbookWriteHandler (com.alibaba.excel.write.handler.WorkbookWriteHandler)1 WriteHandler (com.alibaba.excel.write.handler.WriteHandler)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1