use of common.order.ReverseOrderLookUp in project solution-finder by knewjade.
the class PathCore method getPiecesPattern.
private HashSet<LongPieces> getPiecesPattern(HashSet<LongPieces> piecesSolution) {
if (isHoldReduced) {
// allとvalidが異なる
ReverseOrderLookUp reverseOrderLookUp = new ReverseOrderLookUp(maxDepth, maxDepth + 1);
return piecesSolution.stream().filter(validPieces::contains).flatMap(blocks -> {
return reverseOrderLookUp.parse(blocks.getPieces()).map(stream -> stream.collect(Collectors.toCollection(ArrayList::new))).flatMap(blocksWithHold -> {
int nullIndex = blocksWithHold.indexOf(null);
if (nullIndex < 0)
return Stream.of(new LongPieces(blocksWithHold));
Stream.Builder<LongPieces> builder = Stream.builder();
for (Piece piece : Piece.values()) {
blocksWithHold.set(nullIndex, piece);
builder.accept(new LongPieces(blocksWithHold));
}
return builder.build();
});
}).filter(allPieces::contains).collect(Collectors.toCollection(HashSet::new));
} else if (isUsingHold) {
// allとvalidが同じだが、ホールドが使える
ReverseOrderLookUp reverseOrderLookUp = new ReverseOrderLookUp(maxDepth, maxDepth);
return piecesSolution.stream().filter(validPieces::contains).flatMap(blocks -> {
return reverseOrderLookUp.parse(blocks.getPieces()).map(stream -> stream.collect(Collectors.toCollection(ArrayList::new))).flatMap(blocksWithHold -> {
int nullIndex = blocksWithHold.indexOf(null);
if (nullIndex < 0)
return Stream.of(new LongPieces(blocksWithHold));
Stream.Builder<LongPieces> builder = Stream.builder();
for (Piece piece : Piece.values()) {
blocksWithHold.set(nullIndex, piece);
builder.accept(new LongPieces(blocksWithHold));
}
return builder.build();
});
}).filter(allPieces::contains).collect(Collectors.toCollection(HashSet::new));
} else {
// そのまま絞り込みだけ実施
return piecesSolution.stream().filter(validPieces::contains).collect(Collectors.toCollection(HashSet::new));
}
}
Aggregations