From 8f1a091a431bcd423d59343327f8a9b8540fc9df Mon Sep 17 00:00:00 2001 From: "@hangga" Date: Thu, 2 Nov 2023 09:42:31 +0700 Subject: [PATCH] update : add space after () --- .../com/baeldung/uuid/UUIDPositiveLongGenerator.java | 12 ++++++------ .../uuid/UUIDPositiveLongGeneratorUnitTest.java | 7 +++---- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/core-java-modules/core-java-uuid/src/main/java/com/baeldung/uuid/UUIDPositiveLongGenerator.java b/core-java-modules/core-java-uuid/src/main/java/com/baeldung/uuid/UUIDPositiveLongGenerator.java index b47fee1968..7b98c05684 100644 --- a/core-java-modules/core-java-uuid/src/main/java/com/baeldung/uuid/UUIDPositiveLongGenerator.java +++ b/core-java-modules/core-java-uuid/src/main/java/com/baeldung/uuid/UUIDPositiveLongGenerator.java @@ -12,15 +12,15 @@ public class UUIDPositiveLongGenerator { return Math.abs(UUID.randomUUID().getLeastSignificantBits()); } - public long getMostSignificantBits(){ + public long getMostSignificantBits() { return Math.abs(UUID.randomUUID().getMostSignificantBits()); } - public long gethashCode(){ + public long gethashCode() { return Math.abs(UUID.randomUUID().toString().hashCode()); } - public long combineByteBuffer(){ + public long combineByteBuffer() { UUID uuid = UUID.randomUUID(); ByteBuffer bb = ByteBuffer.wrap(new byte[16]); bb.putLong(uuid.getMostSignificantBits()); @@ -29,20 +29,20 @@ public class UUIDPositiveLongGenerator { return Math.abs(bb.getLong()); } - public long combineBitwise(){ + public long combineBitwise() { UUID uniqueUUID; uniqueUUID = UUID.randomUUID(); return Math.abs((uniqueUUID.getMostSignificantBits() << 32) | (uniqueUUID.getLeastSignificantBits() & 0xFFFFFFFFL)); } - public long combineDirect(){ + public long combineDirect() { UUID uniqueUUID = UUID.randomUUID(); long mostSignificantBits = uniqueUUID.getMostSignificantBits(); long leastSignificantBits = uniqueUUID.getLeastSignificantBits(); return Math.abs(mostSignificantBits ^ (leastSignificantBits >> 1)); } - public long combinePermutation(){ + public long combinePermutation() { UUID uuid = UUID.randomUUID(); long mostSigBits = uuid.getMostSignificantBits(); long leastSigBits = uuid.getLeastSignificantBits(); diff --git a/core-java-modules/core-java-uuid/src/test/java/com/baeldung/uuid/UUIDPositiveLongGeneratorUnitTest.java b/core-java-modules/core-java-uuid/src/test/java/com/baeldung/uuid/UUIDPositiveLongGeneratorUnitTest.java index ebb061216b..cc377254c4 100644 --- a/core-java-modules/core-java-uuid/src/test/java/com/baeldung/uuid/UUIDPositiveLongGeneratorUnitTest.java +++ b/core-java-modules/core-java-uuid/src/test/java/com/baeldung/uuid/UUIDPositiveLongGeneratorUnitTest.java @@ -4,7 +4,6 @@ import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.text.DecimalFormat; import java.util.HashSet; @@ -13,7 +12,7 @@ import java.util.Set; import static org.assertj.core.api.Assertions.assertThat; public class UUIDPositiveLongGeneratorUnitTest { - private final static int n = 1000000; + private final static int N = 1000000; private final static double COLLISION_THRESHOLD = 0.001; private final UUIDPositiveLongGenerator uuidLongGenerator = new UUIDPositiveLongGenerator(); private final Logger logger = LoggerFactory.getLogger(UUIDPositiveLongGeneratorUnitTest.class); @@ -41,14 +40,14 @@ public class UUIDPositiveLongGeneratorUnitTest { private void collisionCheck(Method method) throws Exception { Set uniqueValues = new HashSet<>(); int collisions = 0; - for (int i = 0; i < n; i++) { + for (int i = 0; i < N; i++) { long uniqueValue = (long) method.invoke(uuidLongGenerator); assertThat(uniqueValue).isPositive(); if (!uniqueValues.add(uniqueValue)) { collisions++; } } - double collisionsProbability = (double) collisions / n; + double collisionsProbability = (double) collisions / N; printOutput(method.getName(), collisions, collisionsProbability); assertThat(collisionsProbability).isLessThan(COLLISION_THRESHOLD); }