com.vladsch.flexmark.tree.iteration.FixedIterationConditions Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of flexmark-tree-iteration Show documentation
Show all versions of flexmark-tree-iteration Show documentation
flexmark-java library for recursive tree iteration with the filtering and recursion conditions provided by predicates
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 super N, N> initializer;
final private @NotNull Function super N, N> iterator;
final private @NotNull Function super N, N> reverseInitializer;
final private @NotNull Function super N, N> reverseIterator;
public FixedIterationConditions(@NotNull Function super N, N> initializer, @NotNull Function super N, N> iterator, @NotNull Function super N, N> reverseInitializer, @NotNull Function super N, N> reverseIterator) {
this.initializer = initializer;
this.iterator = iterator;
this.reverseInitializer = reverseInitializer;
this.reverseIterator = reverseIterator;
}
@Override
@NotNull
public Function super N, N> getInitializer() {
return initializer;
}
@Override
@NotNull
public Function super N, N> getIterator() {
return iterator;
}
@NotNull
@Override
public IterationConditions getReversed() {
return new FixedIterationConditions<>(reverseInitializer, reverseIterator, initializer, iterator);
}
public static Function super B, B> getAdapter(Function super T, T> function, Function super B, T> adaptBtoT, Function super T, B> adaptTtoB) {
return adaptBtoT.andThen(function).andThen(adaptTtoB);
}
public static FixedIterationConditions mapTtoB(IterationConditions constraints, Function super B, T> adaptBtoT, Function super T, B> 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