本文整理了Java中com.google.common.collect.MinMaxPriorityQueue.toArray()
方法的一些代码示例,展示了MinMaxPriorityQueue.toArray()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MinMaxPriorityQueue.toArray()
方法的具体详情如下:
包路径:com.google.common.collect.MinMaxPriorityQueue
类名称:MinMaxPriorityQueue
方法名:toArray
暂无
代码示例来源:origin: apache/hive
public Iterable<Integer> indexes() {
Integer[] array = indexes.toArray(new Integer[indexes.size()]);
Arrays.sort(array, 0, array.length, C);
return Arrays.asList(array);
}
}
代码示例来源:origin: google/guava
private static void assertIntactUsingStartedWith(
Collection<?> startedWith, MinMaxPriorityQueue<?> q) {
if (!q.isIntact()) {
fail("Started with " + startedWith + ". State " + Arrays.toString(q.toArray()));
}
}
代码示例来源:origin: google/guava
private static void assertIntact(MinMaxPriorityQueue<?> q) {
if (!q.isIntact()) {
fail("State " + Arrays.toString(q.toArray()));
}
}
代码示例来源:origin: google/guava
private static void assertIntactUsingSeed(long seed, MinMaxPriorityQueue<?> q) {
if (!q.isIntact()) {
fail("Using seed " + seed + ". State " + Arrays.toString(q.toArray()));
}
}
代码示例来源:origin: com.google.guava/guava-tests
public void testCorrectOrdering_randomAccess() {
long seed = new Random().nextLong();
Random random = new Random(seed);
PriorityQueue<Integer> control = new PriorityQueue<>();
MinMaxPriorityQueue<Integer> q = MinMaxPriorityQueue.create();
for (int i = 0; i < 73; i++) { // 73 is a childless uncle case.
Integer element = random.nextInt();
control.add(element);
assertTrue(q.add(element));
}
assertTrue("State " + Arrays.toString(q.toArray()), q.isIntact());
for (int i = 0; i < 500000; i++) {
if (random.nextBoolean()) {
Integer element = random.nextInt();
control.add(element);
q.add(element);
} else {
assertEquals("Using seed " + seed, control.poll(), q.pollFirst());
}
}
while (!control.isEmpty()) {
assertEquals("Using seed " + seed, control.poll(), q.pollFirst());
}
assertTrue(q.isEmpty());
}
代码示例来源:origin: com.google.guava/guava-tests
/**
* 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);
assertTrue("State " + Arrays.toString(q.toArray()), q.isIntact());
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();
}
}
assertTrue(q.isIntact());
assertThat(result).containsExactly(1, 15, 13, 8, 14);
}
代码示例来源:origin: com.google.guava/guava-tests
/**
* 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));
assertTrue(q.isIntact());
while (!q.isEmpty()) {
elements.add(q.pollFirst());
assertTrue("State " + Arrays.toString(q.toArray()), q.isIntact());
}
assertEquals("Using seed " + seed, expected, elements);
}
内容来源于网络,如有侵权,请联系作者删除!