我发现使用Java8 + Apache.POI造成了误解:
(itemList)
(sheet)
并转换为行流(checkSap(row, importProperties.getSapIndex())
itemList.add(rowToItem(row2, impProp)
row2
你知道我该怎么解决吗?
一段代码:
List<Item> itemList = new ArrayList<>();
StreamSupport.stream(sheet.spliterator(), false)
.filter(row -> checkSap(row, importProperties.getSapIndex())
.forEach(row2 -> {
itemList.add(rowToItem(row2, impProp));
});
RowToItem函数:
private Item rowToItem(XSSFRow row, ImportProperties importProperties) {
Item item = new Item();
item.setSap(getString(row, importProperties.getSapIndex()));
return item;
}
ImpProp类:
public class ImpProp{
private String sapText;
private Integer sapIndex;
public boolean findSap(Row row) {
Optional<Integer> optionalIndex = StreamSupport.stream(row.spliterator(), false)
.filter(cell -> ((cell.getCellType() == Cell.CELL_TYPE_STRING)
&& (cell.getStringCellValue().trim().equalsIgnoreCase(sapText.trim()))))
.findAny()
.map(cell -> cell.getColumnIndex());
if (optionalIndex.getClass().isInstance(Integer.class)) {
sapIndex = optionalIndex.get();
return true;
}
return false;
}
public Integer getSapIndex() {
return sapIndex;
}
}
答案 0 :(得分:3)
您不缺少右括号吗?根据您的代码,您知道。
StreamSupport.stream(sheet.spliterator(), false)
.filter(row -> checkSap(row, importProperties.getSapIndex()))
.forEach(row2 -> {
itemList.add(rowToItem(row2, impProp));
});
在带有filter的行上应该有三个右括号。否则,forEach
方法将应用于checkSap
方法的结果。