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

shz.model.Chain Maven / Gradle / Ivy

package shz.model;

import shz.linked.LDNode;

public class Chain {
    private final LDNode> node;

    protected Chain() {
        node = LDNode.of(this);
    }

    public static  Chain of() {
        return new Chain<>();
    }

    public final Chain append(Chain next) {
        node.addNext(next.node);
        return next;
    }

    public final Chain head() {
        if (node.prev() == null) return this;
        return node.prev().val.head();
    }

    public final Chain tail() {
        if (node.next() == null) return this;
        return node.next().val.tail();
    }

    public T execute(T t) {
        return t;
    }

    public final T doFilter(T t) {
        Chain head = head();
        T execute = head.execute(t);
        while (head.node.next() != null && (head = head.node.next().val) != null) execute = head.execute(execute);
        return execute;
    }

    public final void doDuty(T t) {
        Chain head = head();
        T execute = head.execute(t);
        if (execute == null) return;
        while (head.node.next() != null && (head = head.node.next().val) != null) {
            execute = head.execute(execute);
            if (execute == null) return;
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy