class AnnotatedTextBuilder {

  private final static String hiddenChars = "\u00AD\u202D\u202c";

  private final List<TextPart> parts = new ArrayList<>();
  private final Map<AnnotatedText.MetaDataKey, String> metaData = new HashMap<>();
  private final Map<String, String> customMetaData = new HashMap<>();

  public AnnotatedTextBuilder() {
  }

  /**
   * Add global meta data like document title or receiver name (when writing an email).
   * Some rules may use this information.
   * @since 3.9
   */
  public AnnotatedTextBuilder addGlobalMetaData(AnnotatedText.MetaDataKey key, String value) {
    metaData.put(key, value);
    return this;
  }

  /**
   * Add any global meta data about the document to be checked. Some rules may use this information.
   * Unless you're using your own rules for which you know useful keys, you probably want to
   * use {@link #addGlobalMetaData(AnnotatedText.MetaDataKey, String)}.
   * @since 3.9
   */
  public AnnotatedTextBuilder addGlobalMetaData(String key, String value) {
    customMetaData.put(key, value);
    return this;
  }

  /**
   * Add a plain text snippet, to be checked by LanguageTool when using
   * {@link org.languagetool.JLanguageTool#check(AnnotatedText)}.
   */
  public AnnotatedTextBuilder addText(String text) {<FILL_FUNCTION_BODY>}

  /**
   * Add a markup text snippet like {@code <b attr='something'>} or {@code <div>}. These
   * parts will be ignored by LanguageTool when using {@link org.languagetool.JLanguageTool#check(AnnotatedText)}.
   */
  public AnnotatedTextBuilder addMarkup(String markup) {
    parts.add(new TextPart(markup, TextPart.Type.MARKUP));
    return this;
  }

  /**
   * Add a markup text snippet like {@code <b attr='something'>} or {@code <div>}. These
   * parts will be ignored by LanguageTool when using {@link org.languagetool.JLanguageTool#check(AnnotatedText)}.
   * @param interpretAs A string that will be used by the checker instead of the markup. This is usually
   *                    whitespace, e.g. {@code \n\n} for {@code <p>}
   */
  public AnnotatedTextBuilder addMarkup(String markup, String interpretAs) {
    parts.add(new TextPart(markup, TextPart.Type.MARKUP));
    parts.add(new TextPart(interpretAs, TextPart.Type.FAKE_CONTENT));
    return this;
  }

  /** @since 5.4 */
  public void add(TextPart part) {
    parts.add(part);
  }

  /**
   * Create the annotated text to be passed into {@link org.languagetool.JLanguageTool#check(AnnotatedText)}.
   */
  public AnnotatedText build() {
    int plainTextPosition = 0;
    int totalPosition = 0;
    Map<Integer, MappingValue> mapping = new HashMap<>();
    for (int i = 0; i < parts.size(); i++) {
      TextPart part = parts.get(i);
      if (part.getType() == TextPart.Type.TEXT) {
        plainTextPosition += part.getPart().length();
        totalPosition += part.getPart().length();
        MappingValue mappingValue = new MappingValue(totalPosition);
        mapping.put(plainTextPosition, mappingValue);
      } else if (part.getType() == TextPart.Type.MARKUP) {
        totalPosition += part.getPart().length();
        if (hasFakeContent(i, parts)) {
          plainTextPosition += parts.get(i + 1).getPart().length();
          i++;
          if (mapping.get(plainTextPosition) == null) {
            MappingValue mappingValue = new MappingValue(totalPosition, part.getPart().length());
            mapping.put(plainTextPosition, mappingValue);
          }
        }
      }
    }
    return new AnnotatedText(parts, mapping, metaData, customMetaData);
  }

  private boolean hasFakeContent(int i, List<TextPart> parts) {
    int nextPartIndex = i + 1;
    if (nextPartIndex < parts.size()) {
      if (parts.get(nextPartIndex).getType().equals(TextPart.Type.FAKE_CONTENT)) {
        return true;
      }
    }
    return false;
  }

}

    StringTokenizer st = new StringTokenizer(text, hiddenChars, true);
    while (st.hasMoreElements()) {
      String token = (String) st.nextElement();
      if (!hiddenChars.contains(token)) {
        parts.add(new TextPart(token, TextPart.Type.TEXT));
      } else {
        parts.add(new TextPart(token, TextPart.Type.MARKUP));
      }
    }
    return this;
  
<no_super_class>