Java Code Examples for java.util.stream.Stream#sequential()

The following examples show how to use java.util.stream.Stream#sequential() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public void testParSeq() {
    Stream<Integer> s = Arrays.asList(1, 2, 3, 4).stream().parallel();
    assertTrue(s.isParallel());

    s = s.sequential();
    assertFalse(s.isParallel());

    s = s.sequential();
    assertFalse(s.isParallel());

    s = s.parallel();
    assertTrue(s.isParallel());

    s = s.parallel();
    assertTrue(s.isParallel());
}
 
Example 2
public void testParSeq() {
    Stream<Integer> s = Arrays.asList(1, 2, 3, 4).stream().parallel();
    assertTrue(s.isParallel());

    s = s.sequential();
    assertFalse(s.isParallel());

    s = s.sequential();
    assertFalse(s.isParallel());

    s = s.parallel();
    assertTrue(s.isParallel());

    s = s.parallel();
    assertTrue(s.isParallel());
}
 
Example 3
public void testParSeq() {
    Stream<Integer> s = Arrays.asList(1, 2, 3, 4).stream().parallel();
    assertTrue(s.isParallel());

    s = s.sequential();
    assertFalse(s.isParallel());

    s = s.sequential();
    assertFalse(s.isParallel());

    s = s.parallel();
    assertTrue(s.isParallel());

    s = s.parallel();
    assertTrue(s.isParallel());
}
 
Example 4
public void testParSeq() {
    Stream<Integer> s = Arrays.asList(1, 2, 3, 4).stream().parallel();
    assertTrue(s.isParallel());

    s = s.sequential();
    assertFalse(s.isParallel());

    s = s.sequential();
    assertFalse(s.isParallel());

    s = s.parallel();
    assertTrue(s.isParallel());

    s = s.parallel();
    assertTrue(s.isParallel());
}
 
Example 5
public void testParSeq() {
    Stream<Integer> s = Arrays.asList(1, 2, 3, 4).stream().parallel();
    assertTrue(s.isParallel());

    s = s.sequential();
    assertFalse(s.isParallel());

    s = s.sequential();
    assertFalse(s.isParallel());

    s = s.parallel();
    assertTrue(s.isParallel());

    s = s.parallel();
    assertTrue(s.isParallel());
}
 
Example 6
public void testParSeq() {
    Stream<Integer> s = Arrays.asList(1, 2, 3, 4).stream().parallel();
    assertTrue(s.isParallel());

    s = s.sequential();
    assertFalse(s.isParallel());

    s = s.sequential();
    assertFalse(s.isParallel());

    s = s.parallel();
    assertTrue(s.isParallel());

    s = s.parallel();
    assertTrue(s.isParallel());
}
 
Example 7
public void testParSeq() {
    Stream<Integer> s = Arrays.asList(1, 2, 3, 4).stream().parallel();
    assertTrue(s.isParallel());

    s = s.sequential();
    assertFalse(s.isParallel());

    s = s.sequential();
    assertFalse(s.isParallel());

    s = s.parallel();
    assertTrue(s.isParallel());

    s = s.parallel();
    assertTrue(s.isParallel());
}
 
Example 8
public void testParSeq() {
    Stream<Integer> s = Arrays.asList(1, 2, 3, 4).stream().parallel();
    assertTrue(s.isParallel());

    s = s.sequential();
    assertFalse(s.isParallel());

    s = s.sequential();
    assertFalse(s.isParallel());

    s = s.parallel();
    assertTrue(s.isParallel());

    s = s.parallel();
    assertTrue(s.isParallel());
}
 
Example 9
public void testParSeq() {
    Stream<Integer> s = Arrays.asList(1, 2, 3, 4).stream().parallel();
    assertTrue(s.isParallel());

    s = s.sequential();
    assertFalse(s.isParallel());

    s = s.sequential();
    assertFalse(s.isParallel());

    s = s.parallel();
    assertTrue(s.isParallel());

    s = s.parallel();
    assertTrue(s.isParallel());
}
 
Example 10
public void testParSeq() {
    Stream<Integer> s = Arrays.asList(1, 2, 3, 4).stream().parallel();
    assertTrue(s.isParallel());

    s = s.sequential();
    assertFalse(s.isParallel());

    s = s.sequential();
    assertFalse(s.isParallel());

    s = s.parallel();
    assertTrue(s.isParallel());

    s = s.parallel();
    assertTrue(s.isParallel());
}
 
Example 11
public void testParSeq() {
    Stream<Integer> s = Arrays.asList(1, 2, 3, 4).stream().parallel();
    assertTrue(s.isParallel());

    s = s.sequential();
    assertFalse(s.isParallel());

    s = s.sequential();
    assertFalse(s.isParallel());

    s = s.parallel();
    assertTrue(s.isParallel());

    s = s.parallel();
    assertTrue(s.isParallel());
}
 
Example 12
Source Project: streamex   File: TestHelpers.java    License: Apache License 2.0 6 votes vote down vote up
public Stream<T> get() {
    Stream<T> res = base.get();
    switch (mode) {
    case NORMAL:
    case SPLITERATOR: 
        return res.sequential();
    case PARALLEL:
        return res.parallel();
    case APPEND:
        // using Stream.empty() or Arrays.asList() here is optimized out
        // in append/prepend which is undesired
        return StreamEx.of(res.parallel()).append(new ConcurrentLinkedQueue<>());
    case PREPEND:
        return StreamEx.of(res.parallel()).prepend(new ConcurrentLinkedQueue<>());
    case RANDOM:
        return StreamEx.of(new EmptyingSpliterator<>(res.parallel().spliterator())).parallel();
    default:
        throw new InternalError("Unsupported mode: " + mode);
    }
}
 
Example 13
public void testParSeq() {
    Stream<Integer> s = Arrays.asList(1, 2, 3, 4).stream().parallel();
    assertTrue(s.isParallel());

    s = s.sequential();
    assertFalse(s.isParallel());

    s = s.sequential();
    assertFalse(s.isParallel());

    s = s.parallel();
    assertTrue(s.isParallel());

    s = s.parallel();
    assertTrue(s.isParallel());
}
 
Example 14
public void testParSeq() {
    Stream<Integer> s = Arrays.asList(1, 2, 3, 4).stream().parallel();
    assertTrue(s.isParallel());

    s = s.sequential();
    assertFalse(s.isParallel());

    s = s.sequential();
    assertFalse(s.isParallel());

    s = s.parallel();
    assertTrue(s.isParallel());

    s = s.parallel();
    assertTrue(s.isParallel());
}