本文整理了Java中com.google.common.collect.MinMaxPriorityQueue.pollLast()
方法的一些代码示例,展示了MinMaxPriorityQueue.pollLast()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MinMaxPriorityQueue.pollLast()
方法的具体详情如下:
包路径:com.google.common.collect.MinMaxPriorityQueue
类名称:MinMaxPriorityQueue
方法名:pollLast
[英]Removes and returns the greatest element of this queue, or returns null if the queue is empty.
[中]移除并返回此队列中最大的元素,如果队列为空,则返回null。
代码示例来源:origin: google/guava
/**
* Adds the given element to this queue. If this queue has a maximum size, after adding {@code
* element} the queue will automatically evict its greatest element (according to its comparator),
* which may be {@code element} itself.
*/
@CanIgnoreReturnValue
@Override
public boolean offer(E element) {
checkNotNull(element);
modCount++;
int insertIndex = size++;
growIfNeeded();
// Adds the element to the end of the heap and bubbles it up to the correct
// position.
heapForIndex(insertIndex).bubbleUp(insertIndex, element);
return size <= maximumSize || pollLast() != element;
}
代码示例来源:origin: google/j2objc
/**
* Adds the given element to this queue. If this queue has a maximum size, after adding {@code
* element} the queue will automatically evict its greatest element (according to its comparator),
* which may be {@code element} itself.
*/
@CanIgnoreReturnValue
@Override
public boolean offer(E element) {
checkNotNull(element);
modCount++;
int insertIndex = size++;
growIfNeeded();
// Adds the element to the end of the heap and bubbles it up to the correct
// position.
heapForIndex(insertIndex).bubbleUp(insertIndex, element);
return size <= maximumSize || pollLast() != element;
}
代码示例来源:origin: wildfly/wildfly
/**
* Adds the given element to this queue. If this queue has a maximum size, after adding {@code
* element} the queue will automatically evict its greatest element (according to its comparator),
* which may be {@code element} itself.
*/
@CanIgnoreReturnValue
@Override
public boolean offer(E element) {
checkNotNull(element);
modCount++;
int insertIndex = size++;
growIfNeeded();
// Adds the element to the end of the heap and bubbles it up to the correct
// position.
heapForIndex(insertIndex).bubbleUp(insertIndex, element);
return size <= maximumSize || pollLast() != element;
}
代码示例来源:origin: google/guava
public void testCorrectOrdering_mediumHeapsPollLast() {
for (int attempts = 0; attempts < reduceIterationsIfGwt(5000); attempts++) {
int size = new Random().nextInt(256) + 16;
ArrayList<Integer> elements = createOrderedList(size);
List<Integer> expected = ImmutableList.copyOf(elements);
MinMaxPriorityQueue<Integer> q = MinMaxPriorityQueue.create();
long seed = insertRandomly(elements, q);
while (!q.isEmpty()) {
elements.add(0, q.pollLast());
}
assertEqualsUsingSeed(seed, expected, elements);
}
}
代码示例来源:origin: google/guava
public void testCorrectOrdering_smallHeapsPollLast() {
for (int size = 2; size < 16; size++) {
for (int attempts = 0; attempts < size * (size - 1); attempts++) {
ArrayList<Integer> elements = createOrderedList(size);
List<Integer> expected = ImmutableList.copyOf(elements);
MinMaxPriorityQueue<Integer> q = MinMaxPriorityQueue.create();
long seed = insertRandomly(elements, q);
while (!q.isEmpty()) {
elements.add(0, q.pollLast());
}
assertEqualsUsingSeed(seed, expected, elements);
}
}
}
代码示例来源:origin: google/guava
public void testSmall() {
MinMaxPriorityQueue<Integer> mmHeap = MinMaxPriorityQueue.create();
mmHeap.add(1);
mmHeap.add(4);
mmHeap.add(2);
mmHeap.add(3);
assertEquals(4, (int) mmHeap.pollLast());
assertEquals(3, (int) mmHeap.peekLast());
assertEquals(3, (int) mmHeap.pollLast());
assertEquals(1, (int) mmHeap.peek());
assertEquals(2, (int) mmHeap.peekLast());
assertEquals(2, (int) mmHeap.pollLast());
assertEquals(1, (int) mmHeap.peek());
assertEquals(1, (int) mmHeap.peekLast());
assertEquals(1, (int) mmHeap.pollLast());
assertNull(mmHeap.peek());
assertNull(mmHeap.peekLast());
assertNull(mmHeap.pollLast());
}
代码示例来源: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: google/guava
removeMinFromReplica(replica, mmHeap.poll());
} else {
removeMaxFromReplica(replica, mmHeap.pollLast());
代码示例来源:origin: co.cask.hbase/hbase
/**
* @return The last element in this queue, or {@code null} if the queue is
* empty.
*/
public CachedBlock pollLast() {
return queue.pollLast();
}
代码示例来源:origin: com.google.guava/guava-tests
@Override
public T poll() {
return mmHeap.pollLast();
}
代码示例来源:origin: at.bestsolution.efxclipse.eclipse/com.google.guava
/**
* Adds the given element to this queue. If this queue has a maximum size,
* after adding {@code element} the queue will automatically evict its
* greatest element (according to its comparator), which may be {@code
* element} itself.
*/
@Override public boolean offer(E element) {
checkNotNull(element);
modCount++;
int insertIndex = size++;
growIfNeeded();
// Adds the element to the end of the heap and bubbles it up to the correct
// position.
heapForIndex(insertIndex).bubbleUp(insertIndex, element);
return size <= maximumSize || pollLast() != element;
}
代码示例来源:origin: org.hudsonci.lib.guava/guava
/**
* Adds the given element to this queue. If this queue has a maximum size,
* after adding {@code element} the queue will automatically evict its
* greatest element (according to its comparator), which may be {@code
* element} itself.
*/
@Override public boolean offer(E element) {
checkNotNull(element);
modCount++;
int insertIndex = size++;
growIfNeeded();
// Adds the element to the end of the heap and bubbles it up to the correct
// position.
heapForIndex(insertIndex).bubbleUp(insertIndex, element);
return size <= maximumSize || pollLast() != element;
}
代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby
/**
* Adds the given element to this queue. If this queue has a maximum size,
* after adding {@code element} the queue will automatically evict its
* greatest element (according to its comparator), which may be {@code
* element} itself.
*/
@Override public boolean offer(E element) {
checkNotNull(element);
modCount++;
int insertIndex = size++;
growIfNeeded();
// Adds the element to the end of the heap and bubbles it up to the correct
// position.
heapForIndex(insertIndex).bubbleUp(insertIndex, element);
return size <= maximumSize || pollLast() != element;
}
代码示例来源:origin: org.sonatype.sisu/sisu-guava
/**
* Adds the given element to this queue. If this queue has a maximum size,
* after adding {@code element} the queue will automatically evict its
* greatest element (according to its comparator), which may be {@code
* element} itself.
*/
@Override public boolean offer(E element) {
checkNotNull(element);
modCount++;
int insertIndex = size++;
growIfNeeded();
// Adds the element to the end of the heap and bubbles it up to the correct
// position.
heapForIndex(insertIndex).bubbleUp(insertIndex, element);
return size <= maximumSize || pollLast() != element;
}
代码示例来源:origin: Nextdoor/bender
/**
* Adds the given element to this queue. If this queue has a maximum size,
* after adding {@code element} the queue will automatically evict its
* greatest element (according to its comparator), which may be {@code
* element} itself.
*/
@Override public boolean offer(E element) {
checkNotNull(element);
modCount++;
int insertIndex = size++;
growIfNeeded();
// Adds the element to the end of the heap and bubbles it up to the correct
// position.
heapForIndex(insertIndex).bubbleUp(insertIndex, element);
return size <= maximumSize || pollLast() != element;
}
代码示例来源:origin: com.google.guava/guava-jdk5
/**
* Adds the given element to this queue. If this queue has a maximum size,
* after adding {@code element} the queue will automatically evict its
* greatest element (according to its comparator), which may be {@code
* element} itself.
*/
@Override public boolean offer(E element) {
checkNotNull(element);
modCount++;
int insertIndex = size++;
growIfNeeded();
// Adds the element to the end of the heap and bubbles it up to the correct
// position.
heapForIndex(insertIndex).bubbleUp(insertIndex, element);
return size <= maximumSize || pollLast() != element;
}
代码示例来源:origin: com.atlassian.bundles/guava
/**
* Adds the given element to this queue. If this queue has a maximum size,
* after adding {@code element} the queue will automatically evict its
* greatest element (according to its comparator), which may be {@code
* element} itself.
*/
@Override public boolean offer(E element) {
checkNotNull(element);
modCount++;
int insertIndex = size++;
growIfNeeded();
// Adds the element to the end of the heap and bubbles it up to the correct
// position.
heapForIndex(insertIndex).bubbleUp(insertIndex, element);
return size <= maximumSize || pollLast() != element;
}
代码示例来源:origin: com.google.guava/guava-tests
public void testCorrectOrdering_mediumHeapsPollLast() {
for (int attempts = 0; attempts < 5000; attempts++) {
int size = new Random().nextInt(256) + 16;
ArrayList<Integer> elements = createOrderedList(size);
List<Integer> expected = ImmutableList.copyOf(elements);
MinMaxPriorityQueue<Integer> q = MinMaxPriorityQueue.create();
long seed = insertRandomly(elements, q);
while (!q.isEmpty()) {
elements.add(0, q.pollLast());
}
assertEquals("Using seed " + seed, expected, elements);
}
}
代码示例来源:origin: com.google.guava/guava-tests
public void testCorrectOrdering_smallHeapsPollLast() {
for (int size = 2; size < 16; size++) {
for (int attempts = 0; attempts < size * (size - 1); attempts++) {
ArrayList<Integer> elements = createOrderedList(size);
List<Integer> expected = ImmutableList.copyOf(elements);
MinMaxPriorityQueue<Integer> q = MinMaxPriorityQueue.create();
long seed = insertRandomly(elements, q);
while (!q.isEmpty()) {
elements.add(0, q.pollLast());
}
assertEquals("Using seed " + seed, expected, elements);
}
}
}
代码示例来源:origin: com.google.guava/guava-tests
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());
}
内容来源于网络,如有侵权,请联系作者删除!