本文整理了Java中com.google.common.collect.MinMaxPriorityQueue.create()
方法的一些代码示例,展示了MinMaxPriorityQueue.create()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MinMaxPriorityQueue.create()
方法的具体详情如下:
包路径:com.google.common.collect.MinMaxPriorityQueue
类名称:MinMaxPriorityQueue
方法名:create
[英]Creates a new min-max priority queue with default settings: natural order, no maximum size, no initial contents, and an initial expected size of 11.
[中]使用默认设置创建一个新的最小-最大优先级队列:自然顺序、无最大大小、无初始内容,初始预期大小为11。
代码示例来源:origin: google/guava
@Override
public <E extends Comparable<E>> Queue<E> create(Collection<E> contents) {
return MinMaxPriorityQueue.create(contents);
}
};
代码示例来源:origin: google/guava
@Override
protected Queue<String> create(String[] elements) {
return MinMaxPriorityQueue.create(Arrays.asList(elements));
}
})
代码示例来源:origin: google/guava
@Override
protected Iterator<T> newTargetIterator() {
mmHeap = MinMaxPriorityQueue.create(values);
return mmHeap.iterator();
}
代码示例来源:origin: google/guava
/** Regression test for bug found. */
public void testCorrectOrdering_regression() {
MinMaxPriorityQueue<Integer> q = MinMaxPriorityQueue.create(ImmutableList.of(3, 5, 1, 4, 7));
List<Integer> expected = ImmutableList.of(1, 3, 4, 5, 7);
List<Integer> actual = new ArrayList<>(5);
for (int i = 0; i < expected.size(); i++) {
actual.add(q.pollFirst());
}
assertEquals(expected, actual);
}
代码示例来源:origin: google/guava
public void testIteratorPastEndException() {
MinMaxPriorityQueue<Integer> mmHeap = MinMaxPriorityQueue.create();
mmHeap.addAll(Lists.newArrayList(1, 2));
Iterator<Integer> it = mmHeap.iterator();
assertTrue("Iterator has reached end prematurely", it.hasNext());
it.next();
it.next();
try {
it.next();
fail("No exception thrown when iterating past end of heap");
} catch (NoSuchElementException expected) {
}
}
代码示例来源: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
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 testCorrectOrdering_mediumHeapsPollFirst() {
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(q.pollFirst());
}
assertEqualsUsingSeed(seed, expected, elements);
}
}
代码示例来源: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
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_smallHeapsPollFirst() {
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(q.pollFirst());
}
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 testRemoveAt_exhaustive() {
int size = reduceExponentIfGwt(8);
List<Integer> expected = createOrderedList(size);
for (Collection<Integer> perm : Collections2.permutations(expected)) {
for (int i = 0; i < perm.size(); i++) {
MinMaxPriorityQueue<Integer> q = MinMaxPriorityQueue.create(perm);
q.removeAt(i);
assertIntactUsingStartedWith(perm, q);
}
}
}
代码示例来源:origin: google/guava
public void testCreation_simple() {
MinMaxPriorityQueue<Integer> queue = MinMaxPriorityQueue.create();
assertEquals(11, queue.capacity());
checkUnbounded(queue);
checkNatural(queue);
}
代码示例来源:origin: google/guava
/** Regression test for bug found in random testing. */
public void testCorrectOrdering_73ElementBug() {
int size = 73;
long seed = 7522346378524621981L;
ArrayList<Integer> elements = createOrderedList(size);
List<Integer> expected = ImmutableList.copyOf(elements);
MinMaxPriorityQueue<Integer> q = MinMaxPriorityQueue.create();
insertRandomly(elements, q, new Random(seed));
assertIntact(q);
while (!q.isEmpty()) {
elements.add(q.pollFirst());
assertIntact(q);
}
assertEqualsUsingSeed(seed, expected, elements);
}
代码示例来源:origin: google/guava
@GwtIncompatible // NullPointerTester
public void testNullPointers() {
NullPointerTester tester = new NullPointerTester();
tester.testAllPublicConstructors(MinMaxPriorityQueue.class);
tester.testAllPublicStaticMethods(MinMaxPriorityQueue.class);
tester.testAllPublicInstanceMethods(MinMaxPriorityQueue.<String>create());
}
代码示例来源:origin: google/guava
public void testCreation_withContents() {
MinMaxPriorityQueue<Integer> queue = MinMaxPriorityQueue.create(NUMBERS);
assertEquals(6, queue.size());
assertEquals(11, queue.capacity());
checkUnbounded(queue);
checkNatural(queue);
}
代码示例来源: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 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
public void testSmallMinHeap() {
MinMaxPriorityQueue<Integer> mmHeap = MinMaxPriorityQueue.create();
mmHeap.add(1);
mmHeap.add(3);
mmHeap.add(2);
assertEquals(1, (int) mmHeap.peek());
assertEquals(1, (int) mmHeap.poll());
assertEquals(3, (int) mmHeap.peekLast());
assertEquals(2, (int) mmHeap.peek());
assertEquals(2, (int) mmHeap.poll());
assertEquals(3, (int) mmHeap.peekLast());
assertEquals(3, (int) mmHeap.peek());
assertEquals(3, (int) mmHeap.poll());
assertNull(mmHeap.peekLast());
assertNull(mmHeap.peek());
assertNull(mmHeap.poll());
}
内容来源于网络,如有侵权,请联系作者删除!