private int getFinalSegmentNumber() {
    int endSegmentNumber = getTemplate().getEndSegmentNumber();
    if (endSegmentNumber < 0 && getSelectionBeforeTemplate() == null) {
      endSegmentNumber = getTemplate().getVariableSegmentNumber(Template.SELECTION);
    }
    return endSegmentNumber;
  }
private int getFinalSegmentNumber()