错误:不兼容的类型:推断变量T具有不兼容的边界excel Java Apache poi

时间:2019-11-21 07:51:24

标签: java spring-boot apache-poi

我更改了映射中的所有数据类型,但是我不知道代码的哪部分是错误的:

  

错误:类型不兼容:推断变量T具有不兼容   边界相等约束:地图       下限:映射,其中T是类型变量:       T扩展了方法toList()中声明的对象

-这是我的代码-

public List<Map<String, String>> upload(MultipartFile file) throws Exception {

        Path tempDir = Files.createTempDirectory("");

        File tempFile = tempDir.resolve(file.getOriginalFilename()).toFile();

        file.transferTo(tempFile);

        Workbook workbook = WorkbookFactory.create(tempFile);

        Sheet sheet = workbook.getSheetAt(0);

        Supplier<Stream<Row>> rowStreamSupplier = uploadUtils.getRowStreamSupplier(sheet);

        Row headerRow = rowStreamSupplier.get().findFirst().get();

        List<String> headerCells = uploadUtils.getStream(headerRow)
                .map(Cell::getStringCellValue) 
                .collect(Collectors.toList());

        int colCount = headerCells.size();

        return rowStreamSupplier.get()
                .skip(1)
                .map(row -> {

                    Map<CellType, List<Cell>> cellListMap = uploadUtils.getStream(row)
                    .collect(Collectors.groupingBy(Cell::getCellTypeEnum));

                    List<Object> cellList = Stream.of(
                    cellListMap.get(CellType.NUMERIC).stream().map(Cell::getNumericCellValue),
                    cellListMap.get(CellType.STRING).stream().map(Cell::getStringCellValue)
                    ).collect(Collectors.toList());     

                    return uploadUtils.cellIteratorSupplier(colCount)
                             .get()
                             .collect(toMap(headerCells::get, cellList::get));
        })
        .collect(Collectors.toList());
    }

-UploadUtils.java-

public class UploadUtils {

    public Supplier<Stream<Row>> getRowStreamSupplier(Iterable<Row> rows) {
        return () -> getStream(rows);
    }

    public <T> Stream<T> getStream(Iterable<T> iterable) {
        return StreamSupport.stream(iterable.spliterator(), false);
    }

    public Supplier<Stream<Integer>> cellIteratorSupplier(int end) {
        return () -> numberStream(end);
    }

    public Stream<Integer> numberStream(int end) {
        return IntStream.range(0, end).boxed();
    }

}

0 个答案:

没有答案