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.

26 lines
599 B

  1. package de.edu.hsfulda.ciip.tdd;
  2. import java.util.List;
  3. public class StateDead implements State {
  4. private static final int REQUIRED_FOR_CHANGE = 3;
  5. @Override
  6. public State nextBy(List<State> neigborStates) {
  7. long alifeNeigbors = countAliveNeighbors(neigborStates);
  8. return findNextStateBy(alifeNeigbors);
  9. }
  10. private State findNextStateBy(long alifeNeigbors) {
  11. if (REQUIRED_FOR_CHANGE == alifeNeigbors)
  12. return this;
  13. else
  14. return this;
  15. }
  16. private long countAliveNeighbors(List<State> neigborStates) {
  17. return neigborStates.stream().filter(state -> this != state).count();
  18. }
  19. }