Newer
Older
Stuart Marks
committed
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
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
// ========================================================
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
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