All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.vladsch.flexmark.tree.iteration.FixedIterationConditions Maven / Gradle / Ivy

Go to download

flexmark-java library for recursive tree iteration with the filtering and recursion conditions provided by predicates

There is a newer version: 0.64.8
Show newest version
package com.vladsch.flexmark.tree.iteration;

import org.jetbrains.annotations.NotNull;

import java.util.function.Function;

public class FixedIterationConditions implements IterationConditions {
    final private @NotNull Function initializer;
    final private @NotNull Function iterator;
    final private @NotNull Function reverseInitializer;
    final private @NotNull Function reverseIterator;

    public FixedIterationConditions(@NotNull Function initializer, @NotNull Function iterator, @NotNull Function reverseInitializer, @NotNull Function reverseIterator) {
        this.initializer = initializer;
        this.iterator = iterator;
        this.reverseInitializer = reverseInitializer;
        this.reverseIterator = reverseIterator;
    }

    @Override
    @NotNull
    public Function getInitializer() {
        return initializer;
    }

    @Override
    @NotNull
    public Function getIterator() {
        return iterator;
    }

    @NotNull
    @Override
    public IterationConditions getReversed() {
        return new FixedIterationConditions<>(reverseInitializer, reverseIterator, initializer, iterator);
    }

    public static  Function getAdapter(Function function, Function adaptBtoT, Function adaptTtoB) {
        return adaptBtoT.andThen(function).andThen(adaptTtoB);
    }

    public static  FixedIterationConditions mapTtoB(IterationConditions constraints, Function adaptBtoT, Function adaptTtoB) {
        return new FixedIterationConditions<>(
                getAdapter(constraints.getInitializer(), adaptBtoT, adaptTtoB),
                getAdapter(constraints.getIterator(), adaptBtoT, adaptTtoB),
                getAdapter(constraints.getReversed().getInitializer(), adaptBtoT, adaptTtoB),
                getAdapter(constraints.getReversed().getIterator(), adaptBtoT, adaptTtoB)
        );
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy