private void merge(final WordAlignmentState state){
  if (!stack.isEmpty() && state.isComplete()) {
    final WordAlignmentState parentState=stack.pop();
    if (parentState.isComplete()) {
      throw new IllegalStateException("Parent state already complete");
    }
    parentState.substituteIn(state);
    merge(parentState);
  }
 else {
    stack.add(state);
  }
}

private void merge ( final WordAlignmentState state ) { if ( ! stack . isEmpty ( ) && state . isComplete ( ) ) { final WordAlignmentState parentState = stack . pop ( ) ; if ( parentState . isComplete ( ) ) { throw new IllegalStateException ( "Parent state already complete" ) ; } parentState . substituteIn ( state ) ; merge ( parentState ) ; } else { stack . add ( state ) ; } }
merges a state with the top of the stack if applicable or places it on top of the stack .
