Interceptors.java 文件源码

java
阅读 25 收藏 0 点赞 0 评论 0

项目:timey 作者:
/**
 * Creates an interceptor that chains other interceptors.
 * 
 * @param interceptors
 *            instances of {@link MethodInterceptor}.
 * @return interceptor that enclose other interceptors or Interceptors.EMPTY instance if interceptors argument is
 *         null or empty
 */
public static MethodInterceptor create(final MethodInterceptor... interceptors) {

    if (ArrayUtils.isEmpty(interceptors)) {
        return Interceptors.EMPTY;
    }

    final List<MethodInterceptor> flatlist = new ArrayList<>();
    for (final MethodInterceptor interceptor : interceptors) {
        assert (interceptor != null);

        if (interceptor instanceof Interceptors) {
            flatlist.addAll(Arrays.asList(((Interceptors) interceptor).interceptors));
        } else if (EMPTY != interceptor) {
            flatlist.add(interceptor);
        }
    }
    if (flatlist.isEmpty()) {
        return EMPTY;
    } else if (flatlist.size() == 1) {
        return flatlist.get(0);
    }
    return new Interceptors(flatlist.toArray(new MethodInterceptor[flatlist.size()]));
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号