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

org.pkl.thirdparty.commonmark.node.Nodes Maven / Gradle / Ivy

Go to download

Fat Jar containing pkl-cli, pkl-codegen-java, pkl-codegen-kotlin, pkl-config-java, pkl-core, pkl-doc, and their shaded third-party dependencies.

There is a newer version: 0.27.1
Show newest version
package org.pkl.thirdparty.commonmark.node;

import java.util.Iterator;

/**
 * Utility class for working with multiple {@link Node}s.
 *
 * @since 0.16.0
 */
public class Nodes {

    private Nodes() {
    }

    /**
     * The nodes between (not including) start and end.
     */
    public static Iterable between(Node start, Node end) {
        return new NodeIterable(start.getNext(), end);
    }

    private static class NodeIterable implements Iterable {

        private final Node first;
        private final Node end;

        private NodeIterable(Node first, Node end) {
            this.first = first;
            this.end = end;
        }

        @Override
        public Iterator iterator() {
            return new NodeIterator(first, end);
        }
    }

    private static class NodeIterator implements Iterator {

        private Node node;
        private final Node end;

        private NodeIterator(Node first, Node end) {
            node = first;
            this.end = end;
        }

        @Override
        public boolean hasNext() {
            return node != null && node != end;
        }

        @Override
        public Node next() {
            Node result = node;
            node = node.getNext();
            return result;
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException("remove");
        }
    }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy