001/**
002 * Logback: the reliable, generic, fast and flexible logging framework.
003 * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
004 *
005 * This program and the accompanying materials are dual-licensed under
006 * either the terms of the Eclipse Public License v1.0 as published by
007 * the Eclipse Foundation
008 *
009 *   or (per the licensee's choosing)
010 *
011 * under the terms of the GNU Lesser General Public License version 2.1
012 * as published by the Free Software Foundation.
013 */
014package ch.qos.logback.core.net;
015
016import java.util.concurrent.ArrayBlockingQueue;
017import java.util.concurrent.LinkedBlockingDeque;
018
019/**
020 * Factory for {@link java.util.Queue} instances.
021 *
022 * @author Sebastian Gröbler
023 */
024public class QueueFactory {
025
026    /**
027     * Creates a new {@link LinkedBlockingDeque} with the given {@code capacity}. In
028     * case the given capacity is smaller than one it will automatically be
029     * converted to one.
030     *
031     * @param capacity the capacity to use for the queue
032     * @param <E>      the type of elements held in the queue
033     * @return a new instance of {@link ArrayBlockingQueue}
034     */
035    public <E> LinkedBlockingDeque<E> newLinkedBlockingDeque(int capacity) {
036        final int actualCapacity = capacity < 1 ? 1 : capacity;
037        return new LinkedBlockingDeque<E>(actualCapacity);
038    }
039}