package kata.gameoflife.a20170806; import java.util.List; /** * Game of Life Kata. * Copyright (c) 2017, Peter Kofler, licensed under BSD License. */ public class CountLivingNeighbourCells { private final LocateNeighbourCells locateNeighbourCells; private final LookupLivingCells lookupLivingCells; public CountLivingNeighbourCells(LocateNeighbourCells locateNeighbourCells, LookupLivingCells lookupLivingCells) { this.locateNeighbourCells = locateNeighbourCells; this.lookupLivingCells = lookupLivingCells; } public int count() { List neighbourCells = locateNeighbourCells.locateNeighbourCells(); return (int) neighbourCells.stream(). // filter(lookupLivingCells::isAlive). // count(); } // calculateSurroundingCoordinates is the function we are interested. In this case // it is a pain that we also close over the (x,y) because now each CountingNeighbours // has a CalculateSurroundingCoordinates in its constructor. On the other hand, with // the long but exact name, it kind of looks good. }