package com.scarabsoft.jrest;

import java.util.List;

final class RequestInterceptorChainBuilder {

    private RequestInterceptorChainBuilder() {
        throw new RuntimeException("use static methods");
    }

    static RequestInterceptorChainImpl create(RequestInterceptorChainImpl exisitingChain, List<Interceptor> interceptors) throws InstantiationException, IllegalAccessException {
        final RequestInterceptorChainImpl result = exisitingChain.deepClone();
        if (interceptors != null) {
            for (final Interceptor interceptor : interceptors) {
                result.addInterceptor(interceptor.value().newInstance().get());
            }
        }
        return result;
    }

}
