From 016579337010ab145058a3b25dc8b437f8c6f1b6 Mon Sep 17 00:00:00 2001 From: Hangga Aji Sayekti Date: Wed, 1 Nov 2023 10:36:43 +0700 Subject: [PATCH] Update core-java-modules/core-java-uuid/src/test/java/com/baeldung/uuid/UUIDLongGeneratorUnitTest.java IntStream to loop Co-authored-by: Liam Williams --- .../uuid/UUIDLongGeneratorUnitTest.java | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/core-java-modules/core-java-uuid/src/test/java/com/baeldung/uuid/UUIDLongGeneratorUnitTest.java b/core-java-modules/core-java-uuid/src/test/java/com/baeldung/uuid/UUIDLongGeneratorUnitTest.java index 24add0a14a..6d2dff959c 100644 --- a/core-java-modules/core-java-uuid/src/test/java/com/baeldung/uuid/UUIDLongGeneratorUnitTest.java +++ b/core-java-modules/core-java-uuid/src/test/java/com/baeldung/uuid/UUIDLongGeneratorUnitTest.java @@ -37,20 +37,16 @@ public class UUIDLongGeneratorUnitTest { private void collisionAndNegativeCheck(Method method) { Set uniqueValues = new HashSet<>(); - AtomicInteger collisions = new AtomicInteger(0); - AtomicInteger negative = new AtomicInteger(0); + int collisions = 0; + int negative = 0; - IntStream.range(0, n).forEach(i -> { - try { - long uniqueValue = (long) method.invoke(uuidLongGenerator); - if (!uniqueValues.add(uniqueValue)) { - collisions.incrementAndGet(); - } - if (uniqueValue < 0) { - negative.incrementAndGet(); - } - } catch (IllegalAccessException | InvocationTargetException e) { - throw new RuntimeException(e); + for (int i = 0; i < n; i++) { + long uniqueValue = (long) method.invoke(uuidLongGenerator); + if (!uniqueValues.add(uniqueValue)) { + collisions++; + } + if (uniqueValue < 0) { + negative++; } });