package com.sjyt.icom.asst.context.handle;

/**
 * <p>TODO</p>
 *
 * @author renyanru
 * @version V1.0.0
 * @date 2022/6/22 12:53
 */
public abstract class NoBackArgsBaseHandle<T> implements NoBackArgsChain<T> {
    protected NoBackArgsBaseHandle<T> handle;

    /**
     * 下一个handle
     * @param handle handle
     */
    public void next(NoBackArgsBaseHandle<T> handle) {
        this.handle = handle;
    }

    /**
     * 构造维护上下handle
     * @param <T>
     */
    public static class Builder<T> {
        private NoBackArgsBaseHandle<T> head;
        private NoBackArgsBaseHandle<T> tail;
        public NoBackArgsBaseHandle.Builder<T> addHandler(NoBackArgsBaseHandle<T> handler) {
            if (this.head == null) {
                this.head = this.tail = handler;
            }
            this.tail.next(handler);
            this.tail = handler;
            return this;
        }

        public NoBackArgsBaseHandle<T> build() {
            return this.head;
        }
    }
}
