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:
parent
ece5cdeb6e
commit
0165793370
|
@ -37,20 +37,16 @@ public class UUIDLongGeneratorUnitTest {
|
||||||
|
|
||||||
private void collisionAndNegativeCheck(Method method) {
|
private void collisionAndNegativeCheck(Method method) {
|
||||||
Set<Long> uniqueValues = new HashSet<>();
|
Set<Long> uniqueValues = new HashSet<>();
|
||||||
AtomicInteger collisions = new AtomicInteger(0);
|
int collisions = 0;
|
||||||
AtomicInteger negative = new AtomicInteger(0);
|
int negative = 0;
|
||||||
|
|
||||||
IntStream.range(0, n).forEach(i -> {
|
for (int i = 0; i < n; i++) {
|
||||||
try {
|
long uniqueValue = (long) method.invoke(uuidLongGenerator);
|
||||||
long uniqueValue = (long) method.invoke(uuidLongGenerator);
|
if (!uniqueValues.add(uniqueValue)) {
|
||||||
if (!uniqueValues.add(uniqueValue)) {
|
collisions++;
|
||||||
collisions.incrementAndGet();
|
}
|
||||||
}
|
if (uniqueValue < 0) {
|
||||||
if (uniqueValue < 0) {
|
negative++;
|
||||||
negative.incrementAndGet();
|
|
||||||
}
|
|
||||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue