class FootnoteRepository extends NodeRepository<FootnoteBlock> {
    private ArrayList<FootnoteBlock> referencedFootnoteBlocks = new ArrayList<>();

    public static void resolveFootnotes(Document document) {<FILL_FUNCTION_BODY>}

    public void addFootnoteReference(FootnoteBlock footnoteBlock, Footnote footnote) {
        if (!footnoteBlock.isReferenced()) {
            referencedFootnoteBlocks.add(footnoteBlock);
        }

        footnoteBlock.setFirstReferenceOffset(footnote.getStartOffset());

        int referenceOrdinal = footnoteBlock.getFootnoteReferences();
        footnoteBlock.setFootnoteReferences(referenceOrdinal + 1);
        footnote.setReferenceOrdinal(referenceOrdinal);
    }

    public void resolveFootnoteOrdinals() {
        // need to sort by first referenced offset then set each to its ordinal position in the array+1
        Collections.sort(referencedFootnoteBlocks, (f1, f2) -> f1.getFirstReferenceOffset() - f2.getFirstReferenceOffset());

        int ordinal = 0;
        for (FootnoteBlock footnoteBlock : referencedFootnoteBlocks) {
            footnoteBlock.setFootnoteOrdinal(++ordinal);
        }
    }

    public List<FootnoteBlock> getReferencedFootnoteBlocks() {
        return referencedFootnoteBlocks;
    }

    public FootnoteRepository(DataHolder options) {
        super(FootnoteExtension.FOOTNOTES_KEEP.get(options));
    }

    @NotNull
    @Override
    public DataKey<FootnoteRepository> getDataKey() {
        return FootnoteExtension.FOOTNOTES;
    }

    @NotNull
    @Override
    public DataKey<KeepType> getKeepDataKey() {
        return FootnoteExtension.FOOTNOTES_KEEP;
    }

    @NotNull
    @Override
    public Set<FootnoteBlock> getReferencedElements(Node parent) {
        HashSet<FootnoteBlock> references = new HashSet<>();
        visitNodes(parent, value -> {
            if (value instanceof Footnote) {
                FootnoteBlock reference = ((Footnote) value).getReferenceNode(FootnoteRepository.this);
                if (reference != null) {
                    references.add(reference);
                }
            }
        }, Footnote.class);
        return references;
    }
}

        FootnoteRepository footnoteRepository = FootnoteExtension.FOOTNOTES.get(document);
        
        boolean[] hadNewFootnotes = { false };
        NodeVisitor visitor = new NodeVisitor(
                new VisitHandler<>(Footnote.class, node -> {
                    if (!node.isDefined()) {
                        FootnoteBlock footonoteBlock = node.getFootnoteBlock(footnoteRepository);

                        if (footonoteBlock != null) {
                            footnoteRepository.addFootnoteReference(footonoteBlock, node);
                            node.setFootnoteBlock(footonoteBlock);
                            hadNewFootnotes[0] = true;
                        }
                    }
                })
        );

        visitor.visit(document);
        if (hadNewFootnotes[0]) {
            footnoteRepository.resolveFootnoteOrdinals();
        }
    
<methods>public void <init>(@Nullable KeepType) ,public void clear() ,public boolean containsKey(@NotNull Object) ,public boolean containsValue(java.lang.Object) ,public @NotNull Set<Map.Entry<String,FootnoteBlock>> entrySet() ,public boolean equals(java.lang.Object) ,public @Nullable FootnoteBlock get(@NotNull Object) ,public abstract @NotNull DataKey<? extends NodeRepository<FootnoteBlock>> getDataKey() ,public @Nullable FootnoteBlock getFromRaw(@NotNull CharSequence) ,public abstract @NotNull DataKey<KeepType> getKeepDataKey() ,public abstract @NotNull Set<FootnoteBlock> getReferencedElements(com.vladsch.flexmark.util.ast.Node) ,public @NotNull Collection<FootnoteBlock> getValues() ,public int hashCode() ,public boolean isEmpty() ,public @NotNull Set<String> keySet() ,public @NotNull String normalizeKey(@NotNull CharSequence) ,public @Nullable FootnoteBlock put(@NotNull String, @NotNull FootnoteBlock) ,public void putAll(@NotNull Map<? extends String,? extends FootnoteBlock>) ,public @Nullable FootnoteBlock putRawKey(@NotNull CharSequence, @NotNull FootnoteBlock) ,public @Nullable FootnoteBlock remove(@NotNull Object) ,public int size() ,public static boolean transferReferences(@NotNull NodeRepository<T>, @NotNull NodeRepository<T>, boolean, @Nullable Map<String,String>) ,public @NotNull List<FootnoteBlock> values() <variables>protected final non-sealed com.vladsch.flexmark.util.ast.KeepType keepType,protected final ArrayList<com.vladsch.flexmark.ext.footnotes.FootnoteBlock> nodeList,protected final Map<java.lang.String,com.vladsch.flexmark.ext.footnotes.FootnoteBlock> nodeMap