From dba5181326c47a285f667593d3e870505ce2a5e3 Mon Sep 17 00:00:00 2001 From: fredericselva Date: Mon, 27 Mar 2017 16:05:56 +0100 Subject: [PATCH 1/2] exoDone --- stream-api/hs_err_pid5304.log | 248 ++++++++++++++++++ .../test/java/stream/api/Exercise1Test.java | 8 +- .../test/java/stream/api/Exercise2Test.java | 21 +- .../test/java/stream/api/Exercise3Test.java | 2 + 4 files changed, 268 insertions(+), 11 deletions(-) create mode 100644 stream-api/hs_err_pid5304.log diff --git a/stream-api/hs_err_pid5304.log b/stream-api/hs_err_pid5304.log new file mode 100644 index 0000000..cd734d4 --- /dev/null +++ b/stream-api/hs_err_pid5304.log @@ -0,0 +1,248 @@ +# +# A fatal error has been detected by the Java Runtime Environment: +# +# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00000000618ea0a5, pid=5304, tid=0x00000000000012c8 +# +# JRE version: Java(TM) SE Runtime Environment (8.0_101-b13) (build 1.8.0_101-b13) +# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.101-b13 mixed mode windows-amd64 compressed oops) +# Problematic frame: +# V [jvm.dll+0x12a0a5] +# +# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows +# +# If you would like to submit a bug report, please visit: +# http://bugreport.java.com/bugreport/crash.jsp +# + +--------------- T H R E A D --------------- + +Current thread (0x0000000058797000): JavaThread "JDWP Transport Listener: dt_socket" daemon [_thread_in_vm, id=4808, stack(0x0000000059190000,0x0000000059290000)] + +siginfo: ExceptionCode=0xc0000005, reading address 0xffffffffffffffff + +Registers: +RAX=0x000000005928f801, RBX=0x0000000058797000, RCX=0x88007a000b750001, RDX=0x0000000000000000 +RSP=0x000000005928f7f0, RBP=0x88007a000b750001, RSI=0x000000005928f908, RDI=0x000000000214b780 +R8 =0x0000000058797000, R9 =0x000000000000ff00, R10=0x0000000000000000, R11=0xb6321df601be0010 +R12=0x0000000000000000, R13=0x000000005879cdf8, R14=0x0000000000000000, R15=0x0000000000000000 +RIP=0x00000000618ea0a5, EFLAGS=0x0000000000010282 + +Top of Stack: (sp=0x000000005928f7f0) +0x000000005928f7f0: 0000000058797000 0000000058797000 +0x000000005928f800: 000000005928f8b8 0000000061af2f0b +0x000000005928f810: 0000000058797000 0000000061b0f76d +0x000000005928f820: 0000000000000000 000000006e969155 +0x000000005928f830: 0000000058863938 000000006e97291e +0x000000005928f840: 0000000058797000 0000000000000000 +0x000000005928f850: 0000000000000000 0000000000000000 +0x000000005928f860: 88007a000b750001 000000006e971a15 +0x000000005928f870: 000000005928f908 000000005928f8e0 +0x000000005928f880: 0000000000000001 0000000058863938 +0x000000005928f890: 88007a000b750001 000000006e9553b3 +0x000000005928f8a0: 000000005928f9d0 0000000000000001 +0x000000005928f8b0: 0000000000000001 0000000058863938 +0x000000005928f8c0: 00000000f000100a 0000000000000000 +0x000000005928f8d0: 0000000000000000 0000000000000000 +0x000000005928f8e0: 0000000000000001 000000006e955571 + +Instructions: (pc=0x00000000618ea0a5) +0x00000000618ea085: cc cc cc cc cc cc cc cc cc cc cc 48 83 ec 28 48 +0x00000000618ea095: 85 c9 75 07 33 c0 48 83 c4 28 c3 48 89 5c 24 20 +0x00000000618ea0a5: 48 8b 19 48 85 db 74 20 48 83 fb 37 74 1a 48 8b +0x00000000618ea0b5: 13 48 8b cb ff 52 10 84 c0 74 0d 48 8b c3 48 8b + + +Register to memory mapping: + +RAX=0x000000005928f801 is pointing into the stack for thread: 0x0000000058797000 +RBX=0x0000000058797000 is a thread +RCX=0x88007a000b750001 is an unknown value +RDX=0x0000000000000000 is an unknown value +RSP=0x000000005928f7f0 is pointing into the stack for thread: 0x0000000058797000 +RBP=0x88007a000b750001 is an unknown value +RSI=0x000000005928f908 is pointing into the stack for thread: 0x0000000058797000 +RDI=0x000000000214b780 is an unknown value +R8 =0x0000000058797000 is a thread +R9 =0x000000000000ff00 is an unknown value +R10=0x0000000000000000 is an unknown value +R11=0xb6321df601be0010 is an unknown value +R12=0x0000000000000000 is an unknown value +R13=0x000000005879cdf8 is an unknown value +R14=0x0000000000000000 is an unknown value +R15=0x0000000000000000 is an unknown value + + +Stack: [0x0000000059190000,0x0000000059290000], sp=0x000000005928f7f0, free space=1021k +Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code) +V [jvm.dll+0x12a0a5] +V [jvm.dll+0x34f76d] +C [jdwp.dll+0x21a15] +C [jdwp.dll+0x53b3] +C [jdwp.dll+0x5571] +C [jdwp.dll+0xf0a8] +C [jdwp.dll+0x1f2d5] +C [jdwp.dll+0x1f4aa] +V [jvm.dll+0x1bd258] +V [jvm.dll+0x2451a4] +V [jvm.dll+0x29c18a] +C [msvcr100.dll+0x21d9f] +C [msvcr100.dll+0x21e3b] +C [kernel32.dll+0x159cd] +C [ntdll.dll+0x2a2e1] + + +--------------- P R O C E S S --------------- + +Java Threads: ( => current thread ) + 0x0000000058830800 JavaThread "Service Thread" daemon [_thread_blocked, id=1376, stack(0x0000000059b60000,0x0000000059c60000)] + 0x00000000587bb800 JavaThread "C1 CompilerThread2" daemon [_thread_blocked, id=3032, stack(0x0000000059900000,0x0000000059a00000)] + 0x00000000587af000 JavaThread "C2 CompilerThread1" daemon [_thread_blocked, id=5820, stack(0x0000000059760000,0x0000000059860000)] + 0x00000000587b8800 JavaThread "C2 CompilerThread0" daemon [_thread_blocked, id=5704, stack(0x0000000059060000,0x0000000059160000)] + 0x00000000587ad000 JavaThread "JDWP Command Reader" daemon [_thread_in_native, id=6096, stack(0x0000000059500000,0x0000000059600000)] + 0x000000005741d000 JavaThread "JDWP Event Helper Thread" daemon [_thread_blocked, id=4940, stack(0x0000000059310000,0x0000000059410000)] +=>0x0000000058797000 JavaThread "JDWP Transport Listener: dt_socket" daemon [_thread_in_vm, id=4808, stack(0x0000000059190000,0x0000000059290000)] + 0x0000000058791000 JavaThread "Attach Listener" daemon [_thread_blocked, id=5920, stack(0x0000000058de0000,0x0000000058ee0000)] + 0x0000000058790800 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=5612, stack(0x0000000058c70000,0x0000000058d70000)] + 0x00000000573fb000 JavaThread "Finalizer" daemon [_thread_blocked, id=2852, stack(0x00000000584b0000,0x00000000585b0000)] + 0x00000000573b4000 JavaThread "Reference Handler" daemon [_thread_blocked, id=5832, stack(0x00000000585b0000,0x00000000586b0000)] + 0x000000000214f000 JavaThread "main" [_thread_blocked, id=4896, stack(0x00000000022f0000,0x00000000023f0000)] + +Other Threads: + 0x00000000573ac000 VMThread [stack: 0x0000000058380000,0x0000000058480000] [id=1372] + 0x0000000058854800 WatcherThread [stack: 0x0000000059d00000,0x0000000059e00000] [id=5348] + +VM state:not at safepoint (normal execution) + +VM Mutex/Monitor currently owned by a thread: None + +Heap: + PSYoungGen total 38400K, used 9387K [0x00000000d5d00000, 0x00000000d8780000, 0x0000000100000000) + eden space 33280K, 28% used [0x00000000d5d00000,0x00000000d662aeb8,0x00000000d7d80000) + from space 5120K, 0% used [0x00000000d8280000,0x00000000d8280000,0x00000000d8780000) + to space 5120K, 0% used [0x00000000d7d80000,0x00000000d7d80000,0x00000000d8280000) + ParOldGen total 87552K, used 0K [0x0000000081600000, 0x0000000086b80000, 0x00000000d5d00000) + object space 87552K, 0% used [0x0000000081600000,0x0000000081600000,0x0000000086b80000) + Metaspace used 8955K, capacity 9182K, committed 9472K, reserved 1056768K + class space used 1082K, capacity 1163K, committed 1280K, reserved 1048576K + +Card table byte_map: [0x0000000011a80000,0x0000000011e80000] byte_map_base: 0x0000000011675000 + +Marking Bits: (ParMarkBitMap*) 0x0000000061fda6d0 + Begin Bits: [0x00000000126d0000, 0x0000000014678000) + End Bits: [0x0000000014678000, 0x0000000016620000) + +Polling page: 0x0000000000240000 + +CodeCache: size=245760Kb used=2413Kb max_used=2423Kb free=243346Kb + bounds [0x00000000026c0000, 0x0000000002930000, 0x00000000116c0000] + total_blobs=855 nmethods=566 adapters=210 + compilation: enabled + +Compilation events (10 events): +Event: 1.022 Thread 0x00000000587bb800 561 3 java.lang.invoke.MethodType::insertParameterTypes (106 bytes) +Event: 1.024 Thread 0x00000000587bb800 nmethod 561 0x0000000002917d90 code [0x0000000002918060, 0x0000000002919368] +Event: 1.026 Thread 0x00000000587bb800 562 3 jdk.internal.org.objectweb.asm.Type::getArgumentTypes (131 bytes) +Event: 1.027 Thread 0x00000000587bb800 nmethod 562 0x0000000002919f10 code [0x000000000291a0e0, 0x000000000291a9b8] +Event: 1.029 Thread 0x00000000587bb800 564 3 java.lang.reflect.Modifier::isPublic (12 bytes) +Event: 1.030 Thread 0x00000000587bb800 nmethod 564 0x000000000291af10 code [0x000000000291b060, 0x000000000291b1f0] +Event: 1.030 Thread 0x00000000587af000 565 4 java.util.concurrent.ConcurrentHashMap::casTabAt (20 bytes) +Event: 1.030 Thread 0x00000000587bb800 566 3 jdk.internal.org.objectweb.asm.Label:: (5 bytes) +Event: 1.030 Thread 0x00000000587bb800 nmethod 566 0x000000000291b250 code [0x000000000291b3a0, 0x000000000291b550] +Event: 1.030 Thread 0x00000000587af000 nmethod 565 0x000000000291e290 code [0x000000000291e3c0, 0x000000000291e438] + +GC Heap History (0 events): +No events + +Deoptimization events (1 events): +Event: 0.749 Thread 0x000000000214f000 Uncommon trap: reason=unstable_if action=reinterpret pc=0x000000000283daac method=java.lang.String.indexOf([CII[CIII)I @ 3 + +Internal exceptions (10 events): +Event: 0.780 Thread 0x000000000214f000 Exception (0x00000000d6315fa8) thrown at [C:\re\workspace\8-2-build-windows-amd64-cygwin\jdk8u101\7261\hotspot\src\share\vm\runtime\sharedRuntime.cpp, line 605] +Event: 0.780 Thread 0x000000000214f000 Exception (0x00000000d6317268) thrown at [C:\re\workspace\8-2-build-windows-amd64-cygwin\jdk8u101\7261\hotspot\src\share\vm\runtime\sharedRuntime.cpp, line 605] +Event: 0.795 Thread 0x000000000214f000 Exception (0x00000000d63541c0) thrown at [C:\re\workspace\8-2-build-windows-amd64-cygwin\jdk8u101\7261\hotspot\src\share\vm\runtime\sharedRuntime.cpp, line 605] +Event: 0.798 Thread 0x000000000214f000 Exception (0x00000000d635a378) thrown at [C:\re\workspace\8-2-build-windows-amd64-cygwin\jdk8u101\7261\hotspot\src\share\vm\runtime\sharedRuntime.cpp, line 605] +Event: 0.799 Thread 0x000000000214f000 Exception (0x00000000d635eec8) thrown at [C:\re\workspace\8-2-build-windows-amd64-cygwin\jdk8u101\7261\hotspot\src\share\vm\runtime\sharedRuntime.cpp, line 605] +Event: 0.805 Thread 0x000000000214f000 Exception (0x00000000d6378db0) thrown at [C:\re\workspace\8-2-build-windows-amd64-cygwin\jdk8u101\7261\hotspot\src\share\vm\runtime\sharedRuntime.cpp, line 605] +Event: 0.805 Thread 0x000000000214f000 Exception (0x00000000d6379f50) thrown at [C:\re\workspace\8-2-build-windows-amd64-cygwin\jdk8u101\7261\hotspot\src\share\vm\runtime\sharedRuntime.cpp, line 605] +Event: 0.983 Thread 0x000000000214f000 Exception (0x00000000d65128c0) thrown at [C:\re\workspace\8-2-build-windows-amd64-cygwin\jdk8u101\7261\hotspot\src\share\vm\prims\methodHandles.cpp, line 1146] +Event: 0.991 Thread 0x000000000214f000 Exception (0x00000000d651ff80) thrown at [C:\re\workspace\8-2-build-windows-amd64-cygwin\jdk8u101\7261\hotspot\src\share\vm\prims\methodHandles.cpp, line 1146] +Event: 1.022 Thread 0x000000000214f000 Exception (0x00000000d65a60e0) thrown at [C:\re\workspace\8-2-build-windows-amd64-cygwin\jdk8u101\7261\hotspÇ^“Ž<ôè? + +Events (10 events): +Event: 548.134 Executing VM operation: ForceSafepoint +Event: 548.134 Executing VM operation: ForceSafepoint done +Event: 548.153 Executing VM operation: ForceSafepoint +Event: 548.153 Executing VM operation: ForceSafepoint done +Event: 551.136 Executing VM operation: GetOrSetLocal +Event: 551.136 Executing VM operation: GetOrSetLocal done +Event: 5372.668 Executing VM operation: ChangeBreakpoints +Event: 5372.668 Executing VM operation: ChangeBreakpoints done +Event: 5635.574 Executing VM operation: RedefineClasses +Event: 5635.583 Executing VM operation: RedefineClasses done + + +Dynamic libraries: +0x000000013f6a0000 - 0x000000013f6d7000 C:\Program Files\Java\jdk1.8.0_101\bin\java.exe +0x0000000076e40000 - 0x0000000076fea000 C:\windows\SYSTEM32\ntdll.dll +0x0000000076c20000 - 0x0000000076d3f000 C:\windows\system32\kernel32.dll +0x000007fefcc70000 - 0x000007fefccda000 C:\windows\system32\KERNELBASE.dll +0x000007fefd200000 - 0x000007fefd2db000 C:\windows\system32\ADVAPI32.dll +0x000007fefe4f0000 - 0x000007fefe58f000 C:\windows\system32\msvcrt.dll +0x000007fefe590000 - 0x000007fefe5af000 C:\windows\SYSTEM32\sechost.dll +0x000007fefee90000 - 0x000007fefefbd000 C:\windows\system32\RPCRT4.dll +0x0000000076d40000 - 0x0000000076e3a000 C:\windows\system32\USER32.dll +0x000007fefd2e0000 - 0x000007fefd347000 C:\windows\system32\GDI32.dll +0x000007fefcf30000 - 0x000007fefcf3e000 C:\windows\system32\LPK.dll +0x000007fefec90000 - 0x000007fefed5a000 C:\windows\system32\USP10.dll +0x000007fefae40000 - 0x000007fefb034000 C:\windows\WinSxS\amd64_microsoft.windows.common-controls_6595b64144ccf1df_6.0.7601.18837_none_fa3b1e3d17594757\COMCTL32.dll +0x000007fefee10000 - 0x000007fefee81000 C:\windows\system32\SHLWAPI.dll +0x000007fefec60000 - 0x000007fefec8e000 C:\windows\system32\IMM32.DLL +0x000007fefe160000 - 0x000007fefe269000 C:\windows\system32\MSCTF.dll +0x0000000064cd0000 - 0x0000000064da2000 C:\Program Files\Java\jdk1.8.0_101\jre\bin\msvcr100.dll +0x00000000617c0000 - 0x000000006205a000 C:\Program Files\Java\jdk1.8.0_101\jre\bin\server\jvm.dll +0x000007fef9130000 - 0x000007fef9139000 C:\windows\system32\WSOCK32.dll +0x000007fefedc0000 - 0x000007fefee0d000 C:\windows\system32\WS2_32.dll +0x000007fefd150000 - 0x000007fefd158000 C:\windows\system32\NSI.dll +0x000007fefa8d0000 - 0x000007fefa90b000 C:\windows\system32\WINMM.dll +0x000007fefbc60000 - 0x000007fefbc6c000 C:\windows\system32\VERSION.dll +0x0000000077010000 - 0x0000000077017000 C:\windows\system32\PSAPI.DLL +0x000000006ea30000 - 0x000000006ea3f000 C:\Program Files\Java\jdk1.8.0_101\jre\bin\verify.dll +0x000000006e9b0000 - 0x000000006e9d9000 C:\Program Files\Java\jdk1.8.0_101\jre\bin\java.dll +0x000000006e950000 - 0x000000006e985000 C:\Program Files\Java\jdk1.8.0_101\jre\bin\jdwp.dll +0x000000006e940000 - 0x000000006e948000 C:\Program Files\Java\jdk1.8.0_101\jre\bin\npt.dll +0x000000006e990000 - 0x000000006e9a6000 C:\Program Files\Java\jdk1.8.0_101\jre\bin\zip.dll +0x000007fefd3d0000 - 0x000007fefe159000 C:\windows\system32\SHELL32.dll +0x000007fefcf40000 - 0x000007fefd143000 C:\windows\system32\ole32.dll +0x000007fefcb70000 - 0x000007fefcb7f000 C:\windows\system32\profapi.dll +0x000000006e930000 - 0x000000006e939000 C:\Program Files\Java\jdk1.8.0_101\jre\bin\dt_socket.dll +0x000007fefc430000 - 0x000007fefc485000 C:\windows\system32\mswsock.dll +0x000007fefbd30000 - 0x000007fefbd37000 C:\windows\System32\wshtcpip.dll +0x000007fef5160000 - 0x000007fef5285000 C:\windows\system32\dbghelp.dll + +VM Arguments: +jvm_args: -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:50369,suspend=y,server=n -ea -Didea.test.cyclic.buffer.size=1048576 -Dfile.encoding=UTF-8 +java_command: com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 stream.api.Exercise2Test,sortByAge +java_class_path (initial): C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 2017.1\lib\idea_rt.jar;C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 2017.1\plugins\junit\lib\junit-rt.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\rt.jar;C:\Users\Administrateur\IdeaProjects\java8-lambda-stream-insta3\stream-api\target\test-classes;C:\Users\Administrateur\IdeaProjects\java8-lambda-stream-insta3\common-test-tool\target\classes;C:\Users\Administrateur\.m2\repository\junit\junit\4.12\junit-4.12.jar;C:\Users\Administrateur\.m2\repository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar;C:\Users\Administrateur\.m2\repository\org\hamcrest\hamcrest-all\1.3\hamcrest-all-1.3.jar +Launcher Type: SUN_STANDARD + +Environment Variables: +PATH=C:\Program Files (x86)\Google\Chrome\Application;C:\Users\Administrateur\Desktop\Scripts\;C:\Users\Administrateur\Desktop\;C:\ProgramData\Oracle\Java\javapath;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\nodejs\;C:\Program Files\Git\cmd;C:\windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\TortoiseSVN\bin;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\dotnet\;C:\Program Files (x86)\Subversion\bin;C:\Program Files\VisualSVN Server\bin;C:\Users\Administrateur\AppData\Local\Programs\Python\Python35\Scripts\;C:\Users\Administrateur\AppData\Local\Programs\Python\Python35\;C:\Program Files\MySQL\MySQL Server 5.7\bin;C:\Users\Administrateur\AppData\Local\atom\bin +USERNAME=Administrateur +OS=Windows_NT +PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 42 Stepping 7, GenuineIntel + + + +--------------- S Y S T E M --------------- + +OS: Windows 7 , 64 bit Build 7601 (6.1.7601.23543) + +CPU:total 4 (2 cores per cpu, 2 threads per core) family 6 model 42 stepping 7, cmov, cx8, fxsr, mmx, sse, sse2, sse3, ssse3, sse4.1, sse4.2, popcnt, avx, aes, clmul, ht, tsc, tscinvbit + +Memory: 4k page, physical 8292408k(3534420k free), swap 16582956k(11439552k free) + +vm_info: Java HotSpot(TM) 64-Bit Server VM (25.101-b13) for windows-amd64 JRE (1.8.0_101-b13), built on Jun 22 2016 01:21:29 by "java_re" with MS VC++ 10.0 (VS2010) + +time: Mon Mar 27 13:17:59 2017 +elapsed time: 5635 seconds (0d 1h 33m 55s) + diff --git a/stream-api/src/test/java/stream/api/Exercise1Test.java b/stream-api/src/test/java/stream/api/Exercise1Test.java index 368443e..bdefc87 100644 --- a/stream-api/src/test/java/stream/api/Exercise1Test.java +++ b/stream-api/src/test/java/stream/api/Exercise1Test.java @@ -27,8 +27,8 @@ public void findRichCustomers() { * Create a {@link Stream} from customerList only including customer who has more budget than 10000. * Use lambda expression for Predicate and {@link Stream#filter} for filtering. */ - Predicate richCustomerCondition = null; - Stream richCustomerStream = null; + Predicate richCustomerCondition = customer -> customer.getBudget() > 10000; + Stream richCustomerStream = customerList.stream().filter(customer -> customer.getBudget()>10000); assertTrue("Solution for Predicate should be lambda expression", AssertUtil.isLambda(richCustomerCondition)); List richCustomer = richCustomerStream.collect(Collectors.toList()); @@ -45,8 +45,8 @@ public void howOldAreTheCustomers() { * Use method reference(best) or lambda expression(okay) for creating {@link Function} which will * convert {@link Customer} to {@link Integer}, and then apply it by using {@link Stream#map}. */ - Function getAgeFunction = null; - Stream ageStream = null; + Function getAgeFunction = toto -> toto.getAge(); + Stream ageStream = customerList.stream().map(getAgeFunction); assertTrue(AssertUtil.isLambda(getAgeFunction)); List richCustomer = ageStream.collect(Collectors.toList()); diff --git a/stream-api/src/test/java/stream/api/Exercise2Test.java b/stream-api/src/test/java/stream/api/Exercise2Test.java index a7f8956..f91e3d4 100644 --- a/stream-api/src/test/java/stream/api/Exercise2Test.java +++ b/stream-api/src/test/java/stream/api/Exercise2Test.java @@ -27,9 +27,12 @@ public void sortByAge() { * Create a stream with ascending ordered age values. * Use {@link Stream#sorted} to sort them. */ - Stream sortedAgeStream = null; + Function getAgeAsc = customerAsc -> customerAsc.getAge(); + Stream sortedAgeStream = customerList.stream().map(getAgeAsc).sorted(); + Stream sortedCustomerStream = customerList.stream().sorted(Comparator.comparing(getAgeAsc)); List sortedAgeList = sortedAgeStream.collect(Collectors.toList()); + List customerAgeList = sortedCustomerStream.collect(Collectors.toList()); assertThat(sortedAgeList, contains(21, 22, 22, 26, 27, 28, 32, 35, 36, 38)); } @@ -40,8 +43,9 @@ public void descSortByAge() { /** * Create a stream with descending ordered age values. */ - Comparator descOrder = null; - Stream sortedAgeStream = null; + Function getAgeDesc = customerDesc -> customerDesc.getAge(); + Comparator descOrder = (o1, o2) -> o2 - o1; + Stream sortedAgeStream = customerList.stream().map(getAgeDesc).sorted(Comparator.reverseOrder()); assertTrue(AssertUtil.isLambda(descOrder)); List sortedAgeList = sortedAgeStream.collect(Collectors.toList()); @@ -55,7 +59,9 @@ public void top3RichCustomer() { /** * Create a stream with top 3 rich customers using {@link Stream#limit} to limit the size of the stream */ - Stream top3RichCustomerStream = null; + /**Function getTopRich = customerRich -> customerRich.getBudget();*/ + Comparator customerbudget = (c1, c2) -> c2.getBudget() - c1.getBudget(); + Stream top3RichCustomerStream = customerList.stream().sorted(customerbudget).limit(3).map(Customer::getName); List top3RichCustomerList = top3RichCustomerStream.collect(Collectors.toList()); assertThat(top3RichCustomerList, contains("Diana", "Andrew", "Chris")); @@ -68,7 +74,8 @@ public void distinctAge() { /** * Create a stream with distinct age values using {@link Stream#distinct} */ - Stream distinctAgeStream = null; + Function getAgeDistinc = ageDistinc -> ageDistinc.getAge(); + Stream distinctAgeStream = customerList.stream().map(getAgeDistinc).distinct(); List distinctAgeList = distinctAgeStream.collect(Collectors.toList()); assertThat(distinctAgeList, contains(22, 27, 28, 38, 26, 32, 35, 21, 36)); @@ -82,8 +89,8 @@ public void itemsCustomersWantToBuy() { * Create a stream with items' names stored in {@link Customer.wantToBuy} * Use {@link Stream#flatMap} to create a stream from each element of a stream. */ - Function> getItemStream = null; - Stream itemStream = null; + Function> getItemStream = item -> item.getWantToBuy().stream(); + Stream itemStream = customerList.stream().flatMap(getItemStream).map(Item::getName); assertTrue(AssertUtil.isLambda(getItemStream)); List itemList = itemStream.collect(Collectors.toList()); diff --git a/stream-api/src/test/java/stream/api/Exercise3Test.java b/stream-api/src/test/java/stream/api/Exercise3Test.java index 04dfdf3..34c87fc 100644 --- a/stream-api/src/test/java/stream/api/Exercise3Test.java +++ b/stream-api/src/test/java/stream/api/Exercise3Test.java @@ -9,6 +9,7 @@ import java.util.Comparator; import java.util.List; import java.util.Optional; +import java.util.function.Function; import java.util.stream.Stream; import static org.hamcrest.Matchers.is; @@ -23,6 +24,7 @@ public void howManyItemsWanted() { /** * Count how many items there are in {@link Customer.wantToBuy} using {@link Stream#count} */ + Function> countitem = countItem -> countItem.getWantToBuy().stream(); long sum = 0L; assertThat(sum, is(32L)); From 8f9f72b5a7a7779333a0da1b73d7e6252f883823 Mon Sep 17 00:00:00 2001 From: Fred Selva Date: Fri, 31 Mar 2017 11:52:06 +0200 Subject: [PATCH 2/2] exo 1,2,3,4,5,6,7, done --- .../src/test/java/stream/api/Exercise1Test.java | 8 +++++--- .../src/test/java/stream/api/Exercise3Test.java | 16 +++++++++------- .../src/test/java/stream/api/Exercise4Test.java | 11 ++++++----- .../src/test/java/stream/api/Exercise5Test.java | 15 +++++++-------- .../src/test/java/stream/api/Exercise6Test.java | 7 ++++--- .../src/test/java/stream/api/Exercise7Test.java | 12 +++++++----- 6 files changed, 38 insertions(+), 31 deletions(-) diff --git a/stream-api/src/test/java/stream/api/Exercise1Test.java b/stream-api/src/test/java/stream/api/Exercise1Test.java index bdefc87..713abd9 100644 --- a/stream-api/src/test/java/stream/api/Exercise1Test.java +++ b/stream-api/src/test/java/stream/api/Exercise1Test.java @@ -28,7 +28,7 @@ public void findRichCustomers() { * Use lambda expression for Predicate and {@link Stream#filter} for filtering. */ Predicate richCustomerCondition = customer -> customer.getBudget() > 10000; - Stream richCustomerStream = customerList.stream().filter(customer -> customer.getBudget()>10000); + Stream richCustomerStream = customerList.stream().filter(richCustomerCondition); assertTrue("Solution for Predicate should be lambda expression", AssertUtil.isLambda(richCustomerCondition)); List richCustomer = richCustomerStream.collect(Collectors.toList()); @@ -45,7 +45,9 @@ public void howOldAreTheCustomers() { * Use method reference(best) or lambda expression(okay) for creating {@link Function} which will * convert {@link Customer} to {@link Integer}, and then apply it by using {@link Stream#map}. */ - Function getAgeFunction = toto -> toto.getAge(); + /*Function getAgeFunction = customer -> customer.getAge(); + Stream ageStream = customerList.stream().map(getAgeFunction);*/ + Function getAgeFunction = Customer::getAge; Stream ageStream = customerList.stream().map(getAgeFunction); assertTrue(AssertUtil.isLambda(getAgeFunction)); @@ -53,4 +55,4 @@ public void howOldAreTheCustomers() { assertThat(richCustomer, hasSize(10)); assertThat(richCustomer, contains(22, 27, 28, 38, 26, 22, 32, 35, 21, 36)); } -} +} \ No newline at end of file diff --git a/stream-api/src/test/java/stream/api/Exercise3Test.java b/stream-api/src/test/java/stream/api/Exercise3Test.java index 34c87fc..552d748 100644 --- a/stream-api/src/test/java/stream/api/Exercise3Test.java +++ b/stream-api/src/test/java/stream/api/Exercise3Test.java @@ -4,6 +4,7 @@ import common.test.tool.dataset.ClassicOnlineStore; import common.test.tool.entity.Customer; +import common.test.tool.entity.Item; import org.junit.Test; import java.util.Comparator; @@ -24,8 +25,9 @@ public void howManyItemsWanted() { /** * Count how many items there are in {@link Customer.wantToBuy} using {@link Stream#count} */ - Function> countitem = countItem -> countItem.getWantToBuy().stream(); - long sum = 0L; + Function> getItemStream = customer -> customer.getWantToBuy().stream(); + Stream itemStream = customerList.stream().flatMap(getItemStream.andThen(customer -> customer.map(Item::getName))); + long sum = itemStream.count(); assertThat(sum, is(32L)); } @@ -38,8 +40,8 @@ public void richestCustomer() { * Find the richest customer's budget by using {@link Stream#max} and {@link Comparator#naturalOrder} * Don't use {@link Stream#sorted} */ - Comparator comparator = null; - Optional richestCustomer = null; + Comparator comparator = Comparator.naturalOrder(); + Optional richestCustomer = customerList.stream().map(Customer::getBudget).max(comparator); assertThat(comparator.getClass().getSimpleName(), is("NaturalOrderComparator")); assertThat(richestCustomer.get(), is(12000)); @@ -53,9 +55,9 @@ public void youngestCustomer() { * Find the youngest customer by using {@link Stream#min} * Don't use {@link Stream#sorted} */ - Comparator comparator = null; - Optional youngestCustomer = null; + Comparator comparator = Comparator.comparingInt(Customer::getAge); + Optional youngestCustomer = customerList.stream().min(comparator); assertThat(youngestCustomer.get(), is(customerList.get(8))); } -} +} \ No newline at end of file diff --git a/stream-api/src/test/java/stream/api/Exercise4Test.java b/stream-api/src/test/java/stream/api/Exercise4Test.java index 69898e4..d4f0401 100644 --- a/stream-api/src/test/java/stream/api/Exercise4Test.java +++ b/stream-api/src/test/java/stream/api/Exercise4Test.java @@ -8,6 +8,7 @@ import java.util.List; import java.util.Optional; +import java.util.function.Predicate; import java.util.stream.Stream; import static org.hamcrest.Matchers.is; @@ -23,7 +24,7 @@ public void firstRegistrant() { * Find the first customer who registered this online store by using {@link Stream#findFirst} * The customerList are ascending ordered by registered timing. */ - Optional firstCustomer = null; + Optional firstCustomer = customerList.stream().findFirst(); assertThat(firstCustomer.get(), is(customerList.get(0))); } @@ -35,7 +36,7 @@ public void isThereAnyoneOlderThan40() { /** * Check whether any customer older than 40 exists or not, by using {@link Stream#anyMatch} */ - boolean olderThan40Exists = true; + boolean olderThan40Exists = customerList.stream().anyMatch(customer -> customer.getAge() > 40); assertThat(olderThan40Exists, is(false)); } @@ -47,7 +48,7 @@ public void isEverybodyOlderThan20() { /** * Check whether all customer are older than 20 or not, by using {@link Stream#allMatch} */ - boolean allOlderThan20 = false; + boolean allOlderThan20 = customerList.stream().allMatch(customer -> customer.getAge() >= 20); assertThat(allOlderThan20, is(true)); } @@ -60,8 +61,8 @@ public void everyoneWantsSomething() { * Confirm that none of the customer has empty list for their {@link Customer.wantToBuy} * by using {@link Stream#noneMatch} */ - boolean everyoneWantsSomething = false; + boolean everyoneWantsSomething = customerList.stream().noneMatch(customer -> customer.getWantToBuy().isEmpty()); assertThat(everyoneWantsSomething, is(true)); } -} +} \ No newline at end of file diff --git a/stream-api/src/test/java/stream/api/Exercise5Test.java b/stream-api/src/test/java/stream/api/Exercise5Test.java index dc41f32..d0c204e 100644 --- a/stream-api/src/test/java/stream/api/Exercise5Test.java +++ b/stream-api/src/test/java/stream/api/Exercise5Test.java @@ -28,10 +28,10 @@ public void nameList() { /** * Create a list of customer names by using {@link Stream#collect} and {@link Collectors#toList} */ - List nameList = null; + List nameList = customerList.stream().map(Customer::getName).collect(Collectors.toList()); assertThat(nameList, contains("Joe", "Steven", "Patrick", "Diana", "Chris", "Kathy", "Alice", "Andrew", - "Martin", "Amy")); + "Martin", "Amy")); } @Easy @Test @@ -41,7 +41,7 @@ public void ageSet() { /** * Create a set of customer age by using {@link Stream#collect} and {@link Collectors#toSet} */ - Set ageSet = null; + Set ageSet = customerList.stream().map(Customer::getAge).collect(Collectors.toSet()); assertThat(ageSet, hasSize(9)); assertThat(ageSet, hasItems(21, 22, 26, 27, 28, 32, 35, 36, 38)); @@ -54,7 +54,7 @@ public void nameInCsv() { /** * Create a csv string of customer names in brackets "[]" by using {@link Collectors#joining} */ - String string = null; + String string = customerList.stream().map(Customer::getName).collect(Collectors.joining(",", "[","]" )); assertThat(string, is("[Joe,Steven,Patrick,Diana,Chris,Kathy,Alice,Andrew,Martin,Amy]")); } @@ -67,7 +67,7 @@ public void oldestCustomer() { * Get the oldest customer by using {@link Collectors#maxBy}. * Don't use any intermediate operations. */ - Optional oldestCustomer = null; + Optional oldestCustomer = customerList.stream().collect(Collectors.maxBy((o1, o2) -> o1.getAge() - o2.getAge())); assertThat(oldestCustomer.get(), is(customerList.get(3))); } @@ -80,8 +80,7 @@ public void ageDistribution() { * Create a map of age as key and number of customers as value * using {@link Collectors#groupingBy} and {@link Collectors#counting} */ - Map ageDistribution = null; - + Map ageDistribution = customerList.stream().collect(Collectors.groupingBy(Customer::getAge,Collectors.counting())); assertThat(ageDistribution.size(), is(9)); ageDistribution.forEach((k, v) -> { if (k.equals(22)) { @@ -91,4 +90,4 @@ public void ageDistribution() { } }); } -} +} \ No newline at end of file diff --git a/stream-api/src/test/java/stream/api/Exercise6Test.java b/stream-api/src/test/java/stream/api/Exercise6Test.java index 3003eb1..5f7b679 100644 --- a/stream-api/src/test/java/stream/api/Exercise6Test.java +++ b/stream-api/src/test/java/stream/api/Exercise6Test.java @@ -5,6 +5,7 @@ import org.junit.Test; import java.util.List; +import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -18,7 +19,7 @@ public void streamFromValues() { /** * Create a stream with string values "a" "b" "c" by using {@link Stream#of} */ - Stream abcStream = null; + Stream abcStream = Stream.of("a","b","c"); List abcList = abcStream.collect(Collectors.toList()); assertThat(abcList, contains("a", "b", "c")); @@ -29,9 +30,9 @@ public void numberStream() { /** * Create a stream only with multiples of 3, starting from 0, size of 10, by using {@link Stream#iterate} */ - Stream numbers = null; + Stream numbers = Stream.iterate(0, n -> n + 3 ).limit(10); List numbersList = numbers.collect(Collectors.toList()); assertThat(numbersList, contains(0, 3, 6, 9, 12, 15, 18, 21, 24, 27)); } -} +} \ No newline at end of file diff --git a/stream-api/src/test/java/stream/api/Exercise7Test.java b/stream-api/src/test/java/stream/api/Exercise7Test.java index 6eec18a..3b7b021 100644 --- a/stream-api/src/test/java/stream/api/Exercise7Test.java +++ b/stream-api/src/test/java/stream/api/Exercise7Test.java @@ -1,8 +1,10 @@ package stream.api; +import com.sun.corba.se.spi.activation.ServerHolder; import common.test.tool.annotation.Easy; import common.test.tool.dataset.ClassicOnlineStore; import common.test.tool.entity.Customer; +import common.test.tool.entity.Item; import common.test.tool.entity.Shop; import org.junit.Test; @@ -26,8 +28,8 @@ public void averageAge() { * Create {@link IntStream} with customer ages by using {@link Stream#mapToInt} * Then calculate the average of ages by using {@link IntStream#average} */ - IntStream ageStream = null; - OptionalDouble average = null; + IntStream ageStream = customerList.stream().mapToInt(Customer::getAge); + OptionalDouble average = ageStream.average(); assertThat(average.getAsDouble(), is(28.7)); } @@ -40,9 +42,9 @@ public void howMuchToBuyAllItems() { * Create {@link LongStream} with all items' prices using {@link Stream#mapToLong} * Then calculate the sum of prices using {@link LongStream#sum} */ - LongStream priceStream = null; - long priceSum = 0; + LongStream priceStream = shopList.stream().flatMap(shop -> shop.getItemList().stream()).mapToLong(value -> value.getPrice()); + long priceSum = priceStream.sum(); assertThat(priceSum, is(60930L)); } -} +} \ No newline at end of file