本文整理了Java中com.google.common.collect.MinMaxPriorityQueue.remove()
方法的一些代码示例,展示了MinMaxPriorityQueue.remove()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MinMaxPriorityQueue.remove()
方法的具体详情如下:
包路径:com.google.common.collect.MinMaxPriorityQueue
类名称:MinMaxPriorityQueue
方法名:remove
[英]Removes and returns the value at index.
[中]移除并返回索引处的值。
代码示例来源:origin: google/guava
/**
* Removes and returns the least element of this queue.
*
* @throws NoSuchElementException if the queue is empty
*/
@CanIgnoreReturnValue
public E removeFirst() {
return remove();
}
代码示例来源:origin: google/guava
public void testRemoveFromStringHeap() {
MinMaxPriorityQueue<String> mmHeap = MinMaxPriorityQueue.expectedSize(5).create();
Collections.addAll(mmHeap, "foo", "bar", "foobar", "barfoo", "larry", "sergey", "eric");
assertTrue("Heap is not intact initially", mmHeap.isIntact());
assertEquals("bar", mmHeap.peek());
assertEquals("sergey", mmHeap.peekLast());
assertEquals(7, mmHeap.size());
assertTrue("Could not remove larry", mmHeap.remove("larry"));
assertEquals(6, mmHeap.size());
assertFalse("heap contains larry which has been removed", mmHeap.contains("larry"));
assertTrue("heap does not contain sergey", mmHeap.contains("sergey"));
assertTrue("Could not remove larry", mmHeap.removeAll(Lists.newArrayList("sergey", "eric")));
assertFalse("Could remove nikesh which is not in the heap", mmHeap.remove("nikesh"));
assertEquals(4, mmHeap.size());
}
代码示例来源:origin: co.cask.hbase/hbase
/**
* Add a region from the head or tail to the List of regions to return.
*/
void addRegionPlan(final MinMaxPriorityQueue<RegionPlan> regionsToMove,
final boolean fetchFromTail, final ServerName sn, List<RegionPlan> regionsToReturn) {
RegionPlan rp = null;
if (!fetchFromTail) rp = regionsToMove.remove();
else rp = regionsToMove.removeLast();
rp.setDestination(sn);
regionsToReturn.add(rp);
}
代码示例来源:origin: google/j2objc
/**
* Removes and returns the least element of this queue.
*
* @throws NoSuchElementException if the queue is empty
*/
@CanIgnoreReturnValue
public E removeFirst() {
return remove();
}
代码示例来源:origin: google/guava
public void testRemove() {
MinMaxPriorityQueue<Integer> mmHeap = MinMaxPriorityQueue.create();
mmHeap.addAll(Lists.newArrayList(1, 2, 3, 4, 47, 1, 5, 3, 0));
assertTrue("Heap is not intact initally", mmHeap.isIntact());
assertEquals(9, mmHeap.size());
mmHeap.remove(5);
assertEquals(8, mmHeap.size());
assertTrue("Heap is not intact after remove()", mmHeap.isIntact());
assertEquals(47, (int) mmHeap.pollLast());
assertEquals(4, (int) mmHeap.pollLast());
mmHeap.removeAll(Lists.newArrayList(2, 3));
assertEquals(3, mmHeap.size());
assertTrue("Heap is not intact after removeAll()", mmHeap.isIntact());
}
代码示例来源:origin: wildfly/wildfly
/**
* Removes and returns the least element of this queue.
*
* @throws NoSuchElementException if the queue is empty
*/
@CanIgnoreReturnValue
public E removeFirst() {
return remove();
}
代码示例来源:origin: google/guava
/** Regression test for https://github.com/google/guava/issues/2658 */
public void testRemoveRegression() {
MinMaxPriorityQueue<Long> queue =
MinMaxPriorityQueue.create(ImmutableList.of(2L, 3L, 0L, 4L, 1L));
queue.remove(4L);
queue.remove(1L);
assertThat(queue).doesNotContain(1L);
}
代码示例来源:origin: google/guava
/** Tests a failure caused by fix to childless uncle issue. */
public void testIteratorRegressionChildlessUncle() {
final ArrayList<Integer> initial = Lists.newArrayList(1, 15, 13, 8, 9, 10, 11, 14);
MinMaxPriorityQueue<Integer> q = MinMaxPriorityQueue.create(initial);
assertIntact(q);
q.remove(9);
q.remove(11);
q.remove(10);
// Now we're in the critical state: [1, 15, 13, 8, 14]
// Removing 8 while iterating caused duplicates in iteration result.
List<Integer> result = Lists.newArrayListWithCapacity(initial.size());
for (Iterator<Integer> iter = q.iterator(); iter.hasNext(); ) {
Integer value = iter.next();
result.add(value);
if (value == 8) {
iter.remove();
}
}
assertIntact(q);
assertThat(result).containsExactly(1, 15, 13, 8, 14);
}
代码示例来源:origin: google/guava
public void testIteratorConcurrentModification() {
MinMaxPriorityQueue<Integer> mmHeap = MinMaxPriorityQueue.create();
mmHeap.addAll(Lists.newArrayList(1, 2, 3, 4));
Iterator<Integer> it = mmHeap.iterator();
assertTrue("Iterator has reached end prematurely", it.hasNext());
it.next();
it.next();
mmHeap.remove(4);
try {
it.next();
fail("No exception thrown when iterating a modified heap");
} catch (ConcurrentModificationException expected) {
}
}
代码示例来源:origin: google/guava
public void testRandomRemoves() {
Random random = new Random(0);
for (int attempts = 0; attempts < reduceIterationsIfGwt(1000); attempts++) {
ArrayList<Integer> elements = createOrderedList(10);
Collections.shuffle(elements, random);
MinMaxPriorityQueue<Integer> queue = MinMaxPriorityQueue.create(elements);
Collections.shuffle(elements, random);
for (Integer element : elements) {
assertThat(queue.remove(element)).isTrue();
assertIntact(queue);
assertThat(queue).doesNotContain(element);
}
assertThat(queue).isEmpty();
}
}
代码示例来源:origin: google/guava
/** Regression test for b/4124577 */
public void testRegression_dataCorruption() {
int size = 8;
List<Integer> expected = createOrderedList(size);
MinMaxPriorityQueue<Integer> q = MinMaxPriorityQueue.create(expected);
List<Integer> contents = Lists.newArrayList(expected);
List<Integer> elements = Lists.newArrayListWithCapacity(size);
while (!q.isEmpty()) {
assertThat(q).containsExactlyElementsIn(contents);
Integer next = q.pollFirst();
contents.remove(next);
assertThat(q).containsExactlyElementsIn(contents);
for (int i = 0; i <= size; i++) {
q.add(i);
contents.add(i);
assertThat(q).containsExactlyElementsIn(contents);
q.add(next);
contents.add(next);
assertThat(q).containsExactlyElementsIn(contents);
q.remove(i);
assertTrue(contents.remove(Integer.valueOf(i)));
assertThat(q).containsExactlyElementsIn(contents);
assertEquals(next, q.poll());
contents.remove(next);
assertThat(q).containsExactlyElementsIn(contents);
}
elements.add(next);
}
assertEquals(expected, elements);
}
代码示例来源:origin: google/guava
public void testContains() {
MinMaxPriorityQueue<Integer> mmHeap = MinMaxPriorityQueue.create();
mmHeap.addAll(Lists.newArrayList(1, 1, 2));
assertEquals(3, mmHeap.size());
assertFalse("Heap does not contain null", mmHeap.contains(null));
assertFalse("Heap does not contain 3", mmHeap.contains(3));
assertFalse("Heap does not contain 3", mmHeap.remove(3));
assertEquals(3, mmHeap.size());
assertTrue("Heap is not intact after remove()", mmHeap.isIntact());
assertTrue("Heap contains two 1's", mmHeap.contains(1));
assertTrue("Heap contains two 1's", mmHeap.remove(1));
assertTrue("Heap contains 1", mmHeap.contains(1));
assertTrue("Heap contains 1", mmHeap.remove(1));
assertFalse("Heap does not contain 1", mmHeap.contains(1));
assertTrue("Heap contains 2", mmHeap.remove(2));
assertEquals(0, mmHeap.size());
assertFalse("Heap does not contain anything", mmHeap.contains(1));
assertFalse("Heap does not contain anything", mmHeap.remove(2));
}
代码示例来源:origin: google/guava
/** This tests a more obscure special case, but otherwise similar to above. */
public void testInvalidatingRemove2() {
MinMaxPriorityQueue<Integer> mmHeap = MinMaxPriorityQueue.create();
List<Integer> values =
Lists.newArrayList(
1, 20, 1000, 2, 3, 30, 40, 10, 11, 12, 13, 300, 400, 500, 600, 4, 5, 6, 7, 8, 9, 4, 5,
200, 250);
mmHeap.addAll(values);
assertEquals(25, mmHeap.size());
assertTrue("Heap is not intact initially", mmHeap.isIntact());
mmHeap.remove(2);
assertEquals(24, mmHeap.size());
assertTrue("Heap is not intact after remove()", mmHeap.isIntact());
values.removeAll(Lists.newArrayList(2));
assertEquals(values.size(), mmHeap.size());
assertTrue(values.containsAll(mmHeap));
assertTrue(mmHeap.containsAll(values));
}
代码示例来源:origin: google/guava
/**
* This tests a special case of the removeAt() call. Moving an element sideways on the heap could
* break the invariants. Sometimes we need to bubble an element up instead of trickling down. See
* implementation.
*/
public void testInvalidatingRemove() {
MinMaxPriorityQueue<Integer> mmHeap = MinMaxPriorityQueue.create();
mmHeap.addAll(
Lists.newArrayList(1, 20, 1000, 2, 3, 30, 40, 10, 11, 12, 13, 300, 400, 500, 600));
assertEquals(15, mmHeap.size());
assertTrue("Heap is not intact initially", mmHeap.isIntact());
mmHeap.remove(12);
assertEquals(14, mmHeap.size());
assertTrue("Heap is not intact after remove()", mmHeap.isIntact());
}
代码示例来源:origin: google/guava
public void testExhaustive_pollAndPush() {
int size = 5;
List<Integer> expected = createOrderedList(size);
for (Collection<Integer> perm : Collections2.permutations(expected)) {
MinMaxPriorityQueue<Integer> q = MinMaxPriorityQueue.create(perm);
List<Integer> elements = Lists.newArrayListWithCapacity(size);
while (!q.isEmpty()) {
Integer next = q.pollFirst();
for (int i = 0; i <= size; i++) {
assertTrue(q.add(i));
assertTrue(q.add(next));
assertTrue(q.remove(i));
assertEquals(next, q.poll());
}
elements.add(next);
}
assertEqualsUsingStartedWith(perm, expected, elements);
}
}
代码示例来源:origin: com.atlassian.bundles/guava
/**
* Removes and returns the least element of this queue.
*
* @throws NoSuchElementException if the queue is empty
*/
public E removeFirst() {
return remove();
}
代码示例来源:origin: org.hudsonci.lib.guava/guava
/**
* Removes and returns the least element of this queue.
*
* @throws NoSuchElementException if the queue is empty
*/
public E removeFirst() {
return remove();
}
代码示例来源:origin: org.sonatype.sisu/sisu-guava
/**
* Removes and returns the least element of this queue.
*
* @throws NoSuchElementException if the queue is empty
*/
public E removeFirst() {
return remove();
}
代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-analytics
/**
* Removes and returns the least element of this queue.
*
* @throws NoSuchElementException if the queue is empty
*/
public E removeFirst() {
return remove();
}
代码示例来源:origin: org.jboss.eap/wildfly-client-all
/**
* Removes and returns the least element of this queue.
*
* @throws NoSuchElementException if the queue is empty
*/
@CanIgnoreReturnValue
public E removeFirst() {
return remove();
}
内容来源于网络,如有侵权,请联系作者删除!