class SortedTextRules { 

  private static boolean debugMode = false;   //  should be false except for testing
  
  List<Integer> minToCheckParagraph;
  List<List<String>> textLevelRules;

  SortedTextRules (SwJLanguageTool lt, Configuration config, Set<String> disabledRulesUI, boolean checkImpressDocument) {
    minToCheckParagraph = new ArrayList<>(OfficeTools.NUMBER_TEXTLEVEL_CACHE);
    textLevelRules = new ArrayList<>(OfficeTools.NUMBER_TEXTLEVEL_CACHE);
    minToCheckParagraph.add(0,0);
    minToCheckParagraph.add(1,1);
    minToCheckParagraph.add(2,-1);
    minToCheckParagraph.add(3,-2);
    for (int i = 0; i < OfficeTools.NUMBER_TEXTLEVEL_CACHE; i++) {
      textLevelRules.add(i, new ArrayList<>());
      debugMode = OfficeTools.DEBUG_MODE_SR;
    }
    List<Rule> rules = checkImpressDocument ? lt.getAllActiveRules() : lt.getAllActiveOfficeRules();
    int numParasToCheck = config.getNumParasToCheck();
    for (Rule rule : rules) {
      if (rule instanceof TextLevelRule && !lt.getDisabledRules().contains(rule.getId()) 
          && !disabledRulesUI.contains(rule.getId())) {
        insertRule(((TextLevelRule) rule).minToCheckParagraph(), numParasToCheck, rule.getId());
      }
    }
    if (debugMode) {
      MessageHandler.printToLogFile("SortedTextRules: Number different minToCheckParagraph: " + minToCheckParagraph.size());
      for ( int i = 0; i < minToCheckParagraph.size(); i++) {
        MessageHandler.printToLogFile("SortedTextRules: minToCheckParagraph: " + minToCheckParagraph.get(i));
        for (int j = 0; j < textLevelRules.get(i).size(); j++) {
          MessageHandler.printToLogFile("RuleId: " + textLevelRules.get(i).get(j));
        }
      }
    }
  }

  /**
   * Insert a rule to list of text level rules
   */
  private void insertRule (int minPara, int numParasToCheck, String ruleId) {
    if (minPara == 0) {
        textLevelRules.get(0).add(ruleId);
    } else {
      if (numParasToCheck >= 0) {
        textLevelRules.get(1).add(ruleId);
        if (minPara < 0 && minToCheckParagraph.get(1) < numParasToCheck) {
          minToCheckParagraph.set(1, numParasToCheck);
        } else if (minPara <= numParasToCheck && minPara > minToCheckParagraph.get(1)) {
          minToCheckParagraph.set(1, minPara);
        }
      } else if (minPara > 0) {
        textLevelRules.get(1).add(ruleId);
        if (minPara > minToCheckParagraph.get(1)) {
          minToCheckParagraph.set(1, minPara);
        }
      } else if (minPara == -2 && numParasToCheck == -2) {
        textLevelRules.get(3).add(ruleId);
      } else {
        textLevelRules.get(2).add(ruleId);
      }
    }
  }

  /**
   * Get the minimum of paragraphs that should be checked
   */
  public List<Integer> getMinToCheckParas() {
    return minToCheckParagraph;
  }

  /**
   * Activate the text level rules for a specified cache 
   */
  public void activateTextRulesByIndex(int nCache, SwJLanguageTool lt) {<FILL_FUNCTION_BODY>}

  /**
   * Reactivate the text level rules which was deactivated for a specified cache 
   */
  public void reactivateTextRules(SwJLanguageTool lt) {
    for (List<String> textRules : textLevelRules) {
      for (String ruleId : textRules) {
        lt.enableRule(ruleId);
      }
    }
  }

}

    for (int i = 0; i < textLevelRules.size(); i++) {
      if (i == nCache) {
        for (String ruleId : textLevelRules.get(i)) {
          lt.enableRule(ruleId);
        }
      } else {
        for (String ruleId : textLevelRules.get(i)) {
          lt.disableRule(ruleId);
        }
      }
    }
  
<no_super_class>