class PunctuationMarkAtParagraphEnd2 extends TextLevelRule {

  // more than this many word tokens needed for a "real" paragraph that requires a period (etc) at the end:
  private static final int TOKEN_THRESHOLD = 10;
  
  private final Language lang;

  public PunctuationMarkAtParagraphEnd2(ResourceBundle messages, Language lang) {
    super(messages);
    this.lang = Objects.requireNonNull(lang);
    super.setCategory(Categories.PUNCTUATION.getCategory(messages));
    setLocQualityIssueType(ITSIssueType.Grammar);
//  setDefaultTempOff();  // TODO
    setDefaultOff(); 

  }

  @Override
  public String getId() {
    return "PUNCTUATION_PARAGRAPH_END2";
  }

  @Override
  public String getDescription() {
    return messages.getString("punctuation_mark_paragraph_end_desc");
  }
  
  @Override
  public RuleMatch[] match(List<AnalyzedSentence> sentences) throws IOException {
    List<RuleMatch> ruleMatches = new ArrayList<>();
    int pos = 0;
    int sentPos = 0;
    int tokenCount = 0;
    for (AnalyzedSentence sentence : sentences) {
      AnalyzedTokenReadings[] tokens = sentence.getTokens();
      for (AnalyzedTokenReadings token : tokens) {
        if (!token.isNonWord() && !token.isWhitespace()) {
          tokenCount++;
        }
      }
      AnalyzedTokenReadings lastNonSpaceToken = getLastNonSpaceToken(tokens);
      boolean isParaEnd = Tools.isParagraphEnd(sentences, sentPos, lang);
      if (isParaEnd && tokenCount > TOKEN_THRESHOLD &&
          lastNonSpaceToken != null && !lastNonSpaceToken.getToken().matches("[:.?!…]") && !lastNonSpaceToken.isNonWord()) {
        RuleMatch ruleMatch = new RuleMatch(this, sentence, pos + lastNonSpaceToken.getStartPos(), pos + lastNonSpaceToken.getEndPos(),
          messages.getString("punctuation_mark_paragraph_end_msg"));
        ruleMatch.setSuggestedReplacement(lastNonSpaceToken.getToken() + ".");
        ruleMatches.add(ruleMatch);
      }
      if (isParaEnd) {
        tokenCount = 0;
      }
      sentPos++;
      pos += sentence.getCorrectedTextLength();
    }
    return toRuleMatchArray(ruleMatches);
  }

  private AnalyzedTokenReadings getLastNonSpaceToken(AnalyzedTokenReadings[] tokens) {<FILL_FUNCTION_BODY>}

  @Override
  public int minToCheckParagraph() {
    return 0;
  }

}

    for (int i = tokens.length-1; i >= 0; i--) {
      if (!tokens[i].isWhitespace()) {
        return tokens[i];
      }
    }
    return null;
  
<methods>public void <init>() ,public void <init>(java.util.ResourceBundle) ,public int estimateContextForSureMatch() ,public org.languagetool.rules.RuleMatch[] match(List<org.languagetool.AnalyzedSentence>, org.languagetool.markup.AnnotatedText) throws java.io.IOException,public abstract org.languagetool.rules.RuleMatch[] match(List<org.languagetool.AnalyzedSentence>) throws java.io.IOException,public final org.languagetool.rules.RuleMatch[] match(org.languagetool.AnalyzedSentence) throws java.io.IOException,public abstract int minToCheckParagraph() <variables>