update : add space after ()

This commit is contained in:
@hangga 2023-11-02 09:42:31 +07:00
parent a5d0a15419
commit 8f1a091a43
2 changed files with 9 additions and 10 deletions

View File

@ -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();

View File

@ -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<Long> 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);
}