FIFO Queue Management Multiple dialog display

Source: Internet
Author: User

In the project we sometimes encounter such a scenario, the home page loading data to pop up a load dialog box, after loading the data may have to pop up a selection confirmation box to locate the city, or the Personal Preferences dialog box, or interested in the Column Subscription selection dialog box. To make it easier to manage dialog, the previous dialog box is canceled and the next dialog box is displayed, and we can queue the dialog with a FIFO queue.

Private queque<dialog> Dialogqueue = new linkedlist<> ();p rivate Dialog currentdialog = null; The currently displayed dialog box private void ShowDialog (Dialog Dialog) {    if (Dialog! = null) {        dialogqueue.offer (Dialog);    }    if (Currentdialog = = null) {        Currentdialog = Dialogqueue.poll ();        if (currentdialog! = null) {            currentdialog.show ();            Currentdialog.setondismisslistener (New Dialoginterface.ondismisslistener () {                        @Override public                        Void Ondismiss (Dialoginterface Dialog) {                            currentdialog = null;                            ShowDialog (null);}}                    );        }    }
OK, just need to call the ShowDialog () method when we need to display the dialog box, is it convenient? ~ ~ Java, queue usage is very high, most of the production consumption model of the preferred data structure is the queue. The queue interface is the same level as the list and set interface, inheriting the collection interface, and LinkedList implements the queue interface. The queue has two basic operations: an element is added to the end of the queue, and an element is moved from the head of the queue. That is, the queue manages the data in a first in, out-of-the-way manner, and if you attempt to add an element to a blocked queue that is already full or remove an element from an empty blocking queue, it will cause the thread to block. To avoid the Add () and remove () methods of the collection interface, use the queue as much as possible. It is best to queue up with an offer (), and the team will use poll () without throwing an exception. The comparison is as follows: Add adds a single cable if the queue is full, a Iiiegaislabeepeplian exception is thrown
Remove removes and returns the element of the queue header if the queue is empty, throw an nosuchelementexception exception offer adds an element and returns true if the queue is full, false
Poll removing and returning elements to the queue header returns null if the queue is empty
    /**     * Inserts the specified element into this queue if it's possible to does     * so immediately without violating cap acity restrictions.     * When using a capacity-restricted queue, this method was generally     * preferable to {@link #add}, which can fail to INS ERT an element is only     * by throwing an exception.     *     * @param e The element to add     * @return <tt>true</tt> If the element is added to this queue, else
   *         <tt>false</tt>     * @throws classcastexception if the class of the specified element     *         prevents it from being added to this queue     * @throws NullPointerException If the specified element is null and< c15/>* This         queue does is permit null elements     * @throws illegalargumentexception If some property of this Elem ENT     *         prevents it from being added to the this queue     *    /Boolean offer (e e);

  

    /**     * Retrieves and removes the head of this queue,     * or returns <tt>null</tt> if this queue is empty.     *     * @return The head of this queue, or <tt>null</tt> if this queue is empty     *    /E poll ();

FIFO Queue Management Multiple dialog display

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.