Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.Arrays;
import java.util.Base64;
import java.util.Locale;
import java.util.UUID;

/**
* This Variant class holds the Variant-encoded value and metadata binary values.
Expand Down Expand Up @@ -129,8 +130,11 @@ public byte[] getBinary() {
/**
* @return the UUID value
*/
public byte[] getUUID() {
return VariantUtil.getUUID(value, pos);
public UUID getUUID() {
byte[] uuidBytes = VariantUtil.getUUID(value, pos);
long msb = ByteBuffer.wrap(uuidBytes, 0, 8).order(ByteOrder.BIG_ENDIAN).getLong();
long lsb = ByteBuffer.wrap(uuidBytes, 8, 8).order(ByteOrder.BIG_ENDIAN).getLong();
return new UUID(msb, lsb);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.math.BigDecimal;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.security.SecureRandom;
import java.time.Instant;
import java.time.LocalDate;
Expand All @@ -31,6 +33,7 @@
import java.util.Arrays;
import java.util.Base64;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.stream.IntStream;
import org.junit.Assert;
Expand Down Expand Up @@ -346,7 +349,10 @@ public void testUUID() {
vb.appendUUID(uuid);
Assert.assertEquals(
"\"00112233-4455-6677-8899-aabbccddeeff\"", vb.result().toJson());
Assert.assertArrayEquals(uuid, vb.result().getUUID());
long msb = ByteBuffer.wrap(uuid, 0, 8).order(ByteOrder.BIG_ENDIAN).getLong();
long lsb = ByteBuffer.wrap(uuid, 8, 8).order(ByteOrder.BIG_ENDIAN).getLong();
UUID expected = new UUID(msb, lsb);
Assert.assertEquals(expected, vb.result().getUUID());
}

@Test
Expand Down