//TestPriorityQueue1.java
//Here are the essential methods you want for a priority queue:
//add()
//remove()
//peek()
//size()
//isEmpty()
//clear()
//This particular priority queue is the "default" version.

import static java.lang.System.out;
import java.util.Arrays;
import java.util.PriorityQueue;

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

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

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

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

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

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

