当前位置: 首页>>代码示例>>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;未经允许,请勿转载。