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

shz.core.structure.Chain Maven / Gradle / Ivy

There is a newer version: 2024.0.2
Show newest version
package shz.core.structure;

import shz.core.node.LDNode;

import java.io.Serializable;

public class Chain implements Serializable {
    private static final long serialVersionUID = -2319683066926999009L;
    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 - 2024 Weber Informatics LLC | Privacy Policy