Skip to content
Snippets Groups Projects

Resolve "Fix large grid display"

Merged Colin DAMON requested to merge 110-fix-large-grid-display into master
3 files
+ 24
55
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -19,11 +19,12 @@ public class Grid {
}
private Set<Cell> buildDeadCells(Set<Cell> aliveCells) {
return aliveCells.stream()
.map(Box::new)
.flatMap(Box::cells)
.filter(cell -> !aliveCells.contains(cell))
.collect(Collectors.toUnmodifiableSet());
return aliveCells
.stream()
.map(Box::new)
.flatMap(Box::cells)
.filter(cell -> !aliveCells.contains(cell))
.collect(Collectors.toUnmodifiableSet());
}
public boolean isAlive(Cell cell) {
@@ -65,15 +66,11 @@ public class Grid {
}
private Stream<Cell> cells() {
return IntStream.range(leftColumn(), rightColumn())
.mapToObj(Integer::valueOf)
.flatMap(column -> cellsColumn(column));
return IntStream.range(leftColumn(), rightColumn()).mapToObj(Integer::valueOf).flatMap(column -> cellsColumn(column));
}
private Stream<Cell> cellsColumn(Integer column) {
return IntStream.range(topRow(), bottomRow())
.mapToObj(Integer::valueOf)
.map(row -> new Cell(row, column));
return IntStream.range(topRow(), bottomRow()).mapToObj(Integer::valueOf).map(row -> new Cell(row, column));
}
public int topRow() {
@@ -104,29 +101,17 @@ public class Grid {
}
private static Point topLeft(Set<Cell> cells) {
int row = cells.stream()
.mapToInt(Cell::row)
.min()
.orElse(0);
int row = cells.stream().mapToInt(Cell::row).min().orElse(0);
int column = cells.stream()
.mapToInt(Cell::column)
.min()
.orElse(0);
int column = cells.stream().mapToInt(Cell::column).min().orElse(0);
return new Point(row - 1, column - 1);
}
private static Point bottomRight(Set<Cell> cells) {
int row = cells.stream()
.mapToInt(Cell::row)
.max()
.orElse(0);
int column = cells.stream()
.mapToInt(Cell::column)
.max()
.orElse(0);
int row = cells.stream().mapToInt(Cell::row).max().orElse(0);
int column = cells.stream().mapToInt(Cell::column).max().orElse(0);
return new Point(row + 1, column + 1);
}
Loading