Update core-java-modules/core-java-uuid/src/test/java/com/baeldung/uuid/UUIDLongGeneratorUnitTest.java

IntStream to loop

Co-authored-by: Liam Williams <liam.williams@zoho.com>
This commit is contained in:
Hangga Aji Sayekti 2023-11-01 10:36:43 +07:00 committed by GitHub
parent ece5cdeb6e
commit 0165793370
1 changed files with 9 additions and 13 deletions

View File

@ -37,20 +37,16 @@ public class UUIDLongGeneratorUnitTest {
private void collisionAndNegativeCheck(Method method) {
Set<Long> 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++;
}
});