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

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

package com.vladsch.flexmark.tree.iteration;

import com.vladsch.flexmark.util.ast.Node;
import org.jetbrains.annotations.NotNull;

import java.util.Set;
import java.util.function.Function;
import java.util.function.Predicate;

public class NodeIterator extends MappedIterator {
    public NodeIterator(@NotNull Node element, @NotNull ValueIterationAdapter adapter, @NotNull TreeIterator treeIterator) {
        super(element, adapter, treeIterator);
    }

    // *******************************************************
    //
    // Need Subclass Constructors
    //
    // *******************************************************

    @NotNull
    public NodeIterator getModifiedCopy(Node element, ValueIterationAdapter adapter, TreeIterator treeIterator) {
        return new NodeIterator<>(element, adapter, treeIterator);
    }

    @NotNull
    public  NodeIterator getModifiedCopyF(Node element, ValueIterationAdapter adapter, TreeIterator treeIterator) {
        return new NodeIterator<>(element, adapter, treeIterator);
    }

    // *******************************************************
    //
    // Need Overrides with cast to sub-class
    //
    // *******************************************************

    @NotNull
    @Override
    public NodeIterator reversed() {
        return (NodeIterator) super.reversed();
    }

    @NotNull
    @Override
    public NodeIterator recursive() {
        return (NodeIterator) super.recursive();
    }

    @NotNull
    @Override
    public NodeIterator nonRecursive() {
        return (NodeIterator) super.nonRecursive();
    }

    @NotNull
    @Override
    public NodeIterator recursive(boolean recursive) {
        return (NodeIterator) super.recursive(recursive);
    }

    @NotNull
    @Override
    public NodeIterator nonRecursive(boolean nonRecursive) {
        return (NodeIterator) super.nonRecursive(nonRecursive);
    }

    @NotNull
    @Override
    public NodeIterator recurse(@NotNull Predicate predicate) {
        return (NodeIterator) super.recurse(predicate);
    }

    @NotNull
    @Override
    public NodeIterator recurse(@NotNull Class clazz) {
        return (NodeIterator) super.recurse(clazz);
    }

    @NotNull
    @Override
    public  NodeIterator recurse(@NotNull Class clazz, @NotNull Predicate predicate) {
        return (NodeIterator) super.recurse(clazz, predicate);
    }

    @NotNull
    @Override
    public NodeIterator noRecurse(@NotNull Predicate predicate) {
        return (NodeIterator) super.noRecurse(predicate);
    }

    @NotNull
    @Override
    public NodeIterator noRecurse(@NotNull Class clazz) {
        return (NodeIterator) super.noRecurse(clazz);
    }

    @NotNull
    @Override
    public  NodeIterator noRecurse(@NotNull Class clazz, @NotNull Predicate predicate) {
        return (NodeIterator) super.noRecurse(clazz, predicate);
    }

    @NotNull
    @Override
    public NodeIterator filterFalse() {
        return (NodeIterator) super.filterFalse();
    }

    @NotNull
    @Override
    public NodeIterator aborted() {
        return (NodeIterator) super.aborted();
    }

    @NotNull
    @Override
    public NodeIterator filterOut(@NotNull Predicate predicate) {
        return (NodeIterator) super.filterOut(predicate);
    }

    @NotNull
    @Override
    public NodeIterator filterOut(@NotNull Class clazz) {
        return (NodeIterator) super.filterOut(clazz);
    }

    @NotNull
    @Override
    public  NodeIterator filterOut(@NotNull Class clazz, @NotNull Predicate predicate) {
        return (NodeIterator) super.filterOut(clazz, predicate);
    }

    @NotNull
    @Override
    public NodeIterator filter(@NotNull Predicate predicate) {
        return (NodeIterator) super.filter(predicate);
    }

    @NotNull
    @Override
    public NodeIterator acceptFilter(@NotNull ValueIterationFilter filter) {
        return (NodeIterator) super.acceptFilter(filter);
    }

    // *******************************************************
    //
    // Mapping Functions
    //
    // *******************************************************

    @NotNull
    @Override
    public  NodeIterator filter(@NotNull Class clazz) {
        return (NodeIterator) super.filter(clazz);
    }

    @NotNull
    @Override
    public  NodeIterator filter(@NotNull Class clazz, @NotNull Predicate predicate) {
        return (NodeIterator) super.filter(clazz, predicate);
    }

    @NotNull
    @Override
    public  NodeIterator adapt(@NotNull Function adapter) {
        return (NodeIterator) super.adapt(adapter);
    }

    @NotNull
    @Override
    public  NodeIterator adapt(@NotNull ValueIterationAdapter adapter) {
        return (NodeIterator) super.adapt(adapter);
    }

    // *******************************************************
    //
    // Node Looping specific
    //
    // *******************************************************

    @NotNull
    public NodeIterator recurse(@NotNull Set> nodeClassSet) {
        return getModifiedCopyF(myElement, myAdapter, myTreeIterator.recurse(it -> nodeClassSet.contains(it.getClass())));
    }

    @NotNull
    public NodeIterator filterOut(@NotNull Set> nodeClassSet) {
        return getModifiedCopyF(myElement, myAdapter, myTreeIterator.filterOut(it -> nodeClassSet.contains(it.getClass())));
    }

    @NotNull
    public NodeIterator filter(@NotNull Set> nodeClassSet) {
        return getModifiedCopyF(myElement, myAdapter, myTreeIterator.filter(it -> nodeClassSet.contains(it.getClass())));
    }

    @NotNull
    public MappedIterator toNodeObjectMapped() {
        return toObjectMapped(Node.class);
    }

    // *******************************************************
    //
    // Static Factories
    //
    // *******************************************************

    public static NodeIterator of(@NotNull Node element, @NotNull TreeIterator treeIterator) {
        return new NodeIterator<>(element, ValueIterationAdapterImpl.of(), treeIterator);
    }

    public static NodeIterator of(@NotNull Node element, @NotNull IterationConditions constraints) {
        return of(element, new TreeIterator<>(constraints));
    }

    public static NodeIterator of(@NotNull Node element, @NotNull IterationConditions constraints, @NotNull Predicate filter) {
        return of(element, new TreeIterator<>(constraints, filter));
    }

    public static NodeIterator of(@NotNull Node element, @NotNull IterationConditions constraints, @NotNull Predicate filter, @NotNull Predicate recursion) {
        return of(element, new TreeIterator<>(constraints, filter, recursion));
    }
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy