@FunctionalInterfacepublic interface Filter{ T doFilter(T t);}
public class FilterChainimplements Filter { public List > filterChain = new ArrayList >(); public FilterChain addFilter(Filter filter){ filterChain.add(filter); return this; } @Override public T doFilter(T t) { T result = t; for(Filter filter : filterChain){ result = filter.doFilter(t); } return result; }}
public abstract class AbstractProcessor{ protected FilterChain filterChain; protected T object; public AbstractProcessor(FilterChain filterChain, T object){ this.filterChain = filterChain; this.object = object; } public abstract T process(); }
使用方式:
新建自己的filter继承Filter
把filter放入新建的filterChain中新建自己的processor继承AbstractProcessor
通过构造方法加入filterChain 和需要处理的数据