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

shz.core.node.SNode Maven / Gradle / Ivy

package shz.core.node;

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

/**
 * 单向链表节点
 */
@SuppressWarnings("unchecked")
public interface SNode> {
    T next();

    void next(T node);

    default T addNext(T node) {
        node.next(next());
        next(node);
        return node;
    }

    T addPrev(T node);

    void poll();

    default T find(Predicate predicate) {
        if (predicate == null) return null;
        for (T next = (T) this; next != null; next = next.next()) if (predicate.test(next)) return next;
        return null;
    }

    default void forEach(Function func) {
        if (func == null) return;
        for (T next = (T) this; next != null; next = next.next()) {
            Boolean stop = func.apply(next);
            if (stop != null && stop) break;
        }
    }

    default void forEach(Consumer consumer) {
        if (consumer == null) return;
        for (T next = (T) this; next != null; next = next.next()) consumer.accept(next);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy