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


Java ConcurrentSkipListMap.subMap方法代碼示例

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


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

示例1: testSubMapContents

import java.util.concurrent.ConcurrentSkipListMap; //導入方法依賴的package包/類
/**
 * subMap returns map with keys in requested range
 */
public void testSubMapContents() {
    ConcurrentSkipListMap map = map5();
    NavigableMap sm = map.subMap(two, true, four, false);
    assertEquals(two, sm.firstKey());
    assertEquals(three, sm.lastKey());
    assertEquals(2, sm.size());
    assertFalse(sm.containsKey(one));
    assertTrue(sm.containsKey(two));
    assertTrue(sm.containsKey(three));
    assertFalse(sm.containsKey(four));
    assertFalse(sm.containsKey(five));
    Iterator i = sm.keySet().iterator();
    Object k;
    k = (Integer)(i.next());
    assertEquals(two, k);
    k = (Integer)(i.next());
    assertEquals(three, k);
    assertFalse(i.hasNext());
    Iterator r = sm.descendingKeySet().iterator();
    k = (Integer)(r.next());
    assertEquals(three, k);
    k = (Integer)(r.next());
    assertEquals(two, k);
    assertFalse(r.hasNext());

    Iterator j = sm.keySet().iterator();
    j.next();
    j.remove();
    assertFalse(map.containsKey(two));
    assertEquals(4, map.size());
    assertEquals(1, sm.size());
    assertEquals(three, sm.firstKey());
    assertEquals(three, sm.lastKey());
    assertEquals("C", sm.remove(three));
    assertTrue(sm.isEmpty());
    assertEquals(3, map.size());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:41,代碼來源:ConcurrentSkipListMapTest.java

示例2: testSubMapContents2

import java.util.concurrent.ConcurrentSkipListMap; //導入方法依賴的package包/類
public void testSubMapContents2() {
    ConcurrentSkipListMap map = map5();
    NavigableMap sm = map.subMap(two, true, three, false);
    assertEquals(1, sm.size());
    assertEquals(two, sm.firstKey());
    assertEquals(two, sm.lastKey());
    assertFalse(sm.containsKey(one));
    assertTrue(sm.containsKey(two));
    assertFalse(sm.containsKey(three));
    assertFalse(sm.containsKey(four));
    assertFalse(sm.containsKey(five));
    Iterator i = sm.keySet().iterator();
    Object k;
    k = (Integer)(i.next());
    assertEquals(two, k);
    assertFalse(i.hasNext());
    Iterator r = sm.descendingKeySet().iterator();
    k = (Integer)(r.next());
    assertEquals(two, k);
    assertFalse(r.hasNext());

    Iterator j = sm.keySet().iterator();
    j.next();
    j.remove();
    assertFalse(map.containsKey(two));
    assertEquals(4, map.size());
    assertEquals(0, sm.size());
    assertTrue(sm.isEmpty());
    assertSame(sm.remove(three), null);
    assertEquals(4, map.size());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:32,代碼來源:ConcurrentSkipListMapTest.java

示例3: map5

import java.util.concurrent.ConcurrentSkipListMap; //導入方法依賴的package包/類
/**
 * Returns a new map from Integers 1-5 to Strings "A"-"E".
 */
private static ConcurrentNavigableMap map5() {
    ConcurrentSkipListMap map = new ConcurrentSkipListMap();
    assertTrue(map.isEmpty());
    map.put(zero, "Z");
    map.put(one, "A");
    map.put(five, "E");
    map.put(three, "C");
    map.put(two, "B");
    map.put(four, "D");
    map.put(seven, "F");
    assertFalse(map.isEmpty());
    assertEquals(7, map.size());
    return map.subMap(one, true, seven, false);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:18,代碼來源:ConcurrentSkipListSubMapTest.java

示例4: main

import java.util.concurrent.ConcurrentSkipListMap; //導入方法依賴的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.ConcurrentSkipListMap.subMap方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。