Skip to content
Snippets Groups Projects
Exercises.java 38.3 KiB
Newer Older
        
        assertEquals(result1, result2);
        assertFalse(stream1isParallel);
        assertTrue(stream2isParallel);
    }
    // Hint 1:
    // <editor-fold defaultstate="collapsed">
    // By its very nature, you need to do something with side-effects within Stream.peek().
    // </editor-fold>
    // Hint 2:
    // <editor-fold defaultstate="collapsed">
    // The sequential and parallel streams have the same contents, but they will
    // probably end up processing the elements in a different order, even though
    // the output list is collected in the proper order (encounter order).
    // </editor-fold>
    // Hint 3:
    // <editor-fold defaultstate="collapsed">
    // Consider a thread-safe side-effect-supporting structure such as LongAdder.
    // Note that LongAdder's accumulation function must be order-dependent for it
    // to detect parallelism.
    // </editor-fold>

// ========================================================
// END OF EXERCISES -- CONGRATULATIONS!
// TEST INFRASTRUCTURE IS BELOW
// ========================================================

    static final String REGEXP = "[- .:,]+"; // for splitting into words

    private BufferedReader reader;

    @Before
    public void z_setUpBufferedReader() throws IOException {
        reader = Files.newBufferedReader(
                Paths.get("SonnetI.txt"), StandardCharsets.UTF_8);
    }

    @After
    public void z_closeBufferedReader() throws IOException {
        reader.close();
    }
}

//BEGINREMOVE
/*
 * Procedure for deriving exercise file from answers.
 * - Open a shell and change do the LambdaLab/test/solutions directory.
 * - Run the "cleanit" perl script from within this directory.
 * - This should generate the LambdaLab/test/exercises/Exercises.java file automatically.
 * - Make sure the only files open in the project are (unsolved!) Exercises.java and
 *   SonnetI.txt, then run clean, and close the NB project.
 */
//ENDREMOVE