1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| public abstract class Handler<T> {
protected Handler<T> next;
private void next(Handler<T> next) { this.next = next; }
public abstract void doHandler(T data);
public static class Builder<T> { private Handler<T> head; private Handler<T> tail;
public Builder<T> addHandler(Handler<T> handler) { if (this.head == null) { this.head = this.tail = handler; return this; } this.tail.next(handler); this.tail = handler; return this; }
public Handler<T> build() { return this.head; } } }
|