当前位置: 首页>>代码示例>>Java>>正文


Java ConcurrentNavigableMap.pollFirstEntry方法代码示例

本文整理汇总了Java中java.util.concurrent.ConcurrentNavigableMap.pollFirstEntry方法的典型用法代码示例。如果您正苦于以下问题:Java ConcurrentNavigableMap.pollFirstEntry方法的具体用法?Java ConcurrentNavigableMap.pollFirstEntry怎么用?Java ConcurrentNavigableMap.pollFirstEntry使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.concurrent.ConcurrentNavigableMap的用法示例。


在下文中一共展示了ConcurrentNavigableMap.pollFirstEntry方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testPollFirstEntry

import java.util.concurrent.ConcurrentNavigableMap; //导入方法依赖的package包/类
/**
 * pollFirstEntry returns entries in order
 */
public void testPollFirstEntry() {
    ConcurrentNavigableMap map = map5();
    Map.Entry e = map.pollFirstEntry();
    assertEquals(one, e.getKey());
    assertEquals("A", e.getValue());
    e = map.pollFirstEntry();
    assertEquals(two, e.getKey());
    map.put(one, "A");
    e = map.pollFirstEntry();
    assertEquals(one, e.getKey());
    assertEquals("A", e.getValue());
    e = map.pollFirstEntry();
    assertEquals(three, e.getKey());
    map.remove(four);
    e = map.pollFirstEntry();
    assertEquals(five, e.getKey());
    try {
        e.setValue("A");
        shouldThrow();
    } catch (UnsupportedOperationException success) {}
    e = map.pollFirstEntry();
    assertNull(e);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:ConcurrentSkipListSubMapTest.java

示例2: testDescendingPollFirstEntry

import java.util.concurrent.ConcurrentNavigableMap; //导入方法依赖的package包/类
/**
 * pollFirstEntry returns entries in order
 */
public void testDescendingPollFirstEntry() {
    ConcurrentNavigableMap map = dmap5();
    Map.Entry e = map.pollFirstEntry();
    assertEquals(m1, e.getKey());
    assertEquals("A", e.getValue());
    e = map.pollFirstEntry();
    assertEquals(m2, e.getKey());
    map.put(m1, "A");
    e = map.pollFirstEntry();
    assertEquals(m1, e.getKey());
    assertEquals("A", e.getValue());
    e = map.pollFirstEntry();
    assertEquals(m3, e.getKey());
    map.remove(m4);
    e = map.pollFirstEntry();
    assertEquals(m5, e.getKey());
    try {
        e.setValue("A");
        shouldThrow();
    } catch (UnsupportedOperationException success) {}
    e = map.pollFirstEntry();
    assertNull(e);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:ConcurrentSkipListSubMapTest.java

示例3: main

import java.util.concurrent.ConcurrentNavigableMap; //导入方法依赖的package包/类
/**
 * @param args
 */
public static void main(String[] args) {
	/*
	 * Create the navigable map
	 */
	ConcurrentSkipListMap<String, Contact> map = new ConcurrentSkipListMap<>();

	/*
	 * Create an array to store the 26 threads that execute the tasks
	 */
	Thread threads[] = new Thread[26];
	int counter = 0;

	/*
	 * Execute the 26 tasks
	 */
	for (char i = 'A'; i <= 'Z'; i++) {
		Task task = new Task(map, String.valueOf(i));
		threads[counter] = new Thread(task);
		threads[counter].start();
		counter++;
	}

	/*
	 * Wait for the finalization of the threads
	 */
	for (Thread thread : threads) {
		try {
			thread.join();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}

	/*
	 * Write the size of the map
	 */
	System.out.printf("Main: Size of the map: %d\n", map.size());

	/*
	 * Write the first element of the map
	 */
	Map.Entry<String, Contact> element;
	Contact contact;

	element = map.firstEntry();
	contact = element.getValue();
	System.out.printf("Main: First Entry: %s: %s\n", contact.getName(), contact.getPhone());

	/*
	 * Write the last element of the map
	 */
	element = map.lastEntry();
	contact = element.getValue();
	System.out.printf("Main: Last Entry: %s: %s\n", contact.getName(), contact.getPhone());

	/*
	 * Write a subset of the map
	 */
	System.out.printf("Main: Submap from A1996 to B1002: \n");
	ConcurrentNavigableMap<String, Contact> submap = map.subMap("A1996", "B1002");
	do {
		element = submap.pollFirstEntry();
		if (element != null) {
			contact = element.getValue();
			System.out.printf("%s: %s\n", contact.getName(), contact.getPhone());
		}
	} while (element != null);
}
 
开发者ID:PacktPublishing,项目名称:Java-9-Concurrency-Cookbook-Second-Edition,代码行数:72,代码来源:Main.java


注:本文中的java.util.concurrent.ConcurrentNavigableMap.pollFirstEntry方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。