class V2TextChecker extends TextChecker {

  private static final String JSON_CONTENT_TYPE = "application/json";
  private static final Pattern COMMA_WHITESPACE_PATTERN = Pattern.compile(",\\s*");

  private static Map<ConfidenceKey,Float> confidenceMap;

  V2TextChecker(HTTPServerConfig config, boolean internalServer, Queue<Runnable> workQueue, RequestCounter reqCounter) {
    super(config, internalServer, workQueue, reqCounter);
    try {
      if (config.getRuleIdToConfidenceFile() != null) {
        confidenceMap = new ConfidenceMapLoader().load(config.getRuleIdToConfidenceFile());
      }
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }

  @Override
  protected void setHeaders(HttpExchange httpExchange) {
    setCommonHeaders(httpExchange, JSON_CONTENT_TYPE, config.allowOriginUrl);
  }

  @Override
  protected String getResponse(AnnotatedText text, Language usedLang, DetectedLanguage lang, Language motherTongue, List<CheckResults> matches,
                               List<RuleMatch> hiddenMatches, String incompleteResultsReason, int compactMode, boolean showPremiumHint, JLanguageTool.Mode mode) {
    RuleMatchesAsJsonSerializer serializer = new RuleMatchesAsJsonSerializer(compactMode, usedLang);
    serializer.setRuleIdToConfidenceMap(confidenceMap);
    return serializer.ruleMatchesToJson2(matches, hiddenMatches, text, CONTEXT_SIZE, lang, incompleteResultsReason,
      showPremiumHint, mode);
  }

  @NotNull
  @Override
  protected List<String> getEnabledRuleIds(Map<String, String> parameters) {
    String enabledParam = parameters.get("enabledRules");
    List<String> enabledRules = new ArrayList<>();
    if (enabledParam != null) {
      enabledRules.addAll(Arrays.asList(enabledParam.split(",")));
    }
    return enabledRules;
  }

  @NotNull
  @Override
  protected List<String> getDisabledRuleIds(Map<String, String> parameters) {
    return getCommaSeparatedStrings("disabledRules", parameters);
  }

  @Override
  protected boolean getLanguageAutoDetect(Map<String, String> parameters) {
    return "auto".equals(parameters.get("language"));
  }

  @Override
  protected void checkParams(Map<String, String> parameters) {
    super.checkParams(parameters);
    if (StringTools.isEmpty(parameters.get("language"))) {
      throw new BadRequestException("Missing 'language' parameter, e.g. 'language=en-US' for American English or 'language=fr' for French");
    }
    if (parameters.get("enabled") != null) {
      throw new BadRequestException("You specified 'enabled' but the parameter is now called 'enabledRules' in v2 of the API");
    }
    if (parameters.get("disabled") != null) {
      throw new BadRequestException("You specified 'disabled' but the parameter is now called 'disabledRules' in v2 of the API");
    }
    if (parameters.get("preferredvariants") != null) {
      throw new BadRequestException("You specified 'preferredvariants' but the parameter is now called 'preferredVariants' (uppercase 'V') in v2 of the API");
    }
    if (parameters.get("autodetect") != null) {
      throw new BadRequestException("You specified 'autodetect' but automatic language detection is now activated with 'language=auto' in v2 of the API");
    }
  }
  
  @Override
  @NotNull
  protected DetectedLanguage getLanguage(String text, Map<String, String> parameters, List<String> preferredVariants,
                                         List<String> noopLangs, List<String> preferredLangs, boolean testMode) {
    String langParam = parameters.get("language");
    boolean forcePreferredLanguages = "true".equals(parameters.get("forcePreferredLanguages"));
    DetectedLanguage detectedLang = detectLanguageOfString(text, null, preferredVariants, noopLangs, preferredLangs, forcePreferredLanguages);
    Language givenLang;
    if (getLanguageAutoDetect(parameters)) {
      givenLang = detectedLang.getDetectedLanguage();
    } else {
      givenLang = parseLanguage(langParam);
    }
    return new DetectedLanguage(givenLang, detectedLang.getDetectedLanguage(), detectedLang.getDetectionConfidence(),
      detectedLang.getDetectionSource());
  }

  @Override
  @NotNull
  protected List<String> getPreferredVariants(Map<String, String> parameters) {<FILL_FUNCTION_BODY>}

}

    List<String> preferredVariants;
    if (parameters.get("preferredVariants") != null) {
      preferredVariants = Arrays.asList(COMMA_WHITESPACE_PATTERN.split(parameters.get("preferredVariants")));
      if (!"auto".equals(parameters.get("language")) && (parameters.get("multilingual") == null || parameters.get("multilingual").equals("false"))) {
        throw new BadRequestException("You specified 'preferredVariants' but you didn't specify 'language=auto'");
      }
    } else {
      preferredVariants = Collections.emptyList();
    }
    return preferredVariants;
  
<methods>public boolean checkerQueueAlmostFull() <variables>private static final org.languagetool.server.tools.AbTestService AB_TEST_SERVICE,private static final int CACHE_STATS_PRINT,private static final java.util.regex.Pattern COMMA_WHITESPACE_PATTERN,protected static final int CONTEXT_SIZE,private static final java.lang.String ENCODING,protected static final int NUM_PIPELINES_PER_SETTING,private static final int PINGS_CLEAN_MILLIS,private static final int PINGS_MAX_SIZE,private static final java.lang.String SPAN_NAME_PREFIX,private final non-sealed org.languagetool.ResultCache cache,protected final non-sealed org.languagetool.server.HTTPServerConfig config,private final non-sealed org.languagetool.server.DatabaseLogger databaseLogger,private final non-sealed java.util.concurrent.ExecutorService executorService,private final Map<java.lang.String,java.lang.Integer> languageCheckCounts,private final non-sealed org.languagetool.language.identifier.LanguageIdentifier languageIdentifier,private final non-sealed java.lang.Long logServerId,private final Set<org.languagetool.server.DatabasePingLogEntry> pings,private long pingsCleanDateMillis,org.languagetool.server.PipelinePool pipelinePool,private final java.util.Random random,private final non-sealed org.languagetool.server.RequestCounter reqCounter,private final non-sealed Queue<java.lang.Runnable> workQueue