// 
// Decompiled by Procyon v0.6.0
// 

package io.netty.channel;

import io.netty.util.concurrent.EventExecutor;
import java.util.List;
import java.util.Collection;
import java.util.Collections;
import java.util.ArrayList;
import io.netty.util.internal.EmptyArrays;
import io.netty.util.concurrent.EventExecutorChooserFactory;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.Executor;

public class MultiThreadIoEventLoopGroup extends MultithreadEventLoopGroup implements IoEventLoopGroup
{
    public MultiThreadIoEventLoopGroup(final IoHandlerFactory ioHandlerFactory) {
        this(0, ioHandlerFactory);
    }
    
    public MultiThreadIoEventLoopGroup(final int nThreads, final IoHandlerFactory ioHandlerFactory) {
        this(nThreads, (Executor)null, ioHandlerFactory);
    }
    
    public MultiThreadIoEventLoopGroup(final ThreadFactory threadFactory, final IoHandlerFactory ioHandlerFactory) {
        this(0, threadFactory, ioHandlerFactory);
    }
    
    public MultiThreadIoEventLoopGroup(final Executor executor, final IoHandlerFactory ioHandlerFactory) {
        super(0, executor, new Object[] { ioHandlerFactory });
    }
    
    public MultiThreadIoEventLoopGroup(final int nThreads, final Executor executor, final IoHandlerFactory ioHandlerFactory) {
        super(nThreads, executor, new Object[] { ioHandlerFactory });
    }
    
    public MultiThreadIoEventLoopGroup(final int nThreads, final ThreadFactory threadFactory, final IoHandlerFactory ioHandlerFactory) {
        super(nThreads, threadFactory, new Object[] { ioHandlerFactory });
    }
    
    public MultiThreadIoEventLoopGroup(final int nThreads, final Executor executor, final EventExecutorChooserFactory chooserFactory, final IoHandlerFactory ioHandlerFactory) {
        super(nThreads, executor, chooserFactory, new Object[] { ioHandlerFactory });
    }
    
    protected MultiThreadIoEventLoopGroup(final int nThreads, final Executor executor, final IoHandlerFactory ioHandlerFactory, final Object... args) {
        super(nThreads, executor, combine(ioHandlerFactory, args));
    }
    
    protected MultiThreadIoEventLoopGroup(final int nThreads, final ThreadFactory threadFactory, final IoHandlerFactory ioHandlerFactory, final Object... args) {
        super(nThreads, threadFactory, combine(ioHandlerFactory, args));
    }
    
    protected MultiThreadIoEventLoopGroup(final int nThreads, final ThreadFactory threadFactory, final IoHandlerFactory ioHandlerFactory, final EventExecutorChooserFactory chooserFactory, final Object... args) {
        super(nThreads, threadFactory, new Object[] { chooserFactory, combine(ioHandlerFactory, args) });
    }
    
    protected MultiThreadIoEventLoopGroup(final int nThreads, final Executor executor, final IoHandlerFactory ioHandlerFactory, final EventExecutorChooserFactory chooserFactory, final Object... args) {
        super(nThreads, executor, chooserFactory, combine(ioHandlerFactory, args));
    }
    
    @Override
    protected EventLoop newChild(final Executor executor, final Object... args) throws Exception {
        final IoHandlerFactory handlerFactory = (IoHandlerFactory)args[0];
        Object[] argsCopy;
        if (args.length > 1) {
            argsCopy = new Object[args.length - 1];
            System.arraycopy(args, 1, argsCopy, 0, argsCopy.length);
        }
        else {
            argsCopy = EmptyArrays.EMPTY_OBJECTS;
        }
        return this.newChild(executor, handlerFactory, argsCopy);
    }
    
    protected IoEventLoop newChild(final Executor executor, final IoHandlerFactory ioHandlerFactory, final Object... args) {
        return new SingleThreadIoEventLoop(this, executor, ioHandlerFactory);
    }
    
    @Override
    public IoEventLoop next() {
        return (IoEventLoop)super.next();
    }
    
    private static Object[] combine(final IoHandlerFactory handlerFactory, final Object... args) {
        final List<Object> combinedList = new ArrayList<Object>();
        combinedList.add(handlerFactory);
        if (args != null) {
            Collections.addAll(combinedList, args);
        }
        return combinedList.toArray(new Object[0]);
    }
}
