//TestArrayDequeAsQueue.java
//Here are the essential methods you want for a queue,
//to provide the required FIFO behavior:
//add()
//remove()
//peek()
//size()
//isEmpty()
//clear()
//So, the question is: Does an ArrayDeque provide them?
//And the answer, of course, is yes ... along with many
//other methods that are not essential for a queue, but
//are inherited from AbstractCollection<E>, Collection<E>,
//and Iterable<E>, and that should not be used if one is
//adhering strictly to the notion of a FIFO queue.

import static java.lang.System.out;
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Arrays;

public class TestArrayDequeAsQueue
{
    public static void main(String[] args)
    {
        System.out.println("=====1=========================");
        //Create a queue, confirm that it's empty, and display its size.
        Queue<Integer> qInt = new ArrayDeque<>();
        if (qInt.isEmpty())
        {
            out.println("The queue is empty.");
        }
        else
        {
            out.println("The size of the queue is " + qInt.size() + ".");
        }

        System.out.println("=====2=========================");
        //Add some values to the queue, and then display the
        //first value and the size.
        Integer[] a = { 2, 7, 5, 1, 4, 9 };
        for (int i : a)
        {
            qInt.add(i);
        }
        out.println
        (
            "The value at the front of the queue is "
            + qInt.peek() + "."
        );
        if (qInt.isEmpty())
        {
            out.println("The queue is empty.");
        }
        else
        {
            out.println("The size of the queue is " + qInt.size() + ".");
        }

        System.out.println("=====3=========================");
        //Display the queue as a single entity, along with its size.
        out.println(qInt);
        if (qInt.isEmpty())
        {
            out.println("The queue is empty.");
        }
        else
        {
            out.println("The size of the queue is " + qInt.size() + ".");
        }

        System.out.println("=====4=========================");
        //Clear the queue by removing and displaying one value
        //at a time. Then confirm that it's empty.
        //for (int i : qInt) //<--Can use this for-loop here.
        //Unlike in the priority queue.
        while (!qInt.isEmpty())
        {
            System.out.print(qInt.remove() + " ");
        }
        out.println();
        if (qInt.isEmpty())
        {
            out.println("The queue is empty.");
        }
        else
        {
            out.println("The size of the queue is " + qInt.size() + ".");
        }

        System.out.println("=====5=========================");
        //Re-create the queue as before, but this time by adding
        //all the elements of an array after converting it to a
        //list. Then display the queue and its size.
        qInt.addAll(Arrays.asList(a));
        out.println(qInt);
        out.println(qInt.size());

        System.out.println("=====6=========================");
        //Clear the queue once more and display it a final time.
        qInt.clear();
        out.println(qInt);
    }
}
/*  Output:
    =====1=========================
    The queue is empty.
    =====2=========================
    The value at the front of the queue is 2.
    The size of the queue is 6.
    =====3=========================
    [2, 7, 5, 1, 4, 9]
    The size of the queue is 6.
    =====4=========================
    2 7 5 1 4 9
    The queue is empty.
    =====5=========================
    [2, 7, 5, 1, 4, 9]
    6
    =====6=========================
    []
*/

