You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
774 B

  1. package de.edu.hsfulda.ccip.tdd.withdependencies;
  2. import java.util.Collection;
  3. import java.util.LinkedList;
  4. import java.util.stream.Collectors;
  5. public class GameOfLifeCell {
  6. private GameOfLifeStatus status;
  7. private final Collection<GameOfLifeCell> neighborStates = new LinkedList<>();
  8. private GameOfLifeStatus nexState;
  9. public GameOfLifeCell(GameOfLifeStatus status) {
  10. this.status = status;
  11. }
  12. public void addNeighbor(GameOfLifeCell neighbor) {
  13. neighborStates.add(neighbor);
  14. }
  15. public void caclulateNextState() {
  16. nexState = status
  17. .calculateNextBy(neighborStates.stream().map(GameOfLifeCell::getState).collect(Collectors.toList()));
  18. }
  19. public GameOfLifeStatus getState() {
  20. return status;
  21. }
  22. public void updateState() {
  23. status = nexState;
  24. }
  25. }