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.

21 lines
452 B

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