當前位置: 首頁>>代碼示例>>Java>>正文


Java PriorityQueue.iterator方法代碼示例

本文整理匯總了Java中java.util.PriorityQueue.iterator方法的典型用法代碼示例。如果您正苦於以下問題:Java PriorityQueue.iterator方法的具體用法?Java PriorityQueue.iterator怎麽用?Java PriorityQueue.iterator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.PriorityQueue的用法示例。


在下文中一共展示了PriorityQueue.iterator方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testIteratorRemove

import java.util.PriorityQueue; //導入方法依賴的package包/類
/**
 * iterator.remove removes current element
 */
public void testIteratorRemove() {
    final PriorityQueue q = new PriorityQueue(3);
    q.add(new Integer(2));
    q.add(new Integer(1));
    q.add(new Integer(3));

    Iterator it = q.iterator();
    it.next();
    it.remove();

    it = q.iterator();
    assertEquals(it.next(), new Integer(2));
    assertEquals(it.next(), new Integer(3));
    assertFalse(it.hasNext());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:PriorityQueueTest.java

示例2: peekCustomerByOffice

import java.util.PriorityQueue; //導入方法依賴的package包/類
public QCustomer peekCustomerByOffice(QOffice office) {
    //QLog.l().logQUser().debug("peekCustomerByOffice: " + office);

    //  CM:  Get a list of all customers wanting this service.
    PriorityQueue<QCustomer> customers = getCustomers();
    QCustomer customer = null;

    //  CM:  Loop through all customers to see if they are in the office input.   
    for (Iterator<QCustomer> itr = customers.iterator(); itr.hasNext(); ) {
        final QCustomer cust = itr.next();
        //  QLog.l().logQUser().debug("Polling customer: " + cust);
        // QLog.l().logQUser().debug("  Office: " + cust.getOffice());
        // QLog.l().logQUser().debug(" Service: " + cust.getService().name);
        if (cust.getOffice().equals(office)) {
            customer = cust;
            break;
        }
    }

    return customer;
}
 
開發者ID:bcgov,項目名稱:sbc-qsystem,代碼行數:22,代碼來源:QService.java

示例3: peekAllCustomerByOffice

import java.util.PriorityQueue; //導入方法依賴的package包/類
public PriorityQueue<QCustomer> peekAllCustomerByOffice(QOffice office) {

        //  Debug.
        QLog.l().logQUser().debug("==> Start: peekAllCustomerByOffice: " + office);

        //  CM:  Init vars of all customers wanting this service, and those in input office.
        PriorityQueue<QCustomer> customers = getCustomers();
        PriorityQueue<QCustomer> custHere = new PriorityQueue<QCustomer>();
        QCustomer customer = null;

        //  CM:  Loop through all customers to see if they are in the office input.   
        for (Iterator<QCustomer> itr = customers.iterator(); itr.hasNext();) {
            final QCustomer cust = itr.next();
            //QLog.l().logQUser().debug("Polling customer: " + cust);
            //QLog.l().logQUser().debug("  Office: " + cust.getOffice());
            //QLog.l().logQUser().debug(" Service: " + cust.getService().name);
            if (cust.getOffice().equals(office)) {
                custHere.add(cust);
            }
        }

        //  Debug.
        QLog.l().logQUser().debug("==> End: peekAllCustomerByOffice: " + office + "; Customers: " + custHere.size());

        return custHere;
    }
 
開發者ID:bcgov,項目名稱:sbc-qsystem,代碼行數:27,代碼來源:QService.java

示例4: testIterator

import java.util.PriorityQueue; //導入方法依賴的package包/類
/**
 * iterator iterates through all elements
 */
public void testIterator() {
    PriorityQueue q = populatedQueue(SIZE);
    Iterator it = q.iterator();
    int i;
    for (i = 0; it.hasNext(); i++)
        assertTrue(q.contains(it.next()));
    assertEquals(i, SIZE);
    assertIteratorExhausted(it);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:13,代碼來源:PriorityQueueTest.java

示例5: getCountCustomersByOffice

import java.util.PriorityQueue; //導入方法依賴的package包/類
public int getCountCustomersByOffice(QOffice office) {
    PriorityQueue<QCustomer> customers = getCustomers();
    int count = 0;

    for (Iterator<QCustomer> itr = customers.iterator(); itr.hasNext(); ) {
        final QCustomer c = itr.next();
        if (c.getOffice().equals(office)) {
            count += 1;
        }
    }

    return count;
}
 
開發者ID:bcgov,項目名稱:sbc-qsystem,代碼行數:14,代碼來源:QService.java

示例6: realMain

import java.util.PriorityQueue; //導入方法依賴的package包/類
private static void realMain(String[] args) throws Throwable {
    final PriorityQueue<Integer> q = new PriorityQueue<>();
    Iterator<Integer> it;

    //----------------------------------------------------------------
    // Empty
    //----------------------------------------------------------------
    checkQ(q);
    check(q.isEmpty());
    check(! q.contains(1));
    it = q.iterator();
    removeIsCurrentlyIllegal(it);
    noMoreElements(it);
    q.clear();
    check(q.isEmpty());

    //----------------------------------------------------------------
    // Singleton
    //----------------------------------------------------------------
    q.add(1);
    checkQ(q, 1);
    check(! q.isEmpty());
    check(q.contains(1));
    it = q.iterator();
    removeIsCurrentlyIllegal(it);
    check(it.hasNext());
    equal(it.next(), 1);
    noMoreElements(it);
    remove(it, q);
    check(q.isEmpty());
    noMoreElements(it);
    checkQ(q);
    q.clear();

    //----------------------------------------------------------------
    // @see PriorityQueue.forgetMeNot
    //----------------------------------------------------------------
    final Integer[] a = {0, 4, 1, 6, 7, 2, 3}; // Carefully chosen!
    q.addAll(Arrays.asList(a));
    checkQ(q, a);
    it = q.iterator();
    checkQ(q, a);
    removeIsCurrentlyIllegal(it);
    checkQ(q, a);
    check(it.hasNext());
    removeIsCurrentlyIllegal(it);
    checkQ(q, a);
    check(it.hasNext());
    equal(it.next(), 0);
    equal(it.next(), 4);
    equal(it.next(), 1);
    equal(it.next(), 6);
    check(it.hasNext());
    checkQ(q, a);
    remove(it, q);
    checkQ(q, 0, 3, 1, 4, 7, 2);
    check(it.hasNext());
    removeIsCurrentlyIllegal(it);
    equal(it.next(), 7);
    remove(it, q);
    checkQ(q, 0, 2, 1, 4, 3);
    check(it.hasNext());
    removeIsCurrentlyIllegal(it);
    check(it.hasNext());
    equal(it.next(), 3);
    equal(it.next(), 2);
    check(! it.hasNext());
    remove(it, q);
    checkQ(q, 0, 3, 1, 4);
    check(! it.hasNext());
    noMoreElements(it);
    removeIsCurrentlyIllegal(it);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:74,代碼來源:ForgetMeNot.java

示例7: polCustomerByOffice

import java.util.PriorityQueue; //導入方法依賴的package包/類
public QCustomer polCustomerByOffice(QOffice office) {

        //  CM:  NOTE:  First part of this code is identical to peekCustomerByOffice code.
        //  CM:  peekCustomerByOffice finds the next customer.  This routine finds next
        //  CM:  customer and then removes them from the queue.
        QLog.l().logQUser().debug("polCustomerByOffice: " + office);
        PriorityQueue<QCustomer> customers = getCustomers();
        QCustomer customer = null;

        for (Iterator<QCustomer> itr = customers.iterator(); itr.hasNext(); ) {
            final QCustomer cust = itr.next();
            QLog.l().logQUser().debug("Polling customer: " + cust);
            QLog.l().logQUser().debug("  Office: " + cust.getOffice());
            if (cust.getOffice().equals(office)) {
                customer = cust;
                break;
            }
        }

        //  CM:  Code from here on is additional to the peekCustomerByOffice code.
        if (customer != null) {

            //  CM:  This gets executed, when customer is not null.
            QLog.l().logQUser().debug("Cust not null: " + customer.getName() + "; Comments: " + customer.getTempComments());
            int Count = 0;

            // поддержка расширяемости плагинами
            //  CM:  However, this DOES NOT appear to remove any customers, as debug never gets called.
            for (final ICustomerChangePosition event : ServiceLoader
                .load(ICustomerChangePosition.class)) {
                QLog.l().logQUser().debug("Removing customer out of the queue");
                event.remove(customer);
                Count++;
            }

            //  CM:  This does get called, indicating there are no events in the ServiceLoader.load()
            if (Count == 0) {
                QLog.l().logQUser().debug("It appears customer not removed from event queue");
            }
        }

        //  CM:  This appears to have no effect.  Size of clients before/after call is identical.
        int BeforeClear = clients.size();
        clients.clear();
        int AfterClear = clients.size();
        clients.addAll(getCustomers());
        int AfterAdd = clients.size();
        QLog.l().logQUser().debug("Clients before clear: " + BeforeClear + "; after clear: " + AfterClear + "; after add: " + AfterAdd);

        return customer;
    }
 
開發者ID:bcgov,項目名稱:sbc-qsystem,代碼行數:52,代碼來源:QService.java


注:本文中的java.util.PriorityQueue.iterator方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。