3
我想通過刪除已經顯示在屏幕上的重複點來減少我的數據。如何在Java 8中應用reduce/collect過濾器,有單獨的索引?
這是我在Java 7中的代碼
public List<Integer> getFilterIndexes(List<PlotPoint> pixels) {
List<Integer> indexResults = new ArrayList<Integer>(pixels.size());
HashSet<Integer> magList = new HashSet<Integer>(pixels.size());
int pixelStartIndex = 0;
for (int i=1; i < pixels.size(); i++) {
if (pixels.get(i).getX() - pixels.get(pixelStartIndex).getX() < widthInterval) {
int pixelRow = (int) ((pixels.get(i).getY() - minHeight/heightInterval);
if (!magList.add(pixelRow) {
continue;
}
} else {
pixelStartIndex = i;
magList.clear();
}
indexResult.add(i);
}
}
是否有可能實現這個用Java 8? 我想過使用pixelRow的函數mapToInt(index,pixelRow);
Function<PlotPoint, Integer> pixelRow = (n)->(int) (n.getY()-minHeight/heightInterval);
,但不知道如何實現降低或使用當前像素或plotPoint和以前保存的plotPoint收集。
任何想法?
您_might_能夠攻入流這一點,但它的將是天文數字比你已經得到的可讀性。堅持你現在的代碼。 –
最大的障礙不在於索引,而在於相遇順序的依賴。 – Holger