本文整理匯總了Java中java.util.Spliterator.hasCharacteristics方法的典型用法代碼示例。如果您正苦於以下問題:Java Spliterator.hasCharacteristics方法的具體用法?Java Spliterator.hasCharacteristics怎麽用?Java Spliterator.hasCharacteristics使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.Spliterator
的用法示例。
在下文中一共展示了Spliterator.hasCharacteristics方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: trySplitTestingSize
import java.util.Spliterator; //導入方法依賴的package包/類
@Nullable
private static <E> Spliterator<E> trySplitTestingSize(Spliterator<E> spliterator) {
boolean subsized = spliterator.hasCharacteristics(Spliterator.SUBSIZED);
long originalSize = spliterator.estimateSize();
Spliterator<E> trySplit = spliterator.trySplit();
if (spliterator.estimateSize() > originalSize) {
fail(
format(
"estimated size of spliterator after trySplit (%s) is larger than original size (%s)",
spliterator.estimateSize(),
originalSize));
}
if (trySplit != null) {
if (trySplit.estimateSize() > originalSize) {
fail(
format(
"estimated size of trySplit result (%s) is larger than original size (%s)",
trySplit.estimateSize(),
originalSize));
}
}
if (subsized) {
if (trySplit != null) {
assertEquals(
"sum of estimated sizes of trySplit and original spliterator after trySplit",
originalSize,
trySplit.estimateSize() + spliterator.estimateSize());
} else {
assertEquals(
"estimated size of spliterator after failed trySplit",
originalSize,
spliterator.estimateSize());
}
}
return trySplit;
}
示例2: testSplitUntilNull
import java.util.Spliterator; //導入方法依賴的package包/類
private static <T, S extends Spliterator<T>> void testSplitUntilNull(
Collection<T> exp,
Supplier<S> supplier,
UnaryOperator<Consumer<T>> boxingAdapter,
ContentAsserter<T> asserter) {
Spliterator<T> s = supplier.get();
boolean isOrdered = s.hasCharacteristics(Spliterator.ORDERED);
assertSpliterator(s);
List<T> splits = new ArrayList<>();
Consumer<T> c = boxingAdapter.apply(splits::add);
testSplitUntilNull(new SplitNode<T>(c, s));
asserter.assertContents(splits, exp, isOrdered);
}
示例3: assertSpliterator
import java.util.Spliterator; //導入方法依賴的package包/類
private static void assertSpliterator(Spliterator<?> s) {
if (s.hasCharacteristics(Spliterator.SUBSIZED)) {
assertTrue(s.hasCharacteristics(Spliterator.SIZED));
}
if (s.hasCharacteristics(Spliterator.SIZED)) {
assertTrue(s.estimateSize() != Long.MAX_VALUE);
assertTrue(s.getExactSizeIfKnown() >= 0);
}
try {
s.getComparator();
assertTrue(s.hasCharacteristics(Spliterator.SORTED));
} catch (IllegalStateException e) {
assertFalse(s.hasCharacteristics(Spliterator.SORTED));
}
}
示例4: testSplitUntilNull
import java.util.Spliterator; //導入方法依賴的package包/類
private static <T, S extends Spliterator<T>> void testSplitUntilNull(
Collection<T> exp,
Supplier<S> supplier,
UnaryOperator<Consumer<T>> boxingAdapter) {
Spliterator<T> s = supplier.get();
boolean isOrdered = s.hasCharacteristics(Spliterator.ORDERED);
assertSpliterator(s);
List<T> splits = new ArrayList<>();
Consumer<T> c = boxingAdapter.apply(splits::add);
testSplitUntilNull(new SplitNode<T>(c, s));
assertContents(splits, exp, isOrdered);
}
示例5: testSplitUntilNull
import java.util.Spliterator; //導入方法依賴的package包/類
private static <T, S extends Spliterator<T>> void testSplitUntilNull(
Collection<T> exp,
Supplier<S> supplier,
UnaryOperator<Consumer<T>> boxingAdapter) {
Spliterator<T> s = supplier.get();
boolean isOrdered = s.hasCharacteristics(Spliterator.ORDERED);
assertRootSpliterator(s);
List<T> splits = new ArrayList<>();
Consumer<T> c = boxingAdapter.apply(splits::add);
testSplitUntilNull(new SplitNode<T>(c, s));
assertContents(splits, exp, isOrdered);
}
示例6: testElementRemovalDuringTraversal
import java.util.Spliterator; //導入方法依賴的package包/類
/**
* All elements removed in the middle of CONCURRENT traversal.
*/
public void testElementRemovalDuringTraversal() {
Collection c = impl.emptyCollection();
ThreadLocalRandom rnd = ThreadLocalRandom.current();
int n = rnd.nextInt(6);
ArrayList copy = new ArrayList();
for (int i = 0; i < n; i++) {
Object x = impl.makeElement(i);
copy.add(x);
c.add(x);
}
ArrayList iterated = new ArrayList();
ArrayList spliterated = new ArrayList();
Spliterator s = c.spliterator();
Iterator it = c.iterator();
for (int i = rnd.nextInt(n + 1); --i >= 0; ) {
assertTrue(s.tryAdvance(spliterated::add));
if (rnd.nextBoolean()) assertTrue(it.hasNext());
iterated.add(it.next());
}
Consumer alwaysThrows = e -> { throw new AssertionError(); };
if (s.hasCharacteristics(Spliterator.CONCURRENT)) {
c.clear(); // TODO: many more removal methods
if (testImplementationDetails
&& !(c instanceof java.util.concurrent.ArrayBlockingQueue)) {
if (rnd.nextBoolean())
assertFalse(s.tryAdvance(alwaysThrows));
else
s.forEachRemaining(alwaysThrows);
}
if (it.hasNext()) iterated.add(it.next());
if (rnd.nextBoolean()) assertIteratorExhausted(it);
}
assertTrue(copy.containsAll(iterated));
assertTrue(copy.containsAll(spliterated));
}
示例7: testGetComparator_IllegalStateException
import java.util.Spliterator; //導入方法依賴的package包/類
/**
* Spliterator.getComparator throws IllegalStateException iff the
* spliterator does not report SORTED.
*/
public void testGetComparator_IllegalStateException() {
Collection c = impl.emptyCollection();
Spliterator s = c.spliterator();
boolean reportsSorted = s.hasCharacteristics(Spliterator.SORTED);
try {
s.getComparator();
assertTrue(reportsSorted);
} catch (IllegalStateException ex) {
assertFalse(reportsSorted);
}
}
示例8: sourceSpliterator
import java.util.Spliterator; //導入方法依賴的package包/類
/**
* Get the source spliterator for this pipeline stage. For a sequential or
* stateless parallel pipeline, this is the source spliterator. For a
* stateful parallel pipeline, this is a spliterator describing the results
* of all computations up to and including the most recent stateful
* operation.
*/
@SuppressWarnings("unchecked")
private Spliterator<?> sourceSpliterator(int terminalFlags) {
// Get the source spliterator of the pipeline
Spliterator<?> spliterator = null;
if (sourceStage.sourceSpliterator != null) {
spliterator = sourceStage.sourceSpliterator;
sourceStage.sourceSpliterator = null;
}
else if (sourceStage.sourceSupplier != null) {
spliterator = (Spliterator<?>) sourceStage.sourceSupplier.get();
sourceStage.sourceSupplier = null;
}
else {
throw new IllegalStateException(MSG_CONSUMED);
}
if (isParallel() && sourceStage.sourceAnyStateful) {
// Adapt the source spliterator, evaluating each stateful op
// in the pipeline up to and including this pipeline stage.
// The depth and flags of each pipeline stage are adjusted accordingly.
int depth = 1;
for (@SuppressWarnings("rawtypes") AbstractPipeline u = sourceStage, p = sourceStage.nextStage, e = this;
u != e;
u = p, p = p.nextStage) {
int thisOpFlags = p.sourceOrOpFlags;
if (p.opIsStateful()) {
depth = 0;
if (StreamOpFlag.SHORT_CIRCUIT.isKnown(thisOpFlags)) {
// Clear the short circuit flag for next pipeline stage
// This stage encapsulates short-circuiting, the next
// stage may not have any short-circuit operations, and
// if so spliterator.forEachRemaining should be used
// for traversal
thisOpFlags = thisOpFlags & ~StreamOpFlag.IS_SHORT_CIRCUIT;
}
spliterator = p.opEvaluateParallelLazy(u, spliterator);
// Inject or clear SIZED on the source pipeline stage
// based on the stage's spliterator
thisOpFlags = spliterator.hasCharacteristics(Spliterator.SIZED)
? (thisOpFlags & ~StreamOpFlag.NOT_SIZED) | StreamOpFlag.IS_SIZED
: (thisOpFlags & ~StreamOpFlag.IS_SIZED) | StreamOpFlag.NOT_SIZED;
}
p.depth = depth++;
p.combinedFlags = StreamOpFlag.combineOpFlags(thisOpFlags, u.combinedFlags);
}
}
if (terminalFlags != 0) {
// Apply flags from the terminal operation to last pipeline stage
combinedFlags = StreamOpFlag.combineOpFlags(terminalFlags, combinedFlags);
}
return spliterator;
}