com.vladsch.flexmark.tree.iteration.MappedIterator 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;
import java.util.function.Predicate;
public class MappedIterator {
protected final @NotNull B myElement;
protected final @NotNull ValueIterationAdapter super B, T> myAdapter;
protected final @NotNull TreeIterator myTreeIterator;
public MappedIterator(@NotNull B element, @NotNull ValueIterationAdapter super B, T> adapter, @NotNull TreeIterator treeIterator) {
myElement = element;
myAdapter = adapter;
myTreeIterator = treeIterator;
}
// *******************************************************
//
// Looping delegated
//
// *******************************************************
@NotNull
final public TreeIterator getTreeIterator() {
return myTreeIterator;
}
@NotNull
final public R doLoop(@NotNull R defaultValue, @NotNull ValueIterationConsumer super T, R> consumer) {
return myTreeIterator.doLoop(myElement, defaultValue, myAdapter, consumer);
}
final public void doLoop(@NotNull VoidIterationConsumer super T> consumer) {
myTreeIterator.doLoop(myElement, myAdapter, consumer);
}
// *******************************************************
//
// Need Subclass Constructors
//
// *******************************************************
@NotNull
public MappedIterator getModifiedCopy(B element, ValueIterationAdapter super B, T> adapter, TreeIterator treeIterator) {
return new MappedIterator<>(element, adapter, treeIterator);
}
@NotNull
public MappedIterator getModifiedCopyF(B element, ValueIterationAdapter super B, F> adapter, TreeIterator treeIterator) {
return new MappedIterator<>(element, adapter, treeIterator);
}
// *******************************************************
//
// Need Overrides with cast to sub-class
//
// *******************************************************
@NotNull
public MappedIterator reversed() {
return getModifiedCopy(myElement, myAdapter, myTreeIterator.reversed());
}
@NotNull
public MappedIterator recursive() {
return getModifiedCopy(myElement, myAdapter, myTreeIterator.recursive());
}
@NotNull
public MappedIterator nonRecursive() {
return getModifiedCopy(myElement, myAdapter, myTreeIterator.nonRecursive());
}
@NotNull
public MappedIterator recursive(boolean recursive) {
return recursive ? recursive() : nonRecursive();
}
@NotNull
public MappedIterator nonRecursive(boolean nonRecursive) {
return nonRecursive ? nonRecursive() : recursive();
}
@NotNull
public MappedIterator recurse(@NotNull Predicate super B> predicate) {
return getModifiedCopy(myElement, myAdapter, myTreeIterator.recurse(predicate));
}
@NotNull
public MappedIterator recurse(@NotNull Class super B> clazz) {
return getModifiedCopy(myElement, myAdapter, myTreeIterator.recurse(clazz));
}
@NotNull
public MappedIterator recurse(@NotNull Class clazz, @NotNull Predicate super F> predicate) {
return getModifiedCopy(myElement, myAdapter, myTreeIterator.recurse(clazz, predicate));
}
@NotNull
public MappedIterator noRecurse(@NotNull Predicate super B> predicate) {
return getModifiedCopy(myElement, myAdapter, myTreeIterator.noRecurse(predicate));
}
@NotNull
public MappedIterator noRecurse(@NotNull Class super B> clazz) {
return getModifiedCopy(myElement, myAdapter, myTreeIterator.noRecurse(clazz));
}
@NotNull
public MappedIterator noRecurse(@NotNull Class clazz, @NotNull Predicate super F> predicate) {
return getModifiedCopy(myElement, myAdapter, myTreeIterator.recurse(clazz, predicate));
}
@NotNull
public MappedIterator filterFalse() {
return aborted();
}
@NotNull
public MappedIterator aborted() {
return getModifiedCopy(myElement, myAdapter, myTreeIterator.aborted());
}
@NotNull
public MappedIterator filterOut(@NotNull Predicate super B> predicate) {
return getModifiedCopy(myElement, myAdapter, myTreeIterator.filterOut(predicate));
}
@NotNull
public MappedIterator filterOut(@NotNull Class super B> clazz) {
return getModifiedCopy(myElement, myAdapter, myTreeIterator.filterOut(clazz));
}
@NotNull
public MappedIterator filterOut(@NotNull Class clazz, @NotNull Predicate super F> predicate) {
return getModifiedCopy(myElement, myAdapter, myTreeIterator.filterOut(clazz, predicate));
}
@NotNull
public MappedIterator filter(@NotNull Predicate super B> predicate) {
return getModifiedCopy(myElement, myAdapter, myTreeIterator.filter(predicate));
}
@NotNull
public MappedIterator acceptFilter(@NotNull ValueIterationFilter super T> filter) {
return getModifiedCopy(myElement, myAdapter.andThen(ValueIterationAdapterImpl.of(filter)), myTreeIterator);
}
// *******************************************************
//
// Mapping Functions
//
// *******************************************************
@NotNull
public MappedIterator filter(@NotNull Class clazz) {
return getModifiedCopyF(myElement, myAdapter.andThen(ValueIterationAdapterImpl.of(clazz)), myTreeIterator);
}
@NotNull
public MappedIterator filter(@NotNull Class clazz, @NotNull Predicate super F> predicate) {
return getModifiedCopyF(myElement, myAdapter.andThen(ValueIterationAdapterImpl.of(clazz, predicate)), myTreeIterator);
}
@NotNull
public MappedIterator adapt(@NotNull Function super T, F> adapter) {
return getModifiedCopyF(myElement, myAdapter.andThen(ValueIterationAdapterImpl.of(adapter)), myTreeIterator);
}
@NotNull
public MappedIterator adapt(@NotNull ValueIterationAdapter super T, F> adapter) {
return getModifiedCopyF(myElement, myAdapter.andThen(adapter), myTreeIterator);
}
@NotNull
public MappedIterator
© 2015 - 2024 Weber Informatics LLC | Privacy Policy