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


Java ConcurrentLinkedDeque.add方法代码示例

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


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

示例1: testIteratorRemove

import java.util.concurrent.ConcurrentLinkedDeque; //导入方法依赖的package包/类
/**
 * iterator.remove() removes current element
 */
public void testIteratorRemove() {
    final ConcurrentLinkedDeque q = new ConcurrentLinkedDeque();
    final Random rng = new Random();
    for (int iters = 0; iters < 100; ++iters) {
        int max = rng.nextInt(5) + 2;
        int split = rng.nextInt(max - 1) + 1;
        for (int j = 1; j <= max; ++j)
            q.add(new Integer(j));
        Iterator it = q.iterator();
        for (int j = 1; j <= split; ++j)
            assertEquals(it.next(), new Integer(j));
        it.remove();
        assertEquals(it.next(), new Integer(split + 1));
        for (int j = 1; j <= split; ++j)
            q.remove(new Integer(j));
        it = q.iterator();
        for (int j = split + 1; j <= max; ++j) {
            assertEquals(it.next(), new Integer(j));
            it.remove();
        }
        assertFalse(it.hasNext());
        assertTrue(q.isEmpty());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:ConcurrentLinkedDequeTest.java

示例2: testDescendingIteratorOrdering

import java.util.concurrent.ConcurrentLinkedDeque; //导入方法依赖的package包/类
/**
 * Descending iterator ordering is reverse FIFO
 */
public void testDescendingIteratorOrdering() {
    final ConcurrentLinkedDeque q = new ConcurrentLinkedDeque();
    for (int iters = 0; iters < 100; ++iters) {
        q.add(new Integer(3));
        q.add(new Integer(2));
        q.add(new Integer(1));
        int k = 0;
        for (Iterator it = q.descendingIterator(); it.hasNext();) {
            assertEquals(++k, it.next());
        }

        assertEquals(3, k);
        q.remove();
        q.remove();
        q.remove();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:ConcurrentLinkedDequeTest.java

示例3: testDescendingIteratorRemove

import java.util.concurrent.ConcurrentLinkedDeque; //导入方法依赖的package包/类
/**
 * descendingIterator.remove() removes current element
 */
public void testDescendingIteratorRemove() {
    final ConcurrentLinkedDeque q = new ConcurrentLinkedDeque();
    final Random rng = new Random();
    for (int iters = 0; iters < 100; ++iters) {
        int max = rng.nextInt(5) + 2;
        int split = rng.nextInt(max - 1) + 1;
        for (int j = max; j >= 1; --j)
            q.add(new Integer(j));
        Iterator it = q.descendingIterator();
        for (int j = 1; j <= split; ++j)
            assertEquals(it.next(), new Integer(j));
        it.remove();
        assertEquals(it.next(), new Integer(split + 1));
        for (int j = 1; j <= split; ++j)
            q.remove(new Integer(j));
        it = q.descendingIterator();
        for (int j = split + 1; j <= max; ++j) {
            assertEquals(it.next(), new Integer(j));
            it.remove();
        }
        assertFalse(it.hasNext());
        assertTrue(q.isEmpty());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:ConcurrentLinkedDequeTest.java

示例4: compute

import java.util.concurrent.ConcurrentLinkedDeque; //导入方法依赖的package包/类
@Override
protected void compute() {
	
	if (persons.size() < 1000) {
		
		for (Person person: persons) {
			ConcurrentLinkedDeque<Person> personList=personMap.computeIfAbsent(person.getFirstName(), name -> {
				return new ConcurrentLinkedDeque<>();
			});
			personList.add(person);
		}
		return;
	}
	
	PersonMapTask child1, child2;

	child1 = new PersonMapTask(persons.subList(0, persons.size() / 2), personMap);
	child2 = new PersonMapTask(persons.subList(persons.size() / 2, persons.size()), personMap);

	invokeAll(child1, child2);

}
 
开发者ID:PacktPublishing,项目名称:Java-9-Concurrency-Cookbook-Second-Edition,代码行数:23,代码来源:PersonMapTask.java

示例5: testEmpty

import java.util.concurrent.ConcurrentLinkedDeque; //导入方法依赖的package包/类
/**
 * isEmpty is true before add, false after
 */
public void testEmpty() {
    ConcurrentLinkedDeque q = new ConcurrentLinkedDeque();
    assertTrue(q.isEmpty());
    q.add(one);
    assertFalse(q.isEmpty());
    q.add(two);
    q.remove();
    q.remove();
    assertTrue(q.isEmpty());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:ConcurrentLinkedDequeTest.java

示例6: testSize

import java.util.concurrent.ConcurrentLinkedDeque; //导入方法依赖的package包/类
/**
 * size() changes when elements added and removed
 */
public void testSize() {
    ConcurrentLinkedDeque q = populatedDeque(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(SIZE - i, q.size());
        q.remove();
    }
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(i, q.size());
        q.add(new Integer(i));
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:ConcurrentLinkedDequeTest.java

示例7: testAddNull

import java.util.concurrent.ConcurrentLinkedDeque; //导入方法依赖的package包/类
/**
 * add(null) throws NPE
 */
public void testAddNull() {
    ConcurrentLinkedDeque q = new ConcurrentLinkedDeque();
    try {
        q.add(null);
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:ConcurrentLinkedDequeTest.java

示例8: testClear

import java.util.concurrent.ConcurrentLinkedDeque; //导入方法依赖的package包/类
/**
 * clear() removes all elements
 */
public void testClear() {
    ConcurrentLinkedDeque q = populatedDeque(SIZE);
    q.clear();
    assertTrue(q.isEmpty());
    assertEquals(0, q.size());
    q.add(one);
    assertFalse(q.isEmpty());
    q.clear();
    assertTrue(q.isEmpty());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:ConcurrentLinkedDequeTest.java

示例9: testContainsAll

import java.util.concurrent.ConcurrentLinkedDeque; //导入方法依赖的package包/类
/**
 * containsAll(c) is true when c contains a subset of elements
 */
public void testContainsAll() {
    ConcurrentLinkedDeque q = populatedDeque(SIZE);
    ConcurrentLinkedDeque p = new ConcurrentLinkedDeque();
    for (int i = 0; i < SIZE; ++i) {
        assertTrue(q.containsAll(p));
        assertFalse(p.containsAll(q));
        p.add(new Integer(i));
    }
    assertTrue(p.containsAll(q));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:ConcurrentLinkedDequeTest.java

示例10: testIteratorOrdering

import java.util.concurrent.ConcurrentLinkedDeque; //导入方法依赖的package包/类
/**
 * Iterator ordering is FIFO
 */
public void testIteratorOrdering() {
    final ConcurrentLinkedDeque q = new ConcurrentLinkedDeque();
    q.add(one);
    q.add(two);
    q.add(three);

    int k = 0;
    for (Iterator it = q.iterator(); it.hasNext();) {
        assertEquals(++k, it.next());
    }

    assertEquals(3, k);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:ConcurrentLinkedDequeTest.java

示例11: testWeaklyConsistentIteration

import java.util.concurrent.ConcurrentLinkedDeque; //导入方法依赖的package包/类
/**
 * Modifications do not cause iterators to fail
 */
public void testWeaklyConsistentIteration() {
    final ConcurrentLinkedDeque q = new ConcurrentLinkedDeque();
    q.add(one);
    q.add(two);
    q.add(three);

    for (Iterator it = q.iterator(); it.hasNext();) {
        q.remove();
        it.next();
    }

    assertEquals("deque should be empty again", 0, q.size());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:ConcurrentLinkedDequeTest.java

示例12: addOperationToHash

import java.util.concurrent.ConcurrentLinkedDeque; //导入方法依赖的package包/类
private void addOperationToHash(ConcurrentHashMap<String, ConcurrentLinkedDeque<Operation>> userHash,
		Operation operation) {

	ConcurrentLinkedDeque<Operation> opList = userHash.computeIfAbsent(operation.getUser(), user -> new ConcurrentLinkedDeque<>());

	opList.add(operation);

}
 
开发者ID:PacktPublishing,项目名称:Java-9-Concurrency-Cookbook-Second-Edition,代码行数:9,代码来源:HashFiller.java


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